예제 #1
0
        public void Load()
        {
            Debug.Log("Loading");
            if (filename != "")
            {
                if (File.Exists(filePath))
                {
                    using (StreamReader streamReader = File.OpenText(filePath))
                    {
                        var jsonString = streamReader.ReadToEnd();
                        var loadedData =
                            JsonUtility.FromJson <PerkListData>(jsonString);
                        data = loadedData;

                        foreach (var perk in loadedData.Perks)
                        {
                            Debug.Log("[" + name + "PerkList.Load] perk = " + perk);
                        }
                    }
                }
                else
                {
                    // We're creating the data for the first time
                    data = PerkListData.Empty();
                }
            }
        }
예제 #2
0
        public void Save(List <PerkPrototype> perkPrototypes)
        {
            var newData = PerkListData.ForPerkPrototypes(perkPrototypes);

            if (filename != "")
            {
                foreach (var perk in perkPrototypes)
                {
                    Debug.Log("[" + name + "PerkList.Save] perk = " + perk);
                }

                var jsonString = JsonUtility.ToJson(newData, true);

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

                using (StreamWriter streamWriter = File.CreateText(filePath))
                {
                    streamWriter.Write(jsonString);
                }
            }

            data = PerkListData.Null;
        }
예제 #3
0
 private void Reset()
 {
     data = PerkListData.Null;
 }