Exemplo n.º 1
0
        public void OnAfterDeserialize(object self)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                refType_ = null;
#if UNITY_EDITOR
                instance = null;
#endif
                return;
            }

            if (refType_ == null || refType_.Instance == null || refType_.FullName != typeName)
            {
                refType_ = new RefType(typeName);
            }

#if !CloseNested
            if (anyValue != null && !string.IsNullOrEmpty(anyValue.dataKey))
            {
                // 数据因为预置体嵌套被修改了,不完整了,使用TypeSerialize数据来初始化
                MonoSerialize.MergeFrom(refType_.Instance, anyValue);
            }
            else
            {
#endif
            MonoSerialize.MergeFrom(refType_.Instance, bytes, objs);
#if !CloseNested
        }
#endif
            refType_.TrySetProperty("csObj", self);

#if UNITY_EDITOR
            instance = refType_.Instance;
#endif
        }
Exemplo n.º 2
0
        int ITypeSerialize.CalculateSize(object value)
        {
            if (value == null)
            {
                return(0);
            }

            int total = 0;

            for (int i = 0; i < fieldInfos.Count; ++i)
            {
                var fieldInfo = fieldInfos[i];
                var cv        = fieldInfo.GetValue(value);
                if (cv == null)
                {
                    continue;
                }

                var fieldType = fieldInfo.FieldType;
                total += WRStream.ComputeStringSize(fieldInfo.Name);
                int size = MonoSerialize.GetByType(fieldInfo).CalculateSize(cv);
                total += WRStream.ComputeLengthSize(size);
                total += size;
            }

            return(total);
        }
Exemplo n.º 3
0
 public void OnBeforeSerialize()
 {
     if (instance == null)
     {
         if (string.IsNullOrEmpty(typeName))
         {
             bytes = null;
             if (objs != null)
             {
                 objs.Clear();
             }
             else
             {
                 objs = new List <Object>();
             }
             refType_ = null;
             instance = null;
         }
     }
     else
     {
         if (!isDllChange())
         {
             var ms = MonoSerialize.WriteTo(instance);
             bytes = ms.GetBytes();
             objs  = ms.objs;
         }
         else
         {
             refType_ = null;
             instance = null;
         }
     }
 }
Exemplo n.º 4
0
        public void OnAfterDeserialize(object self)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            refType_ = new RefType(typeName, self);
            MonoSerialize.MergeFrom(refType_.Instance, bytes, objs);
        }
Exemplo n.º 5
0
        public void BytesToAnyValue()
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            var rt = new RefType(typeName);

            MonoSerialize.MergeFrom(rt.Instance, bytes, objs);

            anyValue = MonoSerialize.WriteToTS(rt.Instance);
        }
Exemplo n.º 6
0
        public void SaveToTS()
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            var rt = new RefType(typeName);

            MonoSerialize.MergeFrom(rt.Instance, bytes, objs);
            anyValue    = MonoSerialize.WriteToTS(rt.Instance);
            bytesCrc32  = Crc32.To(bytes);
            bytesLength = bytes.Length;
        }
Exemplo n.º 7
0
        public void AnyValueToBytes()
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            var rt = new RefType(typeName);

            MonoSerialize.MergeFrom(rt.Instance, anyValue);

            var ms = MonoSerialize.WriteTo(rt.Instance);

            bytes = ms.GetBytes();
            objs  = ms.objs;
        }
Exemplo n.º 8
0
        public void OnBeforeSerialize()
        {
            if (instance == null)
            {
                if (string.IsNullOrEmpty(typeName))
                {
                    bytes = null;
                    if (objs != null)
                    {
                        objs.Clear();
                    }
                    else
                    {
                        objs = new List <Object>();
                    }
                    refType_ = null;
                    instance = null;
#if !CloseNested
                    bytesLength = 0;
                    bytesCrc32  = 0;
                    anyValue    = null;
#endif
                }
            }
            else
            {
                if (!isDllChange())
                {
                    var ms = MonoSerialize.WriteTo(instance);
                    bytes = ms.GetBytes();
                    objs  = ms.objs;
#if !CloseNested
                    bytesCrc32 = Crc32.To(bytes);
                    var ab = MonoSerialize.WriteToTS(instance);
                    Nested.Any0.Blend(ab, anyValue);
                    anyValue    = (Nested.Any0)ab.clone();
                    bytesLength = bytes.Length;
#endif
                }
                else
                {
                    refType_ = null;
                    instance = null;
                }
            }
        }
Exemplo n.º 9
0
        void Init()
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return;
            }

            if (refType == null)
            {
                refType = new RefType(typeName, this);
            }
            MonoSerialize.MergeFrom(refType.Instance, bytes, objs);

#if UNITY_EDITOR
            instance = refType.Instance;
#endif
        }
Exemplo n.º 10
0
        public void OnAfterDeserialize(object self)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                refType_ = null;
                return;
            }

            if (refType_ == null || refType_.Instance == null || refType_.FullName != typeName)
            {
                refType_ = new RefType(typeName);
            }
            MonoSerialize.MergeFrom(refType_.Instance, bytes, objs);
            refType_.TrySetProperty("csObj", self);

#if UNITY_EDITOR
            instance = refType_.Instance;
#endif
        }
Exemplo n.º 11
0
        void ITypeSerialize.WriteTo(object value, MonoStream ms)
        {
            if (value == null)
            {
                return;
            }

            var            stream = ms.Stream;
            ITypeSerialize ts     = this;

            for (int i = 0; i < fieldInfos.Count; ++i)
            {
                var    field = fieldInfos[i];
                object cv    = field.GetValue(value);
                if (cv == null)
                {
                    continue;
                }

                ts = MonoSerialize.GetByType(field);

                stream.WriteString(field.Name);
                int count = ts.CalculateSize(cv);
                if (count == 0)
                {
                    continue;
                }

                stream.WriteLength(count);
#if UNITY_EDITOR
                int write_pos = stream.WritePos;
#endif
                ts.WriteTo(cv, ms);
#if UNITY_EDITOR
                if (stream.WritePos != write_pos + count)
                {
                    UnityEngine.Debug.LogErrorFormat("type:{0} CalculateSize error!", ts.GetType().Name);
                }
#endif
            }
        }
Exemplo n.º 12
0
        void ISerializationCallbackReceiver.OnBeforeSerialize()
        {
#if UNITY_EDITOR
            if (instance == null)
            {
                bytes = null;
                if (objs != null)
                {
                    objs.Clear();
                }
                else
                {
                    objs = new List <Object>();
                }
                refType = null;
            }
            else
            {
                var ms = MonoSerialize.WriteTo(instance);
                bytes = ms.Stream.GetBytes();
                objs  = ms.objs;
            }
#endif
        }
Exemplo n.º 13
0
        public void MergeFrom(ref object value, MonoStream ms)
        {
            if (value == null)
            {
                value = IL.Help.Create(type);
            }

            WRStream stream = ms.Stream;

            while (stream.ReadSize != 0)
            {
                var fieldName = stream.ReadString();
                var length    = stream.ReadLength();
                if (length == 0)
                {
                }
                else
                {
                    int endPos = stream.WritePos;
                    stream.WritePos = stream.ReadPos + length;
                    try
                    {
                        var fieldInfo = fieldInfos.Find((field) => { return(fieldName == field.Name); });
                        if (fieldInfo == null)
                        {
                            stream.ReadPos += length;
                        }
                        else
                        {
                            object cv = fieldInfo.GetValue(value);
                            //bool isSet = false;
                            //if (cv == null)
                            //{
                            //    cv = IL.Help.Create(fieldInfo.FieldType);
                            //    //isSet = true;
                            //}

                            MonoSerialize.GetByType(fieldInfo).MergeFrom(ref cv, ms);
                            //if (isSet || !cv.GetType().IsClass || cv.GetType().FullName == "System.String")
                            {
                                fieldInfo.SetValue(value, cv);
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        UnityEngine.Debug.LogException(ex);
                    }
                    finally
                    {
#if UNITY_EDITOR
                        if (stream.ReadSize != 0)
                        {
                            UnityEngine.Debug.LogErrorFormat("type:{0} fieldName:{1} length:{2}", type.Name, fieldName, length);
                        }
#endif
                        stream.WritePos = endPos;
                    }
                }
            }
        }
Exemplo n.º 14
0
 public IListAnyType(System.Type arrayType, System.Type elementType)
 {
     this.arrayType       = arrayType;
     this.elementType     = elementType;
     elementTypeSerialize = MonoSerialize.GetByType(elementType);
 }