/// <summary> /// 反序列化数组、列表 /// </summary> /// <param name="propertyName"></param> /// <param name="jsonReader"></param> /// <returns></returns> private bool ArrayDeserialize(string propertyName, JsonReader jsonReader) { if (propertyName == "battleUnits") { //先移除所有战斗单位 RemoveAllBattleUntis(); allBattleUnits = allBattleUnits ?? new List <BattleUnit>(); DeserializeArrayHelper dah = DeserializeArrayHelper.Create(); //这个数组的每个对象都是obj dah.ObjectDeserializeCallback = delegate(int index, JsonReader jr) { //反序列化每个战斗单位 BattleUnit battleUnit = SingletonRecyclePool <BattleUnit> .Get(); battleUnit.Deserialize(jr); allBattleUnits.Add(battleUnit); }; dah.Deserialize(jsonReader, true); return(true); } return(false); }
/// <summary> /// 反序列化对象 /// </summary> /// <param name="propertyName"></param> /// <param name="jsonReader"></param> /// <returns></returns> private bool ObjectDeserialize(string propertyName, JsonReader jsonReader) { if (propertyName == "battleMap") { if (battleMap != null) { battleMap.Return(); } //重新创建地图 battleMap = SingletonRecyclePool <BattleMap> .Get(); battleMap.Deserialize(jsonReader); return(true); } return(false); }