public void AddHighscoreEntry(int score, string name) { HighScoreEntry newScore = new HighScoreEntry { score = score, name = name }; string jsonString = PlayerPrefs.GetString("highscoreTable"); HigScores HighScores = JsonUtility.FromJson <HigScores>(jsonString); if (HighScores == null || HighScores.highScoreEntriesList == null) { HighScores = new HigScores { highScoreEntriesList = new List <HighScoreEntry>() }; } HighScores.highScoreEntriesList.Add(newScore); string json = JsonUtility.ToJson(HighScores); PlayerPrefs.SetString("highscoreTable", json); PlayerPrefs.Save(); }
private void Awake() { if (entryContainer != null && entryTemplate != null) { string jsonString = PlayerPrefs.GetString("highscoreTable"); HigScores HighScores = JsonUtility.FromJson <HigScores>(jsonString); if (HighScores != null && HighScores.highScoreEntriesList.Count > 0) { HighScores.highScoreEntriesList.Sort(); if (HighScores.highScoreEntriesList.Count > 10) { HighScores.highScoreEntriesList.RemoveRange(10, HighScores.highScoreEntriesList.Count - 10); } highScoreEntryTransformList = new List <Transform>(); foreach (HighScoreEntry highScoreEntry in HighScores.highScoreEntriesList) { CreateHighscoreEntryTransform(highScoreEntry, entryContainer, highScoreEntryTransformList); } } } }