Ejemplo n.º 1
0
        public void SaveHighScores(string name, int level, int points)
        {
            HighScores = LoadHighScores() ?? new HighScores();
            if (HighScores.HighScoresList.Count > 4 && HighScores.HighScoresList[4].Points > points)
            {
                return;
            }

            HighScores.HighScoresList.Add(new HighScore {
                Name   = name,
                Points = points,
                Level  = level
            });

            HighScores.HighScoresList = HighScores.HighScoresList.OrderByDescending(score => score.Points).ToList();
            if (HighScores.HighScoresList.Count > 5)
            {
                HighScores.HighScoresList.RemoveAt(5);
            }
            File.WriteAllText(Application.persistentDataPath + "/highscores.json",
                              JsonUtility.ToJson(HighScores, true));
        }
Ejemplo n.º 2
0
 public HighScoresController()
 {
     HighScores = new HighScores();
 }