Hi, Mike. Here’s an example of how i used the save system to capture multiple data types. I’ll paste the code, and explain what’s going on as best I can:
//first, create a serializable class that will be used to capture multiple values.
//this class is contained within the class that has the variables I want to save.
//for this example, I want to save the variables: XPTowardsNextPoint, CurrentPoints, and IsAlive.
//this class lives inside CharXP class (a MonoBehaviour that implements ISaveable)
[System.Serializable]
class MySaveData
{
//create variables for each field I want to save
public int XP_TowardsNextPoint;
public int currentNumOfPoints;
public bool charIsAlive;
}
//CaptureState() is part of the save system Sam built (see ISaveable)
public object CaptureState()
{
//create an instance of the MySaveData class
var saveData = new MySaveData();
//we're going to record the current values of the variables in this CharXP instance
saveData.XP_TowardsNextPoint = XPTowardsNextPoint;
saveData.currentNumOfPoints = CurrentPoints;
saveData.charIsAlive = IsAlive;
//the object we return here is of type MySaveData and has the values we want saved
return saveData;
}
//RestoreState() is part of the save system Sam built (see ISaveable)
public void RestoreState(object state)
{
//create a variable of type MySaveData called saveData; cast the parameter, "state",
//as a MySaveData and assign it to saveData.
var saveData = (MySaveData)state;
//set the values of this instance of CharXP == the values that we saved.
CurrentPoints = saveData.currentNumOfPoints;
XPTowardsNextPoint = saveData.XP_TowardsNextPoint;
IsAlive = saveData.charIsAlive;
//Note: the details of how the data is written to / read from a file on your computer
// when CaptureState() / RestoreState() are called is part of the save system itself,
//but this should give you a good idea of how to use it to do what you are trying to do.
}