예제 #1
0
        public void AddEntry(ScoreboardEntryData scoreboardEntryData)
        {
            ScoreboardSaveData savedScores = GetSavedScores();

            bool scoreAdded = false;

            //Check if the score is high enough to be added.
            for (int i = 0; i < savedScores.highscores.Count; i++)
            {
                if (Player.points > savedScores.highscores[i].entryScore)
                {
                    savedScores.highscores.Insert(i, scoreboardEntryData);
                    scoreAdded = true;
                    break;
                }
            }

            //Check if the score can be added to the end of the list.
            if (!scoreAdded && savedScores.highscores.Count < maxScoreboardEntries)
            {
                savedScores.highscores.Add(scoreboardEntryData);
            }

            //Remove any scores past the limit.
            if (savedScores.highscores.Count > maxScoreboardEntries)
            {
                savedScores.highscores.RemoveRange(maxScoreboardEntries, savedScores.highscores.Count - maxScoreboardEntries);
            }

            UpdateUI(savedScores);

            SaveScores(savedScores);
        }
예제 #2
0
        private void SaveScores(ScoreboardSaveData scoreboardSaveData)
        {
            scoreboardSaveData.highscores.Sort((a, b) => b.entryScore - a.entryScore);

            using (StreamWriter stream = new StreamWriter(SavePath))
            {
                string json = JsonUtility.ToJson(scoreboardSaveData, true);
                stream.Write(json);
            }
        }
예제 #3
0
        private void Start()
        {
            ScoreboardSaveData savedScores = GetSavedScores();

            UpdateUI(savedScores);

            SaveScores(savedScores);

            if (savedScores == null || savedScores.highscores.Count <= 0)
            {
                Debug.Log("Caricamento da file non riuscito");
                lastRecord = 0;
            }
            else
            {
                lastRecord = savedScores.highscores[0].entryScore;
            }
        }
예제 #4
0
        private void UpdateUI(ScoreboardSaveData savedScores)
        {
            savedScores.highscores.Sort((a, b) => b.entryScore - a.entryScore);

            foreach (Transform child in highscoresHolderTransform)
            {
                Destroy(child.gameObject);
            }

            /*foreach (ScoreboardEntryData highscore in savedScores.highscores)
             * {
             *  Instantiate(scoreboardEntryObject, highscoresHolderTransform).GetComponent<ScoreboardEntryUI>().Initialise(highscore);
             * }*/

            for (int j = 0; j < savedScores.highscores.Count; j++)
            {
                savedScores.highscores[j].entryPosition = (j + 1);
                Instantiate(scoreboardEntryObject, highscoresHolderTransform).GetComponent <ScoreboardEntryUI>().Initialise(savedScores.highscores[j]);
            }
        }