/// <summary> /// Saves the achivements as JSON to file. /// </summary> public static void SaveAchievementsToFile(Achievement[] achievements) { string json = AchievementJsonHelper.ToJson(achievements); StreamWriter writer = new StreamWriter(achievementFilePath, false); writer.WriteLine(json); writer.Close(); }
/// <summary> /// Returns the achivements saved in a JSON file. /// </summary> public static Achievement[] LoadAchievementsFromFile() { Achievement[] achievements; // Generate a new set of achievements if the file does not exist if (!File.Exists(achievementFilePath)) { Debug.Log("Achievements file could not be found, creating new set of achievements"); achievements = GenerateSetOfAchievements(); SaveAchievementsToFile(achievements); } string fileContent = File.ReadAllText(achievementFilePath); return(AchievementJsonHelper.FromJson(fileContent)); }