int BoolField(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.toggleStart)
        {
            EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUILayout.Toggle(dispName, sp.boolValue);

            if (EditorGUI.EndChangeCheck())
            {
                sp.boolValue = newValue;
            }

            EditorGUI.EndProperty();

            if (!sp.boolValue)
            {
                return(v.toggleSize);
            }
        }
        else
        {
            EditorGUILayout.PropertyField(sp, new GUIContent(dispName));
        }

        return(0);
    }
    void FloatField(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.limitType == InspectorPlusVar.LimitType.Min && !sp.hasMultipleDifferentValues)
        {
            sp.floatValue = Mathf.Max(v.min, sp.floatValue);
        }
        else if (v.limitType == InspectorPlusVar.LimitType.Max && !sp.hasMultipleDifferentValues)
        {
            sp.floatValue = Mathf.Min(v.max, sp.floatValue);
        }

        if (v.limitType == InspectorPlusVar.LimitType.Range)
        {
            if (!v.progressBar)
            {
                EditorGUILayout.Slider(sp, v.min, v.max);
            }
            else
            {
                if (!sp.hasMultipleDifferentValues)
                {
                    sp.floatValue = Mathf.Clamp(sp.floatValue, v.min, v.max);
                    ProgressBar((sp.floatValue - v.min) / v.max, dispName);
                }
                else
                {
                    ProgressBar((sp.floatValue - v.min) / v.max, dispName);
                }
            }
        }
        else
        {
            EditorGUILayout.PropertyField(sp, new GUIContent(dispName));
        }
    }
    void VectorScene(InspectorPlusVar v, string s, Transform t)
    {
        Vector3 val;

        if (s == typeof(Vector3).Name)
        {
            val = (Vector3)GetTargetField(name);
        }
        else
        {
            val = (Vector3)((Vector2)GetTargetField(name));
        }

        Vector3 newVal   = Vector3.zero;
        Vector3 curVal   = Vector3.zero;
        bool    setVal   = false;
        bool    relative = v.relative;
        bool    scale    = v.scale;

        switch (v.vectorDrawType)
        {
        case InspectorPlusVar.VectorDrawType.Direction:
            curVal = relative ? val:val - t.position;
            float size = scale ? Mathf.Min(2.0f, Mathf.Sqrt(curVal.magnitude) / 2.0f) : 1.0f;
            size *= HandleUtility.GetHandleSize(t.position);
            Handles.ArrowCap(0, t.position, curVal != Vector3.zero ? Quaternion.LookRotation(val.normalized) : Quaternion.identity, size);
            break;

        case InspectorPlusVar.VectorDrawType.Point:
            curVal = relative ? val:t.position + val;
            Handles.SphereCap(0, curVal, Quaternion.identity, 0.1f);
            break;

        case InspectorPlusVar.VectorDrawType.PositionHandle:
            curVal = relative ? t.position + val:val;
            setVal = true;
            newVal = Handles.PositionHandle(curVal, Quaternion.identity) - (relative ? t.position : Vector3.zero);
            break;

        case InspectorPlusVar.VectorDrawType.Scale:
            setVal = true;
            curVal = relative ? t.localScale + val :val;
            newVal = Handles.ScaleHandle(curVal, t.position + v.offset, t.rotation, HandleUtility.GetHandleSize(t.position + v.offset)) - (relative ? t.localScale : Vector3.zero);
            break;

        case InspectorPlusVar.VectorDrawType.Rotation:
            setVal = true;
            curVal = relative ? val + t.rotation.eulerAngles : val;
            newVal = Handles.RotationHandle(Quaternion.Euler(curVal), t.position + v.offset).eulerAngles - (relative?t.rotation.eulerAngles:Vector3.zero);
            break;
        }

        if (setVal)
        {
            object newObjectVal = newVal;

            if (s == typeof(Vector2).Name)
            {
                newObjectVal = (Vector2)newVal;
            }
            else if (s == typeof(Quaternion).Name)
            {
                newObjectVal = Quaternion.Euler(newVal);
            }

            SetTargetField(name, newObjectVal);
        }
    }
    public override void OnInspectorGUI()
    {
        so.Update();
        RefreshVars();

        EditorGUIUtility.LookLikeControls(135.0f, 50.0f);

        for (int i = 0; i < properties.Length; i += 1)
        {
            InspectorPlusVar v = vars[i];

            if (v.active && properties[i] != null)
            {
                SerializedProperty sp = properties [i]; string s = v.type;
                bool skip = false;
                name     = v.name;
                dispName = v.dispName;

                GUI.enabled = v.canWrite;

                GUILayout.BeginHorizontal();

                if (v.toggleLevel != 0)
                {
                    GUILayout.Space(v.toggleLevel * 10.0f);
                }

                if (s == typeof(float).Name)
                {
                    FloatField(sp, v);
                    skip = true;
                }
                if (s == typeof(bool).Name)
                {
                    i   += BoolField(sp, v);
                    skip = true;
                }
                if (!skip)
                {
                    PropertyField(sp, name);
                }
                GUILayout.EndHorizontal();
                GUI.enabled = true;
                if (v.hasTooltip)
                {
                    Rect last = GUILayoutUtility.GetLastRect();
                    GUI.Label(last, new GUIContent("", v.tooltip));

                    GUIStyle style = new GUIStyle();
                    style.fixedWidth = 250.0f;
                    style.wordWrap   = true;

                    Vector2 size = new GUIStyle().CalcSize(new GUIContent(GUI.tooltip));
                    tooltipRect = new Rect(Event.current.mousePosition.x + 4.0f, Event.current.mousePosition.y + 12.0f, 28.0f + size.x, 9.0f + size.y);

                    if (tooltipRect.width > 250.0f)
                    {
                        float delt = (tooltipRect.width - 250.0f);
                        tooltipRect.width  -= delt;
                        tooltipRect.height += size.y * Mathf.CeilToInt(delt / 250.0f);
                    }
                }
            }
        }
        so.ApplyModifiedProperties();
        if (!string.IsNullOrEmpty(GUI.tooltip))
        {
            GUI.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
            GUI.Box(tooltipRect, new GUIContent());
            EditorGUI.HelpBox(tooltipRect, GUI.tooltip, MessageType.Info);
            Repaint();
        }
        GUI.tooltip = "";
        //NOTE NOTE NOTE: WATERMARK HERE
        //You are free to remove this
        //START REMOVE HERE
        GUILayout.BeginHorizontal();
        GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.3f);
        GUILayout.FlexibleSpace();
        GUILayout.Label("Created with");
        GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.6f);
        if (GUILayout.Button("Inspector++"))
        {
            Application.OpenURL("http://forum.unity3d.com/threads/136727-Inspector-Meh-to-WOW-inspectors");
        }
        GUI.color = new Color(1.0f, 1.0f, 1.0f);
        GUILayout.EndHorizontal();
        //END REMOVE HERE
    }