void ITypeSerialize.MergeFrom(ref object value, IStream stream) { byte flag = stream.ReadByte(); if (flag == 0) { value = null; return; } byte flagType = stream.ReadByte(); int lenght = stream.ReadVarInt32(); bool isTypeTrue = flagType == elementTypeSerialize.typeFlag; // 类型是否一致 var array = value as IList; if (isTypeTrue && (array == null || array.Count != lenght)) { array = Create(lenght); value = array; } for (int i = 0; i < lenght; ++i) { int count = RLStream.ReadLength(stream); int endpos = stream.WritePos; stream.WritePos = stream.ReadPos + count; try { if (isTypeTrue) { object v = array[i]; elementTypeSerialize.MergeFrom(ref v, stream); array[i] = v; } else { #if UNITY_EDITOR if (stream.ReadSize != 0) { L.LogErrorFormat("IListAnyType stream.ReadSize != 0"); } #endif stream.ReadPos += count; } } catch (System.Exception ex) { L.LogException(ex); } finally { stream.WritePos = endpos; } } }
public void MergeFrom(ref object value, IStream stream) { byte flag = stream.ReadByte(); if (flag == 0) { value = null; return; } if (value == null) { value = IL.Help.Create(type); } if (flag == 2) { return; } do { byte typeFlag = stream.ReadByte(); var fieldName = stream.ReadString(); var length = RLStream.ReadLength(stream); int endPos = stream.WritePos; stream.WritePos = stream.ReadPos + length; try { var fieldInfo = FindFieldInfo(fieldName); ITypeSerialize bs; if (fieldInfo == null) { //L.LogFormat("type:{0} field:{1} typeFlag:{2} 字段不存在!", IL.Help.GetInstanceType(value).FullName, fieldName, typeFlag); stream.ReadPos += length; } else if ((bs = BinarySerializable.GetByFieldInfo(fieldInfo)).typeFlag != typeFlag) { // 类型与之前的有变化了 //L.LogFormat("type:{0} field:{1} typeFlag {2}->{3} 有变化!", IL.Help.GetInstanceType(value).FullName, fieldName, typeFlag, bs.typeFlag); stream.ReadPos += length; } else { object cv = fieldInfo.GetValue(value); bs.MergeFrom(ref cv, stream); if (typeFlag == TypeFlags.unityObjectType) { cv = UnityObjectSerialize.To((UnityEngine.Object)cv, fieldInfo.FieldType); } fieldInfo.SetValue(value, cv); } } catch (System.Exception ex) { wxb.L.LogException(ex); } finally { #if UNITY_EDITOR if (stream.ReadSize != 0) { wxb.L.LogErrorFormat("type:{0} fieldName:{1} length:{2}", type.Name, fieldName, length); } #endif stream.WritePos = endPos; } }while (stream.ReadSize != 0); }