Best practices for using and modifying Standard Assets?
Short version: I want to use the FPSController Standard Asset (or any SA for that matter) but want to extend and modify its functionality. Is there a best practice for this scenario in relation to copying/subclassing/encapsulating/etc.?
Longer version...
I'm currently messing around with a basic FPS. Placed in the FPSController Standard Asset. Now I'm trying to add to and modify the FPSController (player) with my own scripts (having a stamina bar), and I was wondering if there's any best practices around this. Issues I'm having:
If I try to add my own scripts to be referenced by FPSController (e.g. a PlayerStamina script I wrote), it doesn't seem to be able to find it, because it's in its own namespace? Making my own namespace and trying to use that hasn't worked yet.
I could copy FirstPersonController.cs to my own scripts, but the whole prefab has a lot of other baggage with it, so that doesn't seem like the intended way.
I could wrap the FPSController object with another Object, but not sure what that'll get me.
I could try subclassing (in code) the Standard Asset script, and then reference that script in the prefab instead? Would this have issues with namespaces?
To be clear: I'm not looking for help with the specifics (making a stamina bar or state, etc.), just trying to figure out how to best work with and around the Standard Assets, since they're segmented off from my own assets and don't seem to have ready access to my own scripts.
Answer by dfego · Feb 27, 2017 at 03:46 AM
I ended up copying the components I needed into my own Assets and scripts and then paring them down as needed. It helped me get a better understanding of what's there, and now I can freely modify it with whatever is needed!
Thanks again to @Miguelcldn for his suggestion. I will likely organize some of my additions to these components like that!
Answer by Miguelcldn · Feb 26, 2017 at 03:59 PM
Hi @dfego, I'm not pretty sure if this helps you out, but I was in the same situation and my solution was to just add my own scripts as components to the FirstPersonController so its components end up like this:
First Person Controller (Script)
Player (Script)
Player Stats (Script)
[Other components]
This way the First Person Controller do its job: Control the player, while the Player and Player Stats scripts are my own, where I add the extra functionality I need in the GameObject. I keep the Stamina/Health bars and its control in a separate script (Player Stats) to keep Player cleaner.
@$$anonymous$$iguelcldn Thanks for the response! Question for your setup. FirstPersonController has sprinting (with LeftShift), which I'd like to tie to my sta$$anonymous$$a. Did you tie these together somehow? For my initial test I just check for LeftShift in my Sta$$anonymous$$a code, but that feels like bad design since I already look for and handle the input in the FirstPersonController.
The long-term solution might be to make my own prefab, pulling out the pieces of FirstPersonController that I like!