using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using System.Runtime.Serialization.Formatters.Binary; public class SaveInventorySystem : MonoBehaviour { public static void SaveInventoryItemsList(Dictionary equitabbleItemList, string ElementName) { BinaryFormatter formatter = new BinaryFormatter(); // todo: add in scene name folder string path = SaveSystem.GetSavePath(); Debug.Log("Saved Inventory at " + path); if (!Directory.Exists(path)) Directory.CreateDirectory(path); path += "/" + ElementName + ".fun"; FileStream stream = new FileStream(path, FileMode.Create); Dictionary data = new Dictionary(); foreach(KeyValuePair equitabbleItemEntry in equitabbleItemList) { data[equitabbleItemEntry.Key] = new EquippableItemPrefarbAssetData(equitabbleItemEntry.Value); } formatter.Serialize(stream, data); stream.Close(); } private static void Save() { } public static Dictionary LoadInventoryItemsList(string ElementName) { string path = SaveSystem.GetSavePath() + "/" + ElementName + ".fun"; if(File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); Dictionary equitabbleItemList = formatter.Deserialize(stream) as Dictionary; stream.Close(); return equitabbleItemList; } else { Debug.Log("Save file not found in " + path); return null; } } }