//returns loaded ranking objected public static ScoreDictionary LoadRanking() { string path = Application.dataPath; string filePath = System.IO.Path.Combine(Application.persistentDataPath, gameDataProjectFilePath); if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); ranking = JsonUtility.FromJson <ScoreDictionary>(dataAsJson); } else { //default ranking ranking = new ScoreDictionary(); ranking.Add("Purple Bug", 100); ranking.Add("Green Bug", 200); ranking.Add("Blue Bug", 50); ranking.Add("Cog", 10); ranking.Add("Gravity Robots Inc.", 500); } return(ranking); }
static void AddOrUpdate(ScoreDictionary dict, string key, int newValue) { //player already has score if (dict.ContainsKey(key)) { //update value only if new score is higher if (dict[key] < newValue) { dict[key] = newValue; } } else { //first score recorded for player dict.Add(key, newValue); } }