Scriptum/Assets/Scripts/REFACTORING/Application/Panel/Task/SaveTaskManager.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2022-10-22 18:04:21 +02:00
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
public class SaveTaskDataManager : SaveModelSystem<Task>
{
public override bool SaveModelItem(Task model)
{
return base.SaveModelItem(model);
}
public override bool SaveModelList(List<Task> list)
{
BinaryFormatter formatter = new BinaryFormatter();
Debug.Log("Saved Quest at " + Path);
if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
FileStream stream = new FileStream(
Path + GetFileName(ObjectListName),
FileMode.Create
);
formatter.Serialize(stream, list);
stream.Close();
return true;
}
public override Task LoadModelItem()
{
return base.LoadModelItem();
}
public override List<Task> LoadModelList()
2022-10-22 18:04:21 +02:00
{
string path = Path + GetFileName(ObjectListName);
if(File.Exists(path))
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(path, FileMode.Open);
List<Task> questsList = formatter.Deserialize(stream) as List<Task>;
stream.Close();
return questsList;
} else {
Debug.Log("Save file not found in " + path);
}
return new List<Task>();
}
}