/// <summary> /// Persists the high scores into the player prefs /// </summary> private void SerializeHighScores() { HighScoresContainer container = new HighScoresContainer { HighScores = HighScores }; string json = JsonUtility.ToJson(container); PlayerPrefs.SetString(mPlayerPrefsHighScoresKey, json); }
/// <summary> /// Retrieves the high scores from player prefs /// </summary> private void DeserializeHighScores() { string json = PlayerPrefs.GetString(mPlayerPrefsHighScoresKey, ""); if (string.IsNullOrEmpty(json)) { HighScores = new List <HighScore>(); return; } HighScoresContainer container = JsonUtility.FromJson <HighScoresContainer>(json); HighScores = container.HighScores; }