void OnEnable()
    {
        string styleMode = EditorPrefs.GetString(KEY_STYLE, "Settings");
        string stateMode = EditorPrefs.GetString(KEY_STATE, "Settings");

        styleEditMode       = (GUIStyleEditMode)System.Enum.Parse(typeof(GUIStyleEditMode), styleMode);
        stateEditMode       = (GUIStateEditMode)System.Enum.Parse(typeof(GUIStateEditMode), stateMode);
        previewControlIndex = EditorPrefs.GetInt(KEY_PREV_ID, 0);

        foldBorder = foldMargin = foldOverflow = foldPadding = foldFont = false;

        ResetCustomStyles();

        GUISkin editor = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);

        findStyleName       = "ToolbarSeachTextField";
        searchTextField     = ArrayUtility.Find <GUIStyle>(editor.customStyles, MatchCustomStyle);
        findStyleName       = "ToolbarSeachCancelButton";
        searchClearButton   = ArrayUtility.Find <GUIStyle>(editor.customStyles, MatchCustomStyle);
        findStyleName       = "ToolbarPopup";
        previewToolbarPopup = ArrayUtility.Find <GUIStyle>(editor.customStyles, MatchCustomStyle);
    }
    public override void OnInspectorGUI()
    {
        Undo.SetSnapshotTarget(Target, Target.name);
        Undo.CreateSnapshot();
        Undo.ClearSnapshotTarget();

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
        styleEditMode = (GUIStyleEditMode)EditorGUILayout.EnumPopup(styleEditMode, EditorStyles.toolbarPopup);
        if (styleEditMode != GUIStyleEditMode.Settings)
            stateEditMode = (GUIStateEditMode)EditorGUILayout.EnumPopup(stateEditMode, EditorStyles.toolbarPopup, GUILayout.Width(96f));
        EditorGUILayout.EndHorizontal();

        if (GUI.changed)
            mainScroll = Vector2.zero;

        mainScroll = EditorGUILayout.BeginScrollView(mainScroll, false, false, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUI.skin.box);
        switch (styleEditMode)
        {
            case GUIStyleEditMode.Box:
                Target.box = StyleEditor(Target.box);
                break;
            case GUIStyleEditMode.Button:
                Target.button = StyleEditor(Target.button);
                break;
            case GUIStyleEditMode.Toggle:
                Target.toggle = StyleEditor(Target.toggle);
                break;
            case GUIStyleEditMode.Label:
                Target.label = StyleEditor(Target.label);
                break;
            case GUIStyleEditMode.ScrollView:
                Target.scrollView = StyleEditor(Target.scrollView);
                break;
            case GUIStyleEditMode.TextField:
                Target.textField = StyleEditor(Target.textField);
                break;
            case GUIStyleEditMode.TextArea:
                Target.textArea = StyleEditor(Target.textArea);
                break;
            case GUIStyleEditMode.Window:
                Target.window = StyleEditor(Target.window);
                break;
            case GUIStyleEditMode.HorizontalSlider:
                GUILayout.Label("Horizontal Slider", EditorStyles.boldLabel);
                Target.horizontalSlider = StyleEditor(Target.horizontalSlider);
                GUILayout.Label("Horizontal Slider Thumb", EditorStyles.boldLabel);
                Target.horizontalSliderThumb = StyleEditor(Target.horizontalSliderThumb);
                break;
            case GUIStyleEditMode.VerticalSlider:
                GUILayout.Label("Vertical Slider", EditorStyles.boldLabel);
                Target.verticalSlider = StyleEditor(Target.verticalSlider);
                GUILayout.Label("Vertical Slider Thumb", EditorStyles.boldLabel);
                Target.verticalSliderThumb = StyleEditor(Target.verticalSliderThumb);
                break;
            case GUIStyleEditMode.HorizontalScrollBar:
                GUILayout.Label("Horizontal Scrollbar", EditorStyles.boldLabel);
                Target.horizontalScrollbar = StyleEditor(Target.horizontalScrollbar);
                GUILayout.Label("Horizontal Scrollbar Left Button", EditorStyles.boldLabel);
                Target.horizontalScrollbarLeftButton = StyleEditor(Target.horizontalScrollbarLeftButton);
                GUILayout.Label("Horizontal Scrollbar Right Button", EditorStyles.boldLabel);
                Target.horizontalScrollbarRightButton = StyleEditor(Target.horizontalScrollbarRightButton);
                GUILayout.Label("Horizontal Scrollbar Thumb", EditorStyles.boldLabel);
                Target.horizontalScrollbarThumb = StyleEditor(Target.horizontalScrollbarThumb);
                break;
            case GUIStyleEditMode.VerticalScrollBar:
                GUILayout.Label("Vertical Scrollbar", EditorStyles.boldLabel);
                Target.verticalScrollbar = StyleEditor(Target.verticalScrollbar);
                GUILayout.Label("Vertical Scrollbar Up Button", EditorStyles.boldLabel);
                Target.verticalScrollbarUpButton = StyleEditor(Target.verticalScrollbarUpButton);
                GUILayout.Label("Vertical Scrollbar Down Button", EditorStyles.boldLabel);
                Target.verticalScrollbarDownButton = StyleEditor(Target.verticalScrollbarDownButton);
                GUILayout.Label("Vertical Scrollbar Thumb", EditorStyles.boldLabel);
                Target.verticalScrollbarThumb = StyleEditor(Target.verticalScrollbarThumb);
                break;
            case GUIStyleEditMode.Custom:
                CustomStyleEditor();
                break;
            case GUIStyleEditMode.Settings:
                SkinSettingsGUI();
                break;
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndScrollView();

        if (EditorGUI.EndChangeCheck())
        {
            Undo.SetSnapshotTarget(Target, Target.name);
            Undo.RegisterSnapshot();
        }
    }
    void OnEnable()
    {
        string styleMode = EditorPrefs.GetString(KEY_STYLE, "Settings");
        string stateMode = EditorPrefs.GetString(KEY_STATE, "Settings");

        styleEditMode = (GUIStyleEditMode)System.Enum.Parse(typeof(GUIStyleEditMode), styleMode);
        stateEditMode = (GUIStateEditMode)System.Enum.Parse(typeof(GUIStateEditMode), stateMode);
        previewControlIndex = EditorPrefs.GetInt(KEY_PREV_ID, 0);

        foldBorder = foldMargin = foldOverflow = foldPadding = foldFont = false;

        ResetCustomStyles();

        GUISkin editor = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
        findStyleName = "ToolbarSeachTextField";
        searchTextField = ArrayUtility.Find<GUIStyle>(editor.customStyles, MatchCustomStyle);
        findStyleName = "ToolbarSeachCancelButton";
        searchClearButton = ArrayUtility.Find<GUIStyle>(editor.customStyles, MatchCustomStyle);
        findStyleName = "ToolbarPopup";
        previewToolbarPopup = ArrayUtility.Find<GUIStyle>(editor.customStyles, MatchCustomStyle);
    }
    public override void OnInspectorGUI()
    {
        Undo.SetSnapshotTarget(Target, Target.name);
        Undo.CreateSnapshot();
        Undo.ClearSnapshotTarget();

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
        styleEditMode = (GUIStyleEditMode)EditorGUILayout.EnumPopup(styleEditMode, EditorStyles.toolbarPopup);
        if (styleEditMode != GUIStyleEditMode.Settings)
        {
            stateEditMode = (GUIStateEditMode)EditorGUILayout.EnumPopup(stateEditMode, EditorStyles.toolbarPopup, GUILayout.Width(96f));
        }
        EditorGUILayout.EndHorizontal();

        if (GUI.changed)
        {
            mainScroll = Vector2.zero;
        }

        mainScroll = EditorGUILayout.BeginScrollView(mainScroll, false, false, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUI.skin.box);
        switch (styleEditMode)
        {
        case GUIStyleEditMode.Box:
            Target.box = StyleEditor(Target.box);
            break;

        case GUIStyleEditMode.Button:
            Target.button = StyleEditor(Target.button);
            break;

        case GUIStyleEditMode.Toggle:
            Target.toggle = StyleEditor(Target.toggle);
            break;

        case GUIStyleEditMode.Label:
            Target.label = StyleEditor(Target.label);
            break;

        case GUIStyleEditMode.ScrollView:
            Target.scrollView = StyleEditor(Target.scrollView);
            break;

        case GUIStyleEditMode.TextField:
            Target.textField = StyleEditor(Target.textField);
            break;

        case GUIStyleEditMode.TextArea:
            Target.textArea = StyleEditor(Target.textArea);
            break;

        case GUIStyleEditMode.Window:
            Target.window = StyleEditor(Target.window);
            break;

        case GUIStyleEditMode.HorizontalSlider:
            GUILayout.Label("Horizontal Slider", EditorStyles.boldLabel);
            Target.horizontalSlider = StyleEditor(Target.horizontalSlider);
            GUILayout.Label("Horizontal Slider Thumb", EditorStyles.boldLabel);
            Target.horizontalSliderThumb = StyleEditor(Target.horizontalSliderThumb);
            break;

        case GUIStyleEditMode.VerticalSlider:
            GUILayout.Label("Vertical Slider", EditorStyles.boldLabel);
            Target.verticalSlider = StyleEditor(Target.verticalSlider);
            GUILayout.Label("Vertical Slider Thumb", EditorStyles.boldLabel);
            Target.verticalSliderThumb = StyleEditor(Target.verticalSliderThumb);
            break;

        case GUIStyleEditMode.HorizontalScrollBar:
            GUILayout.Label("Horizontal Scrollbar", EditorStyles.boldLabel);
            Target.horizontalScrollbar = StyleEditor(Target.horizontalScrollbar);
            GUILayout.Label("Horizontal Scrollbar Left Button", EditorStyles.boldLabel);
            Target.horizontalScrollbarLeftButton = StyleEditor(Target.horizontalScrollbarLeftButton);
            GUILayout.Label("Horizontal Scrollbar Right Button", EditorStyles.boldLabel);
            Target.horizontalScrollbarRightButton = StyleEditor(Target.horizontalScrollbarRightButton);
            GUILayout.Label("Horizontal Scrollbar Thumb", EditorStyles.boldLabel);
            Target.horizontalScrollbarThumb = StyleEditor(Target.horizontalScrollbarThumb);
            break;

        case GUIStyleEditMode.VerticalScrollBar:
            GUILayout.Label("Vertical Scrollbar", EditorStyles.boldLabel);
            Target.verticalScrollbar = StyleEditor(Target.verticalScrollbar);
            GUILayout.Label("Vertical Scrollbar Up Button", EditorStyles.boldLabel);
            Target.verticalScrollbarUpButton = StyleEditor(Target.verticalScrollbarUpButton);
            GUILayout.Label("Vertical Scrollbar Down Button", EditorStyles.boldLabel);
            Target.verticalScrollbarDownButton = StyleEditor(Target.verticalScrollbarDownButton);
            GUILayout.Label("Vertical Scrollbar Thumb", EditorStyles.boldLabel);
            Target.verticalScrollbarThumb = StyleEditor(Target.verticalScrollbarThumb);
            break;

        case GUIStyleEditMode.Custom:
            CustomStyleEditor();
            break;

        case GUIStyleEditMode.Settings:
            SkinSettingsGUI();
            break;
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndScrollView();

        if (EditorGUI.EndChangeCheck())
        {
            Undo.SetSnapshotTarget(Target, Target.name);
            Undo.RegisterSnapshot();
        }
    }