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

105 lines
3.2 KiB
C#
Raw 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;
2022-11-06 21:34:17 +01:00
public static void SaveEquitableItem(EquippableItemPrefabAsset 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);
2022-11-06 21:34:17 +01:00
path += "/" + equitabbleItem.Name + ".fun";
FileStream stream = new FileStream(path, FileMode.Create);
2022-11-06 21:34:17 +01:00
EquippableItemPrefabAssetData data = new EquippableItemPrefabAssetData(equitabbleItem);
formatter.Serialize(stream, data);
stream.Close();
}
2022-11-06 21:34:17 +01:00
public static void SaveEquitableItemList(List<EquippableItemPrefabAsset> 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);
2022-11-06 21:34:17 +01:00
List<EquippableItemPrefabAssetData> data = new List<EquippableItemPrefabAssetData>();
2022-11-06 21:34:17 +01:00
foreach(EquippableItemPrefabAsset equitabbleItem in equitabbleItemList)
{
2022-11-06 21:34:17 +01:00
data.Add(new EquippableItemPrefabAssetData(equitabbleItem));
}
formatter.Serialize(stream, data);
stream.Close();
}
private static void Save()
{
}
2022-11-06 21:34:17 +01:00
public static EquippableItemPrefabAssetData 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);
2022-11-06 21:34:17 +01:00
EquippableItemPrefabAssetData equitabbleItem = formatter.Deserialize(stream) as EquippableItemPrefabAssetData;
stream.Close();
return equitabbleItem;
} else {
Debug.Log("Save file not found in " + path);
return null;
}
}
2022-11-06 21:34:17 +01:00
public static List<EquippableItemPrefabAssetData> 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);
2022-11-06 21:34:17 +01:00
List<EquippableItemPrefabAssetData> equitabbleItemList = formatter.Deserialize(stream) as List<EquippableItemPrefabAssetData>;
stream.Close();
return equitabbleItemList;
} else {
Debug.Log("Save file not found in " + path);
return null;
}
}
private static void Load()
{
}
}