public static void SaveInventory(BagInventory inv) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/Inventory.fun"; FileStream stream = new FileStream(path, FileMode.Create); BagInventoryData data = new BagInventoryData(inv); formatter.Serialize(stream, data); stream.Close(); Debug.Log("Saved"); }
public static BagInventoryData LoadInventory() { string path = Application.persistentDataPath + "/Inventory.fun"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); BagInventoryData data = formatter.Deserialize(stream) as BagInventoryData; stream.Close(); Debug.Log("Loaded"); return(data); } else { Debug.Log("Save file not found in " + path); return(null); } }