Scriptum/Assets/Scripts/SceneManager/SaveItem/SaveEquitableItemSystem.cs

105 lines
3.3 KiB
C#
Raw Permalink Normal View History

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<EquippableItemPrefarbAsset> 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<EquippableItemPrefarbAssetData> data = new List<EquippableItemPrefarbAssetData>();
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<EquippableItemPrefarbAssetData> 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<EquippableItemPrefarbAssetData> equitabbleItemList = formatter.Deserialize(stream) as List<EquippableItemPrefarbAssetData>;
stream.Close();
return equitabbleItemList;
} else {
Debug.Log("Save file not found in " + path);
return null;
}
}
private static void Load()
{
}
}