Closed InverNessian closed 4 years ago
It looks like there are a few ways to keep info around after a scene is gone.
While working on this, it's become apparent that I need to re-organize my existing code and functionality. This seems to be the best method:
GameController handles only the game flow and saving game state/progress. Data Manager handles the saving and loading of character data, but otherwise serves as only a holder for the scriptable objects. The Attack classes would be the ones that handle the process of generating attacks.
The problem I'm running into is how to manage the Attacks. Instantiate them as MonoBehaviors? Or should I make Scriptable Objects? But you can't instantiate those, they have to be pre-made in the Asset menu.
I think what I can do is just have another level of inheritance. I'll go back to how it was originally? There will be Attack_Normal and Attack_Savage_Blow and stuff.
This allows me to just have one instance of the attack I guess. Then units can just store a reference to it, dynamically fetched according to talents/etc.
I've gotten a good pattern here. Unit Data will exist in a ScriptableObject class and be instantiated for each unique unit. This means that there will only be one UnitData for each enemy type, allowing me to cut down on RAM usage. However, I need to find a way to have individualized health for enemies.
With that in mind, I've got data persistence implemented, all that's left is to test it.
Apparently ScriptableObjects can't be Serialized by the C# serializer. Ugh.
On the plus side, Unity has built-in Serialization for ScriptableObjects and MonoBehaviors, or so it claims. Seems to only work sometimes. Need more investigation, as this would make things super easy.
It works! Apparently you just need to use EditorUtility.SetDirty(obj) to force Unity to save it on close.
Yeah so apparently this doesn't actually work in build versions of the game? FML.
At least I won't have to worry about making SOs this time. Just remove the SO inheritance and have them be base C# classes. This lets me implement the System.IO serialization.
Actually it'd probably be better to just make the Manager classes serializable. That way they can serve as wrapper classes.
The game needs to be able to save and load data. Obviously the main goal for this is to create save files, but it also means I don't have to manually enter all the units' stats into Scriptable Objects.