103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Runtime.Serialization.Formatters.Binary;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
class SaveMultiDialogueManager : SaveModelSystem<MultiDialogueData>
|
|||
|
{
|
|||
|
public override bool SaveModelItem(MultiDialogueData model)
|
|||
|
{
|
|||
|
return base.SaveModelItem(model);
|
|||
|
}
|
|||
|
|
|||
|
public override bool SaveModelList(List<MultiDialogueData> list)
|
|||
|
{
|
|||
|
BinaryFormatter formatter = new BinaryFormatter();
|
|||
|
|
|||
|
Debug.Log("Saved MultiDialogue list at " + Path);
|
|||
|
|
|||
|
if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
|
|||
|
|
|||
|
/* Main logic of conversion data format */
|
|||
|
var data = list; // ConvertObjectsListToListOfDataModels(list);
|
|||
|
|
|||
|
FileStream stream = new FileStream(
|
|||
|
Path + GetFileName(ObjectListName),
|
|||
|
FileMode.Create
|
|||
|
);
|
|||
|
|
|||
|
formatter.Serialize(stream, data);
|
|||
|
stream.Close();
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override MultiDialogueData LoadModelItem()
|
|||
|
{
|
|||
|
return base.LoadModelItem();
|
|||
|
}
|
|||
|
|
|||
|
public override List<MultiDialogueData> LoadModelList()
|
|||
|
{
|
|||
|
string path = Path + GetFileName(ObjectListName);
|
|||
|
|
|||
|
if (File.Exists(path))
|
|||
|
{
|
|||
|
BinaryFormatter formatter = new BinaryFormatter();
|
|||
|
FileStream stream = new FileStream(path, FileMode.Open);
|
|||
|
|
|||
|
List<MultiDialogueData> dialogueList = formatter.Deserialize(stream) as List<MultiDialogueData>;
|
|||
|
stream.Close();
|
|||
|
|
|||
|
return dialogueList; // ConvertListOfDataModelsToListOfObject(questsList);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.Log("Save file not found in " + path);
|
|||
|
}
|
|||
|
|
|||
|
return new List<MultiDialogueData>();
|
|||
|
}
|
|||
|
|
|||
|
// ----------------- USELLES IN THIS CLASS -----------------
|
|||
|
#region unused
|
|||
|
// Support function
|
|||
|
|
|||
|
// 1. From model to data format
|
|||
|
public static MultiDialogueData ConvertObjectToDataModel(MultiDialogue model)
|
|||
|
{
|
|||
|
return new MultiDialogueData(model);
|
|||
|
}
|
|||
|
|
|||
|
public static List<MultiDialogueData> ConvertObjectsListToListOfDataModels(List<MultiDialogue> modelsList)
|
|||
|
{
|
|||
|
List<MultiDialogueData> convertedList = new List<MultiDialogueData>();
|
|||
|
|
|||
|
foreach (MultiDialogue model in modelsList)
|
|||
|
{
|
|||
|
convertedList.Add(ConvertObjectToDataModel(model));
|
|||
|
}
|
|||
|
|
|||
|
return convertedList;
|
|||
|
}
|
|||
|
|
|||
|
// 2. From data to model format
|
|||
|
public static MultiDialogue ConvertDataModelToObject(MultiDialogueData dataModel)
|
|||
|
{
|
|||
|
return (MultiDialogue)dataModel.MapDataToObject();
|
|||
|
}
|
|||
|
|
|||
|
public static List<MultiDialogue> ConvertListOfDataModelsToListOfObject(List<MultiDialogueData> dataModelsList)
|
|||
|
{
|
|||
|
List<MultiDialogue> convertedList = new List<MultiDialogue>();
|
|||
|
|
|||
|
foreach (MultiDialogueData dataModel in dataModelsList)
|
|||
|
{
|
|||
|
convertedList.Add(ConvertDataModelToObject(dataModel));
|
|||
|
}
|
|||
|
|
|||
|
return convertedList;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|