private TopTenList orderTopTen(TopTenList currentList) { int size = currentList.theTopTenList.Count; for (int i = 0; i <= size; i++) { for (int j = i + 1; j < size; j++) { if (currentList.theTopTenList[j].score > currentList.theTopTenList[i].score) { TopTenEntry tmp = currentList.theTopTenList[i]; currentList.theTopTenList[i] = currentList.theTopTenList[j]; currentList.theTopTenList[j] = tmp; } } } //Debug.Log(JsonUtility.ToJson(currentList)); string jsonTT = JsonUtility.ToJson(currentList); PlayerPrefs.SetString("topTenList", jsonTT); PlayerPrefs.Save(); // Need to check if null ? // for (int k=0; k<= FGlist.highscoreEntryList.Count; k++) { // for (int l=0; l<= AList.highscoreEntryList.Count; l++) { // for(int m=0; m<= MCList.highscoreEntryList.Count; m++) { // if (MCList.highscoreEntryList[m] >= AList.highscoreEntryList[l] && MCList.highscoreEntryList[m] >= FGlist.highscoreEntryList[k]) { // HighscoreEntry tmp = new HighscoreEntry{score = MCList.highscoreEntryList[m], skin = skin3}; // // topTenList.Add(tmp); // } // else { // break; // } // } // if (AList.highscoreEntryList[m] >= AList.highscoreEntryList[l] && MCList.highscoreEntryList[m] >= FGlist.highscoreEntryList[k]) { // //HighscoreEntry tmp = new HighscoreEntry{score = MCList.highscoreEntryList[m], skin = skin3}; // } // else { // break; // } // } // } return(currentList); }
private void AddHighscoreEntry(int thePlayersScore) { if (thePlayersScore > currTopTenList.theTopTenList[0].score) { FindObjectOfType <AudioManager>().Play("HighScore"); } if (PlayerPrefs.GetString("selectedChar") == "FallGuy") { // Create Entry object TopTenEntry testEntry = new TopTenEntry { score = thePlayersScore, selChar = "skin1" }; // Retrieve the current top ten scores from PlayerPref variable currTopTenList = JsonUtility.FromJson <TopTenList>(PlayerPrefs.GetString("topTenList")); // Add Entry object into current top ten list currTopTenList.theTopTenList.Add(testEntry); // Convert current top ten list into a Json string string ttJson = JsonUtility.ToJson(currTopTenList); // Save string to a PlayerPref variable for persistent data PlayerPrefs.SetString("topTenList", ttJson); //Debug.Log(PlayerPrefs.GetString("topTenList")); PlayerPrefs.Save(); } if (PlayerPrefs.GetString("selectedChar") == "alex") { // Create Entry object TopTenEntry testEntry = new TopTenEntry { score = thePlayersScore, selChar = "skin2" }; // Retrieve the current top ten scores from PlayerPref variable currTopTenList = JsonUtility.FromJson <TopTenList>(PlayerPrefs.GetString("topTenList")); // Add Entry object into current top ten list currTopTenList.theTopTenList.Add(testEntry); // Convert current top ten list into a Json string string ttJson = JsonUtility.ToJson(currTopTenList); // Save string to a PlayerPref variable for persistent data PlayerPrefs.SetString("topTenList", ttJson); //Debug.Log(PlayerPrefs.GetString("topTenList")); PlayerPrefs.Save(); } if (PlayerPrefs.GetString("selectedChar") == "MC") { // Create Entry object TopTenEntry testEntry = new TopTenEntry { score = thePlayersScore, selChar = "skin3" }; // Retrieve the current top ten scores from PlayerPref variable currTopTenList = JsonUtility.FromJson <TopTenList>(PlayerPrefs.GetString("topTenList")); // Add Entry object into current top ten list currTopTenList.theTopTenList.Add(testEntry); // Convert current top ten list into a Json string string ttJson = JsonUtility.ToJson(currTopTenList); // Save string to a PlayerPref variable for persistent data PlayerPrefs.SetString("topTenList", ttJson); //Debug.Log(PlayerPrefs.GetString("topTenList")); PlayerPrefs.Save(); } //Debug.Log(PlayerPrefs.GetString("highscoresA")); //Debug.Log(PlayerPrefs.GetString("highscoresFG")); //Debug.Log(PlayerPrefs.GetString("highscoresMC")); }