public void AddEntry(ScoreboardEntryData scoreboardEntryData)
        {
            ScoreboardSaveData savedScores = GetSavedScores();

            bool scoreAdded = false;

            for (int i = 0; i < savedScores.highscores.Count; i++)
            {
                if (scoreboardEntryData.entryScore > savedScores.highscores[i].entryScore)
                {
                    savedScores.highscores.Insert(i, scoreboardEntryData);
                    scoreAdded = true;
                    break;
                }
            }

            if (!scoreAdded && savedScores.highscores.Count < maxScoreboardEntries)
            {
                savedScores.highscores.Add(scoreboardEntryData);
            }

            if (savedScores.highscores.Count > maxScoreboardEntries)
            {
                savedScores.highscores.RemoveRange(
                    maxScoreboardEntries,
                    savedScores.highscores.Count - maxScoreboardEntries);
            }

            //   UpdateUI(savedScores);

            this.SaveScores(savedScores);
        }
 public void SaveScores(ScoreboardSaveData scoreboardSaveData)
 {
     using (StreamWriter stream = new StreamWriter(SavePath))
     {
         string json = JsonUtility.ToJson(scoreboardSaveData, true);
         stream.Write(json);
     }
 }
        private void UpdateUI(ScoreboardSaveData savedScores)
        {
            foreach (Transform child in highscoresHolderTransform)
            {
                Destroy(child.gameObject);
            }

            foreach (ScoreboardEntryData highscore in savedScores.highscores)
            {
                Instantiate(scoreboardEntryObject, highscoresHolderTransform).
                GetComponent <ScoreboardEntryUI>().Initialize(highscore);
            }
        }
示例#4
0
 public void Start()
 {
     congratulations.SetActive(false);
     topTen = scoreBoard.GetSavedScores();
     for (int i = 0; i < topTen.highscores.Count; i++)
     {
         if (points.getNumber() > topTen.highscores[i].entryScore || topTen.highscores.Count < 10)
         {
             inputName.SetActive(true);
             retry.SetActive(false);
             break;
         }
         else
         {
             inputName.SetActive(false);
             retry.SetActive(true);
         }
     }
 }
        private void Start()
        {
            ScoreboardSaveData savedScores = GetSavedScores();

            UpdateUI(savedScores);
        }