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