示例#1
0
 public RefTypeSerialize(System.Type type)
 {
     this.type     = type;
     typeSerialize = BinarySerializable.GetByType(type);
 }
示例#2
0
        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);
        }
示例#3
0
 public static void MergeFrom(object obj, Nested.AnyBase ab)
 {
     BinarySerializable.MergeFrom(obj, ab);
 }