Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        /// <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));
        }