using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using System.Runtime.Serialization.Formatters.Binary; public static class SaveEquippableItemSystem { private static string map; public static void SaveEquitableItem(EquippableItemPrefarbAsset equitabbleItem, string ElementFolderName) { BinaryFormatter formatter = new BinaryFormatter(); // todo: add in scene name folder string path = SaveSystem.GetSavePath(ElementFolderName); Debug.Log(path); if (!Directory.Exists(path)) Directory.CreateDirectory(path); path += "/" + equitabbleItem.name + ".fun"; FileStream stream = new FileStream(path, FileMode.Create); EquippableItemPrefarbAssetData data = new EquippableItemPrefarbAssetData(equitabbleItem); formatter.Serialize(stream, data); stream.Close(); } public static void SaveEquitableItemList(List equitabbleItemList, string _path, string ElementName) { BinaryFormatter formatter = new BinaryFormatter(); // todo: add in scene name folder string path = SaveSystem.GetSavePath(_path); Debug.Log("Saved EquitableItemList at " + path); if (!Directory.Exists(path)) Directory.CreateDirectory(path); path += "/" + ElementName + ".fun"; FileStream stream = new FileStream(path, FileMode.Create); List data = new List(); foreach(EquippableItemPrefarbAsset equitabbleItem in equitabbleItemList) { data.Add(new EquippableItemPrefarbAssetData(equitabbleItem)); } formatter.Serialize(stream, data); stream.Close(); } private static void Save() { } public static EquippableItemPrefarbAssetData LoadEquitableItem(string equitabbleItemName, string ElementFolderName) { string path = SaveSystem.GetSavePath(ElementFolderName) + "/" + equitabbleItemName;// + ".fun"; if(File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); EquippableItemPrefarbAssetData equitabbleItem = formatter.Deserialize(stream) as EquippableItemPrefarbAssetData; stream.Close(); return equitabbleItem; } else { Debug.Log("Save file not found in " + path); return null; } } public static List LoadEquitableItemList(string _path, string ElementName) { string path = SaveSystem.GetSavePath(_path) + "/" + ElementName + ".fun"; if(File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); List equitabbleItemList = formatter.Deserialize(stream) as List; stream.Close(); return equitabbleItemList; } else { Debug.Log("Save file not found in " + path); return null; } } private static void Load() { } }