I hope you could help with some trouble I'm having saving a class.
I have a PlayerSave class here:
Code: Select all
public class PlayerSave
{
// high scores for each level
public Dictionary<string, float> LevelHighScore { get; set; }
// dict to hold all unlockables in for the hubroom
// string will be there name and the bool will be if they are unlocked
public Dictionary<string, bool> UnlockablesHubroom { get; set; }
// dict to hold levels unlocked
// string for name of level
public Dictionary<string, bool> LevelsUnlocked { get; set; }
public bool FirstTimePlayer { get; set; }
}
Code: Select all
public PlayerSave playerSave = new PlayerSave();
private string saveKey = "playersave";
// level codes
public string[] levelCodes = {"forest", "temple"};
/// <summary>
/// get save data from file
/// </summary>
public void GetPlayerSave()
{
// check if there is a save data
if (ES3.KeyExists(saveKey))
{
// data exists so load data
playerSave = ES3.Load<PlayerSave>(saveKey);
}
else
{
// data does not exists so lets make some
playerSave.FirstTimePlayer = true;
playerSave.LevelHighScore = new Dictionary<string, float>();
playerSave.LevelsUnlocked = new Dictionary<string, bool>();
playerSave.UnlockablesHubroom = new Dictionary<string, bool>();
// add levels with starting score of 0
foreach(string l in levelCodes)
{
playerSave.LevelHighScore.Add(l, 0);
}
ES3.Save(saveKey, playerSave);
}
}
Code: Select all
{
"playersave" : {
"__type" : "PlayerSave,Assembly-CSharp",
"value" : {
}
}
}
Would love some insight on this. Been struggling with it the past few days!
Thanks in advance!!