Finally, I have a save mechanism for Spamocalypse. As usual, I based it on serialisation and deserialisation – basically, writing a class out to a binary file. There are actually two classes here: SpammerSave and SaveGame. The first one is a utility class that saves the following details for a specific NPC:
- Alertness levels
- Current state
SaveGame holds a Dictionary of these in addition to the following player details:
- Loot gathered
- Ammo count
- Status of each objective
Almost all of these are primitive data types, such as integers or floats. Positions and rotations* are saved as instances of the SerializableVector3 class that I’ve been using in my pathfinding system to store positions, and which is just a serialisable version of the standard Vector3 class in Unity. The state of each NPC and objective is saved as an enum, which in C# can have integer values assigned to them, so serialising them is no problem at all.
So far, it worked when I tried this inside the Editor. It saves this into the persistent data path, which will vary for each operating system. As usual, the download link is here.