public override void WriteArray(T inf, NetDataWriter w)
 {
     w.PutBytesWithLength(GetterArr(inf));
 }
Example #2
0
        public static void PutValue(this NetDataWriter writer, Type type, object value)
        {
            #region Generic Values
            if (type == typeof(bool))
            {
                writer.Put((bool)value);
                return;
            }

            if (type == typeof(bool[]))
            {
                writer.PutArray((bool[])value);
                return;
            }

            if (type == typeof(byte))
            {
                writer.Put((byte)value);
                return;
            }

            if (type == typeof(byte[]))
            {
                writer.PutBytesWithLength((byte[])value);
                return;
            }

            if (type == typeof(char))
            {
                writer.Put((char)value);
                return;
            }

            if (type == typeof(double))
            {
                writer.Put((double)value);
                return;
            }

            if (type == typeof(double[]))
            {
                writer.PutArray((double[])value);
                return;
            }

            if (type == typeof(float))
            {
                writer.Put((float)value);
                return;
            }

            if (type == typeof(float[]))
            {
                writer.PutArray((float[])value);
                return;
            }

            if (type == typeof(int))
            {
                writer.Put((int)value);
                return;
            }

            if (type == typeof(int[]))
            {
                writer.PutArray((int[])value);
                return;
            }

            if (type == typeof(long))
            {
                writer.Put((long)value);
                return;
            }

            if (type == typeof(long[]))
            {
                writer.PutArray((long[])value);
                return;
            }

            if (type == typeof(sbyte))
            {
                writer.Put((sbyte)value);
                return;
            }

            if (type == typeof(short))
            {
                writer.Put((short)value);
                return;
            }

            if (type == typeof(short[]))
            {
                writer.PutArray((short[])value);
                return;
            }

            if (type == typeof(string))
            {
                writer.Put((string)value);
                return;
            }

            if (type == typeof(uint))
            {
                writer.Put((uint)value);
                return;
            }

            if (type == typeof(uint[]))
            {
                writer.PutArray((uint[])value);
                return;
            }

            if (type == typeof(ulong))
            {
                writer.Put((ulong)value);
                return;
            }

            if (type == typeof(ulong[]))
            {
                writer.PutArray((ulong[])value);
                return;
            }

            if (type == typeof(ushort))
            {
                writer.Put((ushort)value);
                return;
            }

            if (type == typeof(ushort[]))
            {
                writer.PutArray((ushort[])value);
                return;
            }
            #endregion

            #region Unity Values
            if (type == typeof(Color))
            {
                writer.Put((Color)value);
                return;
            }

            if (type == typeof(Quaternion))
            {
                writer.Put((Quaternion)value);
                return;
            }

            if (type == typeof(Vector2))
            {
                writer.Put((Vector2)value);
                return;
            }

            if (type == typeof(Vector2Int))
            {
                writer.Put((Vector2Int)value);
                return;
            }

            if (type == typeof(Vector3))
            {
                writer.Put((Vector3)value);
                return;
            }

            if (type == typeof(Vector3Int))
            {
                writer.Put((Vector3Int)value);
                return;
            }

            if (type == typeof(Vector4))
            {
                writer.Put((Vector4)value);
                return;
            }
            #endregion

            if (typeof(INetSerializable).IsAssignableFrom(type))
            {
                (value as INetSerializable).Serialize(writer);
                return;
            }

            throw new ArgumentException("NetDataReader cannot write type " + value.GetType().Name);
        }