/// <summary> /// Load the high scores from PlayerPrefs. /// </summary> public static void LoadHighScores() { try { string json = ""; if (PlayerPrefs.HasKey(saveKey)) { json = PlayerPrefs.GetString(saveKey); } if (json != "{}") { HighScoreWrapper wrapper = JsonUtility.FromJson <HighScoreWrapper>(json); highScores = new List <HighScore>(wrapper.highScores); } else { highScores = new List <HighScore>(); } } catch (Exception e) { BugLog.Instance.ShowException(e); } }
/// <summary> /// Save the high score to PlayerPrefs. /// </summary> public static void SaveHighScores() { HighScoreWrapper wrapper = new HighScoreWrapper(); //Need to wrap the high sores because Lists cannot be serialized independently. wrapper.highScores = highScores.ToArray(); string json = JsonUtility.ToJson(wrapper); PlayerPrefs.SetString(saveKey, json); }