59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
|
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<int, EquippableItemPrefarbAsset> 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<int, EquippableItemPrefarbAssetData> data = new Dictionary<int, EquippableItemPrefarbAssetData>();
|
||
|
|
||
|
foreach(KeyValuePair<int, EquippableItemPrefarbAsset> equitabbleItemEntry in equitabbleItemList)
|
||
|
{
|
||
|
data[equitabbleItemEntry.Key] = new EquippableItemPrefarbAssetData(equitabbleItemEntry.Value);
|
||
|
}
|
||
|
|
||
|
formatter.Serialize(stream, data);
|
||
|
stream.Close();
|
||
|
}
|
||
|
|
||
|
private static void Save()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
public static Dictionary<int, EquippableItemPrefarbAssetData> 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<int, EquippableItemPrefarbAssetData> equitabbleItemList = formatter.Deserialize(stream) as Dictionary<int, EquippableItemPrefarbAssetData>;
|
||
|
stream.Close();
|
||
|
|
||
|
return equitabbleItemList;
|
||
|
} else {
|
||
|
Debug.Log("Save file not found in " + path);
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|