Exemplo n.º 1
0
        public static void MergeFrom(object obj, byte[] bytes, List <Object> objs)
        {
            if (bytes == null || bytes.Length == 0)
            {
                return;
            }

            var ts = GetByInstance(obj);

            if (ts == null)
            {
                return;
            }

            try
            {
                WRStream stream = new WRStream(bytes);
                stream.WritePos = bytes.Length;
                var ms = new MonoStream(stream, objs);
                ts.MergeFrom(ref obj, ms);
            }
            catch (System.Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Exemplo n.º 2
0
        void ITypeSerialize.MergeFrom(ref object value, MonoStream ms)
        {
            int lenght = ms.Stream.ReadLength();
            var array  = value as Object[];

            if (array == null || array.Length != lenght)
            {
                array = new Object[lenght];
                value = array;
            }

            var stream = ms.Stream;

            for (int i = 0; i < lenght; ++i)
            {
                short pos = stream.ReadInt16();
                if (pos == -1)
                {
                    array[i] = null;
                }
                else
                {
                    array[i] = ms.objs[pos];
                }
            }
        }
Exemplo n.º 3
0
        public static MonoStream WriteTo(object obj)
        {
            MonoStream ms = new MonoStream(new WRStream(512), new List <Object>());

            GetByInstance(obj).WriteTo(obj, ms);
            return(ms);
        }
Exemplo n.º 4
0
        void ITypeSerialize.WriteTo(object value, MonoStream ms)
        {
            if (value == null)
            {
                return;
            }

            ms.Stream.WriteInt16((short)ms.Add((Object)value));
        }
Exemplo n.º 5
0
 void ITypeSerialize.WriteTo(object value, MonoStream ms)
 {
     string[] array = value as string[];
     if (array != null)
     {
         ms.Stream.WriteLength(array.Length);
         var stream = ms.Stream;
         for (int i = 0; i < array.Length; ++i)
         {
             stream.WriteString(array[i]);
         }
     }
 }
Exemplo n.º 6
0
        void ITypeSerialize.WriteTo(object value, MonoStream ms)
        {
            Object[] array = (Object[])value;
            if (array == null)
            {
                return;
            }

            ms.Stream.WriteLength(array.Length);
            var stream = ms.Stream;

            for (int i = 0; i < array.Length; ++i)
            {
                stream.WriteInt16((short)ms.Add(array[i]));
            }
        }
Exemplo n.º 7
0
        void ITypeSerialize.MergeFrom(ref object value, MonoStream ms)
        {
            int lenght = ms.Stream.ReadLength();
            var array  = value as IList <T>;

            if (array == null || array.Count != lenght)
            {
                array = Create(lenght);
                value = array;
            }

            var stream = ms.Stream;

            for (int i = 0; i < lenght; ++i)
            {
                array[i] = Read(stream);
            }
        }
Exemplo n.º 8
0
        void ITypeSerialize.MergeFrom(ref object value, MonoStream ms)
        {
            int lenght = ms.Stream.ReadLength();
            var array  = value as string[];

            if (array == null || array.Length != lenght)
            {
                array = new string[lenght];
                value = array;
            }

            var stream = ms.Stream;

            for (int i = 0; i < lenght; ++i)
            {
                array[i] = stream.ReadString();
            }
        }
Exemplo n.º 9
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.º 10
0
        void ITypeSerialize.MergeFrom(ref object value, MonoStream ms)
        {
            var stream = ms.Stream;
            int lenght = stream.ReadLength();
            var array  = value as IList;

            if (array == null || array.Count != lenght)
            {
                array = Create(lenght);
                value = array;
            }

            for (int i = 0; i < lenght; ++i)
            {
                object v     = array[i];
                int    count = stream.ReadLength();
                if (count != 0)
                {
                    int endpos = stream.WritePos;
                    stream.WritePos = stream.ReadPos + count;
                    try
                    {
                        elementTypeSerialize.MergeFrom(ref v, ms);
                        array[i] = v;
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogException(ex);
                    }
                    finally
                    {
                        stream.WritePos = endpos;
                    }
                }
                else
                {
                    array[i] = null;
                }
            }
        }
Exemplo n.º 11
0
        void ITypeSerialize.WriteTo(object value, MonoStream ms)
        {
            IList array = (IList)value;

            if (array == null)
            {
                return;
            }

            var stream = ms.Stream;

            stream.WriteLength(array.Count);
            for (int i = 0; i < array.Count; ++i)
            {
                int count = elementTypeSerialize.CalculateSize(array[i]);
                stream.WriteLength(count);
                if (count != 0)
                {
                    elementTypeSerialize.WriteTo(array[i], ms);
                }
            }
        }
Exemplo n.º 12
0
        void ITypeSerialize.WriteTo(object value, MonoStream ms)
        {
            IList <T> array = (IList <T>)value;

            if (array == null)
            {
                return;
            }

            int count = array.Count;

            ms.Stream.WriteLength(count);

            if (array != null)
            {
                var stream = ms.Stream;
                for (int i = 0; i < count; ++i)
                {
                    Write(stream, array[i]);
                }
            }
        }
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
        void ITypeSerialize.MergeFrom(ref object parent, MonoStream ms)
        {
            var pos = ms.Stream.ReadInt16();

            parent = ms.objs[pos];
        }
Exemplo n.º 15
0
 void ITypeSerialize.MergeFrom(ref object value, MonoStream ms)
 {
     value = Read(ms.Stream);
 }
Exemplo n.º 16
0
        void ITypeSerialize.WriteTo(object obj, MonoStream ms)
        {
            T value = (T)obj;

            Write(ms.Stream, value);
        }