public String Serialize() { Serial.EntitySerialize serialize = new Serial.EntitySerialize(); serialize.Frames = new List <Serial.S_Frame_Model>();; serialize.Lines = new List <Serial.S_Line_Model>(); foreach (EntityFrame_Model f in m_Elements.m_Frames.Values) { var s_f = new Serial.S_Frame_Model() { Pos_X = (int)f.UIEntity.Translation.X, Pos_Y = (int)f.UIEntity.Translation.Y, Code = f.UIEntity.m_MetaText, Name = f.Name, }; int s_f_paramcount = f.UIEntity.GetParamCount(); for (int i = 0; i < s_f_paramcount; i++) { s_f.Params.Add(f.UIEntity.GetParam(i)); } serialize.Frames.Add(s_f); } foreach (EntityLine_Model f in m_Elements.m_Lines.Values) { serialize.Lines.Add(new Serial.S_Line_Model() { Name = f.Name, from_index = f.from_index, from_Name = f.from_Name, from_SlotName = f.from_SlotName, to_index = f.to_index, to_Name = f.to_Name, to_SlotName = f.to_SlotName, }); } String json_str = Serial.JsonHelper.ToJson(serialize,serialize.GetType()); return(json_str); }
public String Deserialize(String json_str) { Serial.EntitySerialize serialize = (Serial.EntitySerialize)Serial.JsonHelper.FromJson(json_str,typeof(Serial.EntitySerialize)); foreach (Serial.S_Frame_Model f in serialize.Frames) { var entity = AddFrame(f.Name); entity.UIEntity.Translation = new System.Numerics.Vector3(f.Pos_X,f.Pos_Y,0); entity.UIEntity.SetCodeBox(f.Code); entity.UIEntity.Decode_Talker(); if (f.Params == null) { f.Params = new List <string>(); } int f_paramcount = f.Params.Count; for (int i = 0; i < f_paramcount; i++) { entity.UIEntity.SetParam(i,f.Params[i]); } } foreach (Serial.S_Line_Model f in serialize.Lines) { AddLine(new EntityLine_Model() { Name = f.Name, from_index = f.from_index, from_Name = f.from_Name, from_SlotName = f.from_SlotName, to_index = f.to_index, to_Name = f.to_Name, to_SlotName = f.to_SlotName, },f.Name); } //String json_str = Serial.JsonHelper.ToJson(serialize, serialize.GetType()); return(json_str); }