void Sort() { List <LocalPlayerInfoJson> sortedTemp = data.OrderByDescending(x => x.score).ToList(); if (sortedTemp != null && sortedTemp.Count > 2) { //Debug.Log("AFTER SORT"); //for (int i = 0; i < sortedTemp.Count; i++) //{ // Debug.Log(sortedTemp[i].name + " : " + sortedTemp[i].score + "\n"); ////} if (sortedTemp.Count > 10) { lastScore = sortedTemp[placesList.Count - 1].score; lastName = sortedTemp[placesList.Count - 1].name; Debug.Log("Last name: " + lastName + " | " + "Last score: " + lastScore); } Populate(sortedTemp); if (newlyAdded != null) { Debug.Log("Newlyadded: " + newlyAdded.score); for (int i = 0; i < sortedTemp.Count; i++) { if (newlyAdded == sortedTemp[i]) { int index = sortedTemp.FindIndex(x => x.score == newlyAdded.score && x.name == newlyAdded.name); //Debug.Log("index: " + index); HighlightNewlyAdded(index); newlyAdded = null; } } } else { Debug.Log("No newly added place!"); } } else { Populate(sortedTemp); if (newlyAdded != null) { Debug.Log("Newlyadded: " + newlyAdded.score); for (int i = 0; i < sortedTemp.Count; i++) { if (newlyAdded == sortedTemp[i]) { int index = sortedTemp.FindIndex(x => x.score == newlyAdded.score && x.name == newlyAdded.name); //Debug.Log("index: " + index); HighlightNewlyAdded(index); newlyAdded = null; } } } Debug.Log("Not enough to sort!"); } }
// Use this to add info to leaderboard public LocalPlayerInfoJson CreatePlayerInfo(string _name, int _score) { LocalPlayerInfoJson info = new LocalPlayerInfoJson { name = _name, score = _score, }; return(info); }
public void AddPlayerInfo(LocalPlayerInfoJson pInfo) { newlyAdded = pInfo; data.Add(pInfo); string saveJsonStr = JsonArrayUtility.ToJson(data, true); JsonFileUtility.WriteJsonToFile(SAVEFILENAME, saveJsonStr, JSONSTATE.PERSISTENT_DATA_PATH); Debug.Log("Saving as JSON " + saveJsonStr); Sort(); }
// Testing func to randomly add users LocalPlayerInfoJson RandomAddUser() { LocalPlayerInfoJson temp = new LocalPlayerInfoJson(); string[] names = { "abc", "cba", "asd", "ghj", "you" }; int randName = Random.Range(0, names.Length); int randScore = Random.Range(50, 1000); temp.name = names[randName]; temp.score = randScore; return(temp); }