Beispiel #1
0
        /// <summary>
        /// Save the equipment data to the JSON file that this
        /// EquipmentDictionary references.
        /// </summary>
        public void Save()
        {
            string jsonString =
                JsonUtility.ToJson(EquipmentData.ForEquipment(equipment), true);
            var directoryPath =
                Path.Combine(Application.persistentDataPath, folderName);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            using (StreamWriter streamWriter = File.CreateText(path))
            {
                streamWriter.Write(jsonString);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Load the equipment data from the JSON file that this
        /// EquipmentDictionary references.
        /// </summary>
        public void Load()
        {
            if (File.Exists(path))
            {
                using (StreamReader streamReader = File.OpenText(path))
                {
                    string        jsonString = streamReader.ReadToEnd();
                    EquipmentData loadedData =
                        JsonUtility.FromJson <EquipmentData>(jsonString);
                    data = loadedData;

                    // Load the actual equipment
                    foreach (EquipmentEntry entry in loadedData.Entries)
                    {
                        equipment[entry.Slot] = entry.Item;
                    }
                }
            }
        }