示例#1
0
 /// <summary>
 /// Loads the achievement data using JsonUtility
 /// You can change the desired save/load path in AchievementController.cs
 /// </summary>
 public static void Load()
 {
     if (SaveExists())
     {
         AchievementProgressDataCollection progressCollection = JsonUtility.FromJson <AchievementProgressDataCollection>
                                                                    (File.ReadAllText(Application.persistentDataPath + saveDataPath + "/achievement-save.json"));
         for (int i = 0; i < achievementMaster.Count; i++)
         {
             SetValue(progressCollection.achievementProgressList[i].id, progressCollection.achievementProgressList[i].value, false);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Saves the achievement progress data using JsonUtility
        /// You can change the desired save/load path in AchievementController.cs
        /// </summary>
        public static void Save()
        {
            AchievementProgressDataCollection progressCollection = new AchievementProgressDataCollection();

            foreach (Achievement achievement in achievementMaster)
            {
                progressCollection.achievementProgressList.Add(new AchievementProgressData(achievement.id, achievement.value));
            }
            string jsonString = JsonUtility.ToJson(progressCollection, true);

            // This method creates the directory for the data IF it doesn't already exist.
            // No explicit check required.
            Directory.CreateDirectory(Application.persistentDataPath + saveDataPath);
            File.WriteAllText(Application.persistentDataPath + saveDataPath + "/achievement-save.json", jsonString);
        }