예제 #1
0
    //Resets ranking to original state
    public static void ResetRanking()
    {
        ranking = null;

        string path = Application.dataPath;

        string filePath = System.IO.Path.Combine(Application.persistentDataPath, gameDataProjectFilePath);

        File.Delete(filePath);

        SaveRanking();
    }
예제 #2
0
 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);
     }
 }
예제 #3
0
    //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);
    }