IPatchGraphManager ISerializer.Load(string filename) { PatchGraph patchGraph; string xml; IPatchGraphManager patchGraphManager = new PatchGraphManager(); try { Tracer.Log("Application.persistentDataPath + Others.SavesFolder + filename" + Application.persistentDataPath + Others.SavesFolder + filename); xml = File.ReadAllText(Application.persistentDataPath + Others.SavesFolder + filename); using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(PatchGraph)); patchGraph = (PatchGraph)xmlSerializer.Deserialize(memoryStream); } SerializedPatch[] serializedPatches = patchGraph.patches; SerializedPatch serializedPatch; Dictionary <int, Patch> patches = new Dictionary <int, Patch>(); Patch patch; for (int i = 0; i < serializedPatches.Length; i++) { serializedPatch = serializedPatches[i]; patch = new Patch() { Id = serializedPatch.id, Code = serializedPatch.code, PosX = serializedPatch.PosX, PosY = serializedPatch.PosY, Values = new SortedList <string, float>() }; foreach (Parameter parameter in serializedPatch.parameters) { patch.Values.Add(parameter.name, parameter.value); } patches.Add(patch.Id, patch); } ((PatchGraphManager)patchGraphManager).patches = patches; Dictionary <int, Connection> connections = new Dictionary <int, Connection>(); foreach (Connection connection in patchGraph.connections) { patches[connection.SourcePatch].GetOutputConnections().Add(connection); patches[connection.TargetPatch].GetInputConnections().Add(connection); connections.Add(connection.Id, connection); } ((PatchGraphManager)patchGraphManager).connections = connections; ((PatchGraphManager)patchGraphManager).maxId = patchGraph.maxId; } catch (Exception e) { Tracer.Log(e.Message + e.StackTrace); } return(patchGraphManager); }
IPatchGraphManager ISerializer.Load(string filename) { IPatchGraphManager patchGraphManager; string json; try { Tracer.Log("Application.persistentDataPath + Others.SavesFolder + filename" + Application.persistentDataPath + Others.SavesFolder + filename); json = File.ReadAllText(Application.persistentDataPath + Others.SavesFolder + filename); using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(json))) { DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(PatchGraphManager)); patchGraphManager = (PatchGraphManager)deserializer.ReadObject(memoryStream); } } catch (Exception e) { Tracer.Log(e.Message + e.StackTrace); patchGraphManager = new PatchGraphManager(); } return(patchGraphManager); }