Exemple #1
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (_Type.IsGenericType && _Type.GetGenericTypeDefinition() == typeof(List <>))
            {
                if (_Type.GetGenericArguments().Length == 1)
                {
                    ByteWriter var_Writer = new ByteWriter();

                    if (_Object == null)
                    {
                        var_Writer.Write((bool)true);
                        _Bytes = var_Writer.ToArray();
                        return(true);
                    }
                    else
                    {
                        var_Writer.Write((bool)false);
                    }

                    //

                    Type var_GenericItemType = _Type.GetGenericArguments()[0];

                    IList var_List = _Object as IList;

                    var_Writer.Write((UInt16)var_List.Count);

                    if (PrimitiveTypeMatcher.TypeHashSet.Contains(_Type))
                    {
                        for (int i = 0; i < var_List.Count; i++)
                        {
                            var_Writer.Write(var_GenericItemType, var_List[i]);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < var_List.Count; i++)
                        {
#pragma warning disable
                            byte[] var_Bytes = Serializer.Internal_Serialize(var_GenericItemType, var_List[i]);
#pragma warning restore
                            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                        }
                    }

                    _Bytes = var_Writer.ToArray();
                    return(true);
                }
            }

            _Bytes = null;
            return(false);
        }
        private void InternSerialize(Object _Object, ByteWriter _Writer, List <Type> _SerializeAbleBaseList, int _CurrentIndex)
        {
            Type var_CurrentType = _SerializeAbleBaseList[_CurrentIndex];

            //
            FieldInfo[] var_FoundFields;
            int[]       var_FoundFieldsId;
            bool[]      var_FoundFieldsOptional;

            FieldContext.LoadFields(var_CurrentType, out var_FoundFields, out var_FoundFieldsId, out var_FoundFieldsOptional);

            _Writer.Write((byte)var_FoundFields.Length);

            for (int i = 0; i < var_FoundFields.Length; i++)
            {
                //
                _Writer.Write((byte)var_FoundFieldsId[i]);

                //
                var var_FieldType = var_FoundFields[i].FieldType;

                //
                var var_Objectvalue = var_FoundFields[i].GetValue(_Object);

                if (PrimitiveTypeMatcher.TypeHashSet.Contains(var_FieldType))
                {
                    _Writer.Write(var_FieldType, var_Objectvalue);
                }
                else
                {
#pragma warning disable
                    byte[] var_Bytes = Serializer.Internal_Serialize(var_FieldType, var_Objectvalue);
#pragma warning restore
                    _Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                }
            }

            if (_CurrentIndex == _SerializeAbleBaseList.Count - 1)
            {
                return;
            }

            this.InternSerialize(_Object, _Writer, _SerializeAbleBaseList, _CurrentIndex + 1);
        }
Exemple #3
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (!_Type.IsNullable())
            {
                _Bytes = null;
                return(false);
            }

            Type var_UnderlyingType = _Type.GetNullableUnderlyingType();

            ByteWriter var_Writer = new ByteWriter();

            if (_Object == null)
            {
                var_Writer.Write(true);
                _Bytes = var_Writer.ToArray();
                return(true);
            }
            else
            {
                var_Writer.Write(false);

                if (PrimitiveTypeMatcher.TypeHashSet.Contains(var_UnderlyingType))
                {
                    var_Writer.Write(var_UnderlyingType, _Object);
                }
                else
                {
#pragma warning disable
                    byte[] var_Bytes = Serializer.Internal_Serialize(var_UnderlyingType, _Object);
#pragma warning restore
                    var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                }

                _Bytes = var_Writer.ToArray();
            }

            return(true);
        }
Exemple #4
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (_Type.IsGenericType && _Type.GetGenericTypeDefinition() == typeof(Queue <>))
            {
                ByteWriter var_Writer = new ByteWriter();

                if (_Object == null)
                {
                    var_Writer.Write((bool)true);
                    _Bytes = var_Writer.ToArray();
                    return(true);
                }
                else
                {
                    var_Writer.Write((bool)false);
                }

                //
                Type var_GenericItemType = _Type.GetGenericArguments()[0];

                IEnumerable var_Enumerable = _Object as IEnumerable;

                int        var_ItemCount  = 0;
                ByteWriter var_ItemWriter = new ByteWriter();

                if (PrimitiveTypeMatcher.TypeDictionary.ContainsKey(var_GenericItemType))
                {
                    IEnumerator var_Enumerator = var_Enumerable.GetEnumerator();
                    while (var_Enumerator.MoveNext())
                    {
                        Object var_Current = var_Enumerator.Current;

                        var_ItemWriter.Write(var_GenericItemType, var_Current);

                        var_ItemCount += 1;
                    }
                }
                else
                {
                    IEnumerator var_Enumerator = var_Enumerable.GetEnumerator();
                    while (var_Enumerator.MoveNext())
                    {
                        Object var_Current = var_Enumerator.Current;

                        byte[] var_Bytes = Serializer.Internal_Serialize(var_GenericItemType, var_Current);
                        var_ItemWriter.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

                        var_ItemCount += 1;
                    }
                }

                var_Writer.Write((UInt16)var_ItemCount);

                byte[] var_ItemBytes = var_ItemWriter.ToArray();
                var_Writer.WriteBytesAndSize(var_ItemBytes, var_ItemBytes.Length);

                _Bytes = var_Writer.ToArray();
                return(true);
            }

            _Bytes = null;
            return(false);
        }
Exemple #5
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (!_Type.IsArray)
            {
                _Bytes = null;
                return(false);
            }

            ByteWriter var_Writer = new ByteWriter();

            if (_Object == null)
            {
                var_Writer.Write((bool)true);
                _Bytes = var_Writer.ToArray();
                return(true);
            }
            else
            {
                var_Writer.Write((bool)false);
            }

            //

            Array var_Array = _Object as Array;

            Type var_ElementType = _Type.GetElementType();

            //Write dimensions!
            int var_Rank = var_Array.Rank;

            var_Writer.Write((int)var_Rank);
            //Go through each dimension and write the length!
            int[] var_ArrayLength = new int[var_Array.Rank];
            for (int d = 0; d < var_Array.Rank; d++)
            {
                var_ArrayLength[d] = (int)var_Array.GetLength(d);
                var_Writer.Write((int)var_Array.GetLength(d));
            }
            //Go through each dimension and write the lowerbound!
            int[] var_ArrayLowerBound = new int[var_Array.Rank];
            for (int d = 0; d < var_Array.Rank; d++)
            {
                var_ArrayLowerBound[d] = (int)var_Array.GetLowerBound(d);
                var_Writer.Write((int)var_Array.GetLowerBound(d));
            }

            if (var_Rank == 1)
            {
                ArrayIndexer_D_1 arrayIndexer = new ArrayIndexer_D_1(var_ArrayLength[0], var_ArrayLowerBound[0]);

                if (PrimitiveTypeMatcher.TypeHashSet.Contains(var_ElementType))
                {
                    int[] var_IndexArray = new int[1];
                    while (arrayIndexer.MoveNext())
                    {
                        var_IndexArray[0] = arrayIndexer.Current_0;

                        var_Writer.Write(var_ElementType, var_Array.GetValue(var_IndexArray));
                    }
                }
                else
                {
                    int[] var_IndexArray = new int[1];
                    while (arrayIndexer.MoveNext())
                    {
                        var_IndexArray[0] = arrayIndexer.Current_0;

#pragma warning disable
                        byte[] var_Bytes = Serializer.Internal_Serialize(var_ElementType, var_Array.GetValue(var_IndexArray));
#pragma warning restore
                        var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                    }
                }
            }
            else if (var_Rank == 2)
            {
                ArrayIndexer_D_2 arrayIndexer = new ArrayIndexer_D_2(var_ArrayLength[0], var_ArrayLength[1], var_ArrayLowerBound[0], var_ArrayLowerBound[1]);

                if (PrimitiveTypeMatcher.TypeHashSet.Contains(var_ElementType))
                {
                    int[] var_IndexArray = new int[2];
                    while (arrayIndexer.MoveNext())
                    {
                        var_IndexArray[0] = arrayIndexer.Current_0;
                        var_IndexArray[1] = arrayIndexer.Current_1;

                        var_Writer.Write(var_ElementType, var_Array.GetValue(var_IndexArray));
                    }
                }
                else
                {
                    int[] var_IndexArray = new int[2];
                    while (arrayIndexer.MoveNext())
                    {
                        var_IndexArray[0] = arrayIndexer.Current_0;
                        var_IndexArray[1] = arrayIndexer.Current_1;

#pragma warning disable
                        byte[] var_Bytes = Serializer.Internal_Serialize(var_ElementType, var_Array.GetValue(var_IndexArray));
#pragma warning restore
                        var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                    }
                }
            }
            else
            {
                ArrayIndexer_D_N arrayIndexer = new ArrayIndexer_D_N(var_ArrayLength, var_ArrayLowerBound);

                if (PrimitiveTypeMatcher.TypeHashSet.Contains(var_ElementType))
                {
                    while (arrayIndexer.MoveNext())
                    {
                        var_Writer.Write(var_ElementType, var_Array.GetValue(arrayIndexer.Current));
                    }
                }
                else
                {
                    while (arrayIndexer.MoveNext())
                    {
#pragma warning disable
                        byte[] var_Bytes = Serializer.Internal_Serialize(var_ElementType, var_Array.GetValue(arrayIndexer.Current));
#pragma warning restore
                        var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                    }
                }
            }

            _Bytes = var_Writer.ToArray();
            return(true);
        }
Exemple #6
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (_Type != typeof(Mesh))
            {
                _Bytes = null;
                return(false);
            }

            ByteWriter var_Writer = new ByteWriter();

            if (_Object == null)
            {
                var_Writer.Write((bool)true);
                _Bytes = var_Writer.ToArray();
                return(true);
            }
            else
            {
                var_Writer.Write((bool)false);
            }

            //

            Mesh var_Mesh = _Object as Mesh;

#pragma warning disable
            //Bindposes
            byte[] var_Bytes = Serializer.Internal_Serialize(typeof(Matrix4x4[]), var_Mesh.bindposes);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //BoneWeights
            var_Bytes = Serializer.Internal_Serialize(typeof(BoneWeight[]), var_Mesh.boneWeights);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //Bounds
            var_Bytes = Serializer.Internal_Serialize(typeof(Bounds), var_Mesh.bounds);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //Vertices
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector3[]), var_Mesh.vertices);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //Normals
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector3[]), var_Mesh.normals);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //Colors
            var_Bytes = Serializer.Internal_Serialize(typeof(Color[]), var_Mesh.colors);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //Colors32
            var_Bytes = Serializer.Internal_Serialize(typeof(Color32[]), var_Mesh.colors32);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //UV
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector2[]), var_Mesh.uv);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector2[]), var_Mesh.uv2);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector2[]), var_Mesh.uv3);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector2[]), var_Mesh.uv4);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

            //SubMeshCount
            var_Writer.Write(var_Mesh.subMeshCount);
            for (int s = 0; s < var_Mesh.subMeshCount; s++)
            {
                var_Bytes = Serializer.Internal_Serialize(typeof(int[]), var_Mesh.GetIndices(s));
                var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);

                var_Writer.Write((byte)var_Mesh.GetTopology(s));

                var_Bytes = Serializer.Internal_Serialize(typeof(int[]), var_Mesh.GetTriangles(s));
                var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
            }

            //Tangents
            var_Bytes = Serializer.Internal_Serialize(typeof(Vector4[]), var_Mesh.tangents);
            var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
#pragma warning restore

            _Bytes = var_Writer.ToArray();
            return(true);
        }
Exemple #7
0
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (!_Type.IsArray)
            {
                _Bytes = null;
                return(false);
            }

            ByteWriter var_Writer = new ByteWriter();

            if (_Object == null)
            {
                var_Writer.Write((bool)true);
                _Bytes = var_Writer.ToArray();
                return(true);
            }
            else
            {
                var_Writer.Write((bool)false);
            }

            //

            Array var_Array = _Object as Array;

            Type var_ElementType = _Type.GetElementType();

            //Write dimensions!
            var_Writer.Write((int)var_Array.Rank);
            //Go through each dimension and write the length!
            int[] var_ArrayLength = new int[var_Array.Rank];
            for (int d = 0; d < var_Array.Rank; d++)
            {
                var_ArrayLength[d] = (int)var_Array.GetLength(d);
                var_Writer.Write((int)var_Array.GetLength(d));
            }
            //Go through each dimension and write the lowerbound!
            int[] var_ArrayLowerBound = new int[var_Array.Rank];
            for (int d = 0; d < var_Array.Rank; d++)
            {
                var_ArrayLowerBound[d] = (int)var_Array.GetLowerBound(d);
                var_Writer.Write((int)var_Array.GetLowerBound(d));
            }

            ArrayIndexer arrayIndexer = new ArrayIndexer(var_ArrayLength, var_ArrayLowerBound);

            if (PrimitiveTypeMatcher.TypeDictionary.ContainsKey(var_ElementType))
            {
                while (arrayIndexer.MoveNext())
                {
                    var_Writer.Write(var_ElementType, var_Array.GetValue(arrayIndexer.Current));
                }
            }
            else
            {
                while (arrayIndexer.MoveNext())
                {
                    byte[] var_Bytes = Serializer.Internal_Serialize(var_ElementType, var_Array.GetValue(arrayIndexer.Current));
                    var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
                }
            }

            _Bytes = var_Writer.ToArray();
            return(true);
        }
        public bool Serialize(Type _Type, object _Object, out byte[] _Bytes)
        {
            if (_Type != typeof(Collider2D))
            {
                _Bytes = null;
                return(false);
            }

            ByteWriter var_Writer = new ByteWriter();

            if (_Object == null)
            {
                var_Writer.Write((bool)true);
                _Bytes = var_Writer.ToArray();
                return(true);
            }
            else
            {
                var_Writer.Write((bool)false);
            }

            //

            Collider2D var_Collider = _Object as Collider2D;

            //Shared
            var_Writer.Write(var_Collider.enabled);
            var_Writer.Write(var_Collider.density);
            var_Writer.Write(var_Collider.isTrigger);
            var_Writer.Write(var_Collider.offset);

            if (var_Collider is BoxCollider2D)
            {
                var_Writer.Write(((BoxCollider2D)var_Collider).autoTiling);
                var_Writer.Write(((BoxCollider2D)var_Collider).edgeRadius);
                var_Writer.Write(((BoxCollider2D)var_Collider).size);
            }
            if (var_Collider is EdgeCollider2D)
            {
                var_Writer.Write(((EdgeCollider2D)var_Collider).edgeRadius);

                byte[] var_Bytes = Serializer.Internal_Serialize(typeof(Vector2[]), ((EdgeCollider2D)var_Collider).points);
                var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
            }
            else if (var_Collider is CapsuleCollider2D)
            {
                var_Writer.Write((int)((CapsuleCollider2D)var_Collider).direction);
                var_Writer.Write(((CapsuleCollider2D)var_Collider).size);
            }
            else if (var_Collider is CircleCollider2D)
            {
                var_Writer.Write(((CircleCollider2D)var_Collider).radius);
            }
            else if (var_Collider is PolygonCollider2D)
            {
                var_Writer.Write(((PolygonCollider2D)var_Collider).autoTiling);
                var_Writer.Write(((PolygonCollider2D)var_Collider).pathCount);

                byte[] var_Bytes = Serializer.Internal_Serialize(typeof(Vector2[]), ((PolygonCollider2D)var_Collider).points);
                var_Writer.WriteBytesAndSize(var_Bytes, var_Bytes.Length);
            }

            _Bytes = var_Writer.ToArray();
            return(true);
        }