Example #1
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);
        }
 public override void WriteArray(T inf, NetDataWriter w)
 {
     w.PutArray(GetterArr(inf), _maxLength);
 }
Example #3
0
        public static void PutValue <TType>(this NetDataWriter writer, TType value)
        {
            #region Generic Values
            if (value is bool)
            {
                writer.Put((bool)(object)value);
                return;
            }

            if (value is bool[])
            {
                writer.PutArray((bool[])(object)value);
                return;
            }

            if (value is byte)
            {
                writer.Put((byte)(object)value);
                return;
            }

            if (value is char)
            {
                writer.Put((char)(object)value);
                return;
            }

            if (value is double)
            {
                writer.Put((double)(object)value);
                return;
            }

            if (value is double[])
            {
                writer.PutArray((double[])(object)value);
                return;
            }

            if (value is float)
            {
                writer.Put((float)(object)value);
                return;
            }

            if (value is float[])
            {
                writer.PutArray((float[])(object)value);
                return;
            }

            if (value is int)
            {
                writer.Put((int)(object)value);
                return;
            }

            if (value is int[])
            {
                writer.PutArray((int[])(object)value);
                return;
            }

            if (value is long)
            {
                writer.Put((long)(object)value);
                return;
            }

            if (value is long[])
            {
                writer.PutArray((long[])(object)value);
                return;
            }

            if (value is sbyte)
            {
                writer.Put((sbyte)(object)value);
                return;
            }

            if (value is short)
            {
                writer.Put((short)(object)value);
                return;
            }

            if (value is short[])
            {
                writer.PutArray((short[])(object)value);
                return;
            }

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

            if (value is uint)
            {
                writer.Put((uint)(object)value);
                return;
            }

            if (value is uint[])
            {
                writer.PutArray((uint[])(object)value);
                return;
            }

            if (value is ulong)
            {
                writer.Put((ulong)(object)value);
                return;
            }

            if (value is ulong[])
            {
                writer.PutArray((ulong[])(object)value);
                return;
            }

            if (value is ushort)
            {
                writer.Put((ushort)(object)value);
                return;
            }

            if (value is ushort[])
            {
                writer.PutArray((ushort[])(object)value);
                return;
            }
            #endregion

            #region Unity Values
            if (value is Color)
            {
                writer.Put((Color)(object)value);
                return;
            }

            if (value is Quaternion)
            {
                writer.Put((Quaternion)(object)value);
                return;
            }

            if (value is Vector2)
            {
                writer.Put((Vector2)(object)value);
                return;
            }

            if (value is Vector2Int)
            {
                writer.Put((Vector2Int)(object)value);
                return;
            }

            if (value is Vector3)
            {
                writer.Put((Vector3)(object)value);
                return;
            }

            if (value is Vector3Int)
            {
                writer.Put((Vector3Int)(object)value);
                return;
            }

            if (value is Vector4)
            {
                writer.Put((Vector4)(object)value);
                return;
            }
            #endregion

            if (value is INetSerializable)
            {
                ((INetSerializable)value).Serialize(writer);
                return;
            }

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