Exemplo n.º 1
0
        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);

            SaveScores(savedScores);
        }
Exemplo n.º 2
0
 private void SaveScores(ScoreboardSaveData scoreboardSaveData)
 {
     using (StreamWriter stream = new StreamWriter(SavePath))
     {
         string json = JsonUtility.ToJson(scoreboardSaveData, true);
         stream.Write(json);
     }
 }
Exemplo n.º 3
0
        private void Start()
        {
            Debug.Log(Application.persistentDataPath);
            ScoreboardSaveData savedScores = GetSavedScores();


            SaveScores(savedScores);

            UpdateUI(savedScores);
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        public void AddTestEntry()
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.typegame", FileMode.Open);
            Save            save = (Save)bf.Deserialize(file);

            file.Close();
            int    newScore = save.score;
            string newName  = PlayerPrefs.GetString("playerNAME");;

            Debug.Log(Application.persistentDataPath);
            ScoreboardSaveData  savedScores         = GetSavedScores();
            ScoreboardEntryData scoreBoardEntryData = new ScoreboardEntryData();

            scoreBoardEntryData.entryName  = newName;
            scoreBoardEntryData.entryScore = newScore;
            AddEntry(scoreBoardEntryData);
            Debug.Log("NAME AND SCORE: " + newName + " " + newScore);
            //AddEntry(testEntrydata);
        }