/** * Loads the highscore list from the player prefs */ private void Start() { for (var rank = 1; rank <= this.highscoreListLength; rank++) { if (PlayerPrefs.HasKey("Rank" + rank + "Name")) { var name = PlayerPrefs.GetString("Rank" + rank + "Name"); var score = PlayerPrefs.GetInt("Rank" + rank + "Score"); var scoreStruct = new Struct.Score(name, score); this.highscoreList.Add(scoreStruct); } } }
/** * Adds the given score to the highscore list if its high enough */ public void AddScore(string name, int score) { if (this.IsInHighscoreList(score)) { var scoreStruct = new Struct.Score(name, score); this.highscoreList.Add(scoreStruct); this.highscoreList = this.highscoreList.OrderByDescending(orderScoreStruct => orderScoreStruct.score).ToList(); // Remove the the last entry if the highscore list is longer that it should be if (this.highscoreList.Count > this.highscoreListLength) { this.highscoreList.RemoveAt(this.highscoreListLength); } this.Save(); } }
/** * Sets the row display data */ public void SetRowData(int rank, Struct.Score scoreStruct) { this.rank.text = rank + "."; this.playerName.text = scoreStruct.name; this.score.text = scoreStruct.score.ToString("n0"); }