public static string Serialize(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            Type type = obj.GetType();

            if (type.IsEnum)
            {
                return(BloxStringSerializer.GetData((int)obj));
            }
            if (type.IsArray)
            {
                return(BloxStringSerializer.SerializeArray(obj));
            }
            if (type.IsGenericType)
            {
                if (type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    return(BloxStringSerializer.SerializeList(obj));
                }
                return(null);
            }
            if (BloxStringSerializer.writers.ContainsKey(type))
            {
                return(BloxStringSerializer.writers[type](obj));
            }
            return(JsonUtility.ToJson(obj));
        }
 static BloxStringSerializer()
 {
     BloxStringSerializer.writers = new Dictionary <Type, Func <object, string> >();
     BloxStringSerializer.readers = new Dictionary <Type, Func <string, object> >();
     BloxStringSerializer.writers[typeof(bool)]       = ((object value) => BloxStringSerializer.GetData((bool)value));
     BloxStringSerializer.writers[typeof(byte)]       = ((object value) => BloxStringSerializer.GetData((byte)value));
     BloxStringSerializer.writers[typeof(sbyte)]      = ((object value) => BloxStringSerializer.GetData((sbyte)value));
     BloxStringSerializer.writers[typeof(char)]       = ((object value) => BloxStringSerializer.GetData((char)value));
     BloxStringSerializer.writers[typeof(int)]        = ((object value) => BloxStringSerializer.GetData((int)value));
     BloxStringSerializer.writers[typeof(uint)]       = ((object value) => BloxStringSerializer.GetData((uint)value));
     BloxStringSerializer.writers[typeof(short)]      = ((object value) => BloxStringSerializer.GetData((short)value));
     BloxStringSerializer.writers[typeof(ushort)]     = ((object value) => BloxStringSerializer.GetData((ushort)value));
     BloxStringSerializer.writers[typeof(long)]       = ((object value) => BloxStringSerializer.GetData((long)value));
     BloxStringSerializer.writers[typeof(ulong)]      = ((object value) => BloxStringSerializer.GetData((ulong)value));
     BloxStringSerializer.writers[typeof(float)]      = ((object value) => BloxStringSerializer.GetData((float)value));
     BloxStringSerializer.writers[typeof(double)]     = ((object value) => BloxStringSerializer.GetData((double)value));
     BloxStringSerializer.writers[typeof(decimal)]    = ((object value) => BloxStringSerializer.GetData((decimal)value));
     BloxStringSerializer.writers[typeof(string)]     = ((object value) => BloxStringSerializer.GetData((string)value));
     BloxStringSerializer.writers[typeof(Vector2)]    = ((object value) => BloxStringSerializer.GetData((Vector2)value));
     BloxStringSerializer.writers[typeof(Vector3)]    = ((object value) => BloxStringSerializer.GetData((Vector3)value));
     BloxStringSerializer.writers[typeof(Vector4)]    = ((object value) => BloxStringSerializer.GetData((Vector4)value));
     BloxStringSerializer.writers[typeof(Quaternion)] = ((object value) => BloxStringSerializer.GetData((Quaternion)value));
     BloxStringSerializer.writers[typeof(Rect)]       = ((object value) => BloxStringSerializer.GetData((Rect)value));
     BloxStringSerializer.writers[typeof(Color)]      = ((object value) => BloxStringSerializer.GetData((Color)value));
     BloxStringSerializer.writers[typeof(Color32)]    = ((object value) => BloxStringSerializer.GetData((Color32)value));
     BloxStringSerializer.readers[typeof(bool)]       = ((string data) => BloxStringSerializer.ToBool(data));
     BloxStringSerializer.readers[typeof(byte)]       = ((string data) => BloxStringSerializer.ToByte(data));
     BloxStringSerializer.readers[typeof(sbyte)]      = ((string data) => BloxStringSerializer.ToSByte(data));
     BloxStringSerializer.readers[typeof(char)]       = ((string data) => BloxStringSerializer.ToChar(data));
     BloxStringSerializer.readers[typeof(int)]        = ((string data) => BloxStringSerializer.ToInt(data));
     BloxStringSerializer.readers[typeof(uint)]       = ((string data) => BloxStringSerializer.ToUInt(data));
     BloxStringSerializer.readers[typeof(short)]      = ((string data) => BloxStringSerializer.ToShort(data));
     BloxStringSerializer.readers[typeof(ushort)]     = ((string data) => BloxStringSerializer.ToUShort(data));
     BloxStringSerializer.readers[typeof(long)]       = ((string data) => BloxStringSerializer.ToLong(data));
     BloxStringSerializer.readers[typeof(ulong)]      = ((string data) => BloxStringSerializer.ToULong(data));
     BloxStringSerializer.readers[typeof(float)]      = ((string data) => BloxStringSerializer.ToFloat(data));
     BloxStringSerializer.readers[typeof(double)]     = ((string data) => BloxStringSerializer.ToDouble(data));
     BloxStringSerializer.readers[typeof(decimal)]    = ((string data) => BloxStringSerializer.ToDecimal(data));
     BloxStringSerializer.readers[typeof(string)]     = ((string data) => BloxStringSerializer.ToString(data));
     BloxStringSerializer.readers[typeof(Vector2)]    = ((string data) => BloxStringSerializer.ToVector2(data));
     BloxStringSerializer.readers[typeof(Vector3)]    = ((string data) => BloxStringSerializer.ToVector3(data));
     BloxStringSerializer.readers[typeof(Vector4)]    = ((string data) => BloxStringSerializer.ToVector4(data));
     BloxStringSerializer.readers[typeof(Quaternion)] = ((string data) => BloxStringSerializer.ToQuaternion(data));
     BloxStringSerializer.readers[typeof(Rect)]       = ((string data) => BloxStringSerializer.ToRect(data));
     BloxStringSerializer.readers[typeof(Color)]      = ((string data) => BloxStringSerializer.ToColor(data));
     BloxStringSerializer.readers[typeof(Color32)]    = ((string data) => BloxStringSerializer.ToColor32(data));
 }