Got a pretty interesting surprise today when I started working on the project. For some reason my github is corrupted. I did some research and ended up removing and adding my origin back. Not sure why the head became null out of no where…but then after that I finally got to complete the first iteration of the high level game loop and move on to the save system.
When you load the game, you need to have a few information:
- name of the scene
- player data
- health, mana
- current location
- state
- item data
- With their specific information
More is needed for saving:
- save time
- progress (ex. chapter 3 – 1)
- name of the save
The class that holds the information above should use attribute [System.Serializable] since we are using the JsonUtility in Unity. Using ToJson and FromJason can easily turn the class into text format. I choose to have a static member of save data to carry them across the scene. We have all the scene script derived from a base scene script. It will be nice if we can define the load function callback in the base script’s awake, and have the base call it. Unfortunately, Unity’s C# behave a little bit different and won’t do that. Seems like we will have to either have all the scene script do their own loading function in Awake or call it in Awake, or having the base class do it in its own Awake and make sure the child always call base.Awake() as the first line.
Not all the scene needs to load data, so having each scene handles the data is probably what we are going to do…however, it will be nice if we can clean the save data after we are done loading. We could use an in-game MonoBehaviour to track it, but that means we need another actor/component in every scene. Something I want to try is a clean-up-after-yourself approach. When the save data got taken, it should clean it self after it. When all the data got cleaned, we know all the loading has happened and it can wipe itself after that. Right now it works without thinking about the loaded data, meaning it might have trouble when finishing a game and move into next level. The next step will be implementing that system.