/// <summary> /// 反序列化一场战斗 /// </summary> private void DeserializeBattleField() { if (!File.Exists(outputPath)) { UnityEditor.EditorUtility.DisplayDialog("错误", "找不到战斗序列化文件,请先序列化一场战斗...", "得嘞"); return; } battleField?.Return(); battleField = BattleField.Create(); using (TextReader rt = new StreamReader(outputPath)) { LitJson.JsonReader jsonReader = new LitJson.JsonReader(rt); var dh = DeserializeHelper.Create(); dh.ObjectDeserializeCallback = delegate(string propertyName, JsonReader reader) { if (propertyName == "battleField") { battleField.Deserialize(reader); return(true); } return(false); }; //开始反序列化 dh.Deserialize(jsonReader, true); } Debug.Log("反序列化完成"); //对反序列化战场进行序列化 if (battleField != null) { SerializeBattleFieldToPath(mirrorOutputPath); } }
public void Deserialize(JsonReader jsonReader) { if (jsonReader == null) { return; } DeserializeHelper dh = DeserializeHelper.Create(); dh.IntDeserializeCallback = IntDeserialize; dh.Deserialize(jsonReader, true); }
/// <summary> /// 反序列化战场 /// </summary> /// <param name="jsonReader"></param> public void Deserialize(JsonReader jsonReader) { if (jsonReader == null) { return; } DeserializeHelper dh = DeserializeHelper.Create(); //反序列化对象(暂时只有地图) dh.ObjectDeserializeCallback = ObjectDeserialize; //反序列化数组(暂时只有战斗单位) dh.ArrayDeserializeCallback = ArrayDeserialize; dh.Deserialize(jsonReader, true); }