public static object GetValue(this NetDataReader reader, Type type) { #region Generic Values if (type.IsEnum) { type = type.GetEnumUnderlyingType(); } if (type == typeof(bool)) { return(reader.GetBool()); } if (type == typeof(byte)) { return(reader.GetByte()); } if (type == typeof(char)) { return(reader.GetChar()); } if (type == typeof(double)) { return(reader.GetDouble()); } if (type == typeof(float)) { return(reader.GetFloat()); } if (type == typeof(int)) { return(reader.GetPackedInt()); } if (type == typeof(long)) { return(reader.GetPackedLong()); } if (type == typeof(sbyte)) { return(reader.GetSByte()); } if (type == typeof(short)) { return(reader.GetPackedShort()); } if (type == typeof(string)) { return(reader.GetString()); } if (type == typeof(uint)) { return(reader.GetPackedUInt()); } if (type == typeof(ulong)) { return(reader.GetPackedULong()); } if (type == typeof(ushort)) { return(reader.GetPackedUShort()); } #endregion #region Unity Values if (type == typeof(Color)) { return(reader.GetColor()); } if (type == typeof(Quaternion)) { return(reader.GetQuaternion()); } if (type == typeof(Vector2)) { return(reader.GetVector2()); } if (type == typeof(Vector2Int)) { return(reader.GetVector2Int()); } if (type == typeof(Vector3)) { return(reader.GetVector3()); } if (type == typeof(Vector3Int)) { return(reader.GetVector3Int()); } if (type == typeof(Vector4)) { return(reader.GetVector4()); } #endregion if (typeof(INetSerializable).IsAssignableFrom(type)) { object instance = Activator.CreateInstance(type); (instance as INetSerializable).Deserialize(reader); return(instance); } throw new ArgumentException("NetDataReader cannot read type " + type.Name); }