public static byte[] Serialize(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms, System.Text.Encoding.UTF8);

            System.Type t = obj.GetType();
            byte        header;

            if (!TypesToHeader.TryGetValue(t, out header))
            {
#if NETFX_CORE
                if (!System.Reflection.IntrospectionExtensions.GetTypeInfo(t).IsEnum)
#else
                if (!t.IsEnum)
#endif

                {
                    return(null);
                }
                header = HeaderEnum;
            }
            writer.Write(header);
            switch (header)
            {
            case HeaderFloat: { writer.Write((float)obj); break; }

            case HeaderInt: { writer.Write((int)obj); break; }

            case HeaderShort: { writer.Write((short)obj); break; }

            case HeaderByte: { writer.Write((byte)obj); break; }

            case HeaderColor: { Color c = (Color)obj; writer.Write(c.r); writer.Write(c.g); writer.Write(c.b); writer.Write(c.a); break; }

            case HeaderVector2: { Vector2 v = (Vector2)obj; writer.Write(v.x); writer.Write(v.y); break; }

            case HeaderVector3: { Vector3 v = (Vector3)obj; writer.Write(v.x); writer.Write(v.y); writer.Write(v.z); break; }

            case HeaderVector4: { Vector4 v = (Vector4)obj; writer.Write(v.x); writer.Write(v.y); writer.Write(v.z); writer.Write(v.w); break; }

            case HeaderQuaternion: { Quaternion q = (Quaternion)obj; writer.Write(q.x); writer.Write(q.y); writer.Write(q.z); writer.Write(q.w); break; }

            case HeaderBool: { writer.Write((bool)obj); break; }

            case HeaderFloatRange: { RangeOfFloats v = (RangeOfFloats)obj; writer.Write(v.Minimum); writer.Write(v.Maximum); break; }

            case HeaderIntRange: { RangeOfIntegers v = (RangeOfIntegers)obj; writer.Write(v.Minimum); writer.Write(v.Maximum); break; }

            case HeaderEnum: { writer.Write((int)obj); break; }
            }
            return(ms.ToArray());
        }
        private void RenderRangeOfInts(Rect rect, WeatherMakerPropertyTransition t, FieldInfo field, SingleLineClampAttribute clamp)
        {
            GUIContent      labelMin = new GUIContent("Min", "Minimum Value (Inclusive)");
            GUIContent      labelMax = new GUIContent("Max", "Maximum Value (Inclusive)");
            RangeOfIntegers r        = (RangeOfIntegers)GetFieldValue(field, t);
            float           w        = rect.width;

            rect.width *= 0.5f;
            rect.width -= 6.0f;
            r.Minimum   = EditorGUI.IntField(rect, labelMin, r.Minimum);
            rect.x     += rect.width + 6.0f;
            r.Maximum   = EditorGUI.IntField(rect, labelMax, r.Maximum);
            t.Value     = r;
        }