示例#1
0
        void OnGUI()
        {
            if (_styles == null)
            {
                _styles = EnumerateStyles();
            }

            if (Style == null)
            {
                Style = GetStyle(null, GUIStyle.none);
            }

            if (Content == null)
            {
                ResetContent();
            }

            _splitter.OnGui();

            using (new GUILayout.AreaScope(_splitter.LeftSide))
            {
                using (var scroll = new EditorGUILayout.ScrollViewScope(_leftScrollPosition))
                {
                    using (var changes = new EditorGUI.ChangeCheckScope())
                    {
                        _selectedStyle = EditorGUILayout.Popup("Select Style", _selectedStyle, _styles.Names);

                        if (changes.changed)
                        {
                            Style = GetStyle(_styles.Skins[_selectedStyle], _styles.Styles[_selectedStyle]);
                        }
                    }

                    EditorGUILayout.LabelField("Positioning", EditorStyles.boldLabel);
                    Style.margin = RectOffsetField("Margin", Style.margin);

                    EditorGUILayout.LabelField("Sizing", EditorStyles.boldLabel);
                    Style.fixedWidth    = EditorGUILayout.FloatField("Fixed Width", Style.fixedWidth);
                    Style.fixedHeight   = EditorGUILayout.FloatField("Fixed Height", Style.fixedHeight);
                    Style.stretchWidth  = EditorGUILayout.Toggle("Stretch Width", Style.stretchWidth);
                    Style.stretchHeight = EditorGUILayout.Toggle("Stretch Height", Style.stretchHeight);

                    EditorGUILayout.LabelField("Background", EditorStyles.boldLabel);
                    Style.border               = RectOffsetField("Border", Style.border);
                    Style.overflow             = RectOffsetField("Overflow", Style.overflow);
                    Style.normal.background    = _normal.OnGui();
                    Style.onNormal.background  = _onNormal.OnGui();
                    Style.hover.background     = _hover.OnGui();
                    Style.onHover.background   = _onHover.OnGui();
                    Style.focused.background   = _focused.OnGui();
                    Style.onFocused.background = _onFocused.OnGui();
                    Style.active.background    = _active.OnGui();
                    Style.onActive.background  = _onActive.OnGui();

                    EditorGUILayout.LabelField("Content", EditorStyles.boldLabel);
                    Style.padding       = RectOffsetField("Padding", Style.padding);
                    Style.contentOffset = EditorGUILayout.Vector2Field("Content Offset", Style.contentOffset);
                    Style.clipping      = (TextClipping)EditorGUILayout.EnumPopup("Clipping", Style.clipping);

                    EditorGUILayout.LabelField("Text", EditorStyles.boldLabel);
                    Style.font                = (Font)EditorGUILayout.ObjectField("Font", Style.font, typeof(Font), false);
                    Style.fontSize            = EditorGUILayout.IntSlider("Size", Style.fontSize, 1, 200);
                    Style.fontStyle           = (FontStyle)EditorGUILayout.EnumPopup("Style", Style.fontStyle);
                    Style.alignment           = (TextAnchor)EditorGUILayout.EnumPopup("Alignment", Style.alignment);
                    Style.wordWrap            = EditorGUILayout.Toggle("Word Wrap", Style.wordWrap);
                    Style.richText            = EditorGUILayout.Toggle("Use Rich Text", Style.richText);
                    Style.normal.textColor    = EditorGUILayout.ColorField("Normal Color", Style.normal.textColor);
                    Style.onNormal.textColor  = EditorGUILayout.ColorField("On Normal Color", Style.onNormal.textColor);
                    Style.hover.textColor     = EditorGUILayout.ColorField("Hovered Color", Style.hover.textColor);
                    Style.onHover.textColor   = EditorGUILayout.ColorField("On Hovered Color", Style.onHover.textColor);
                    Style.focused.textColor   = EditorGUILayout.ColorField("Focused Color", Style.focused.textColor);
                    Style.onFocused.textColor = EditorGUILayout.ColorField("On Focused Color", Style.onFocused.textColor);
                    Style.active.textColor    = EditorGUILayout.ColorField("Active Color", Style.active.textColor);
                    Style.onActive.textColor  = EditorGUILayout.ColorField("On Active Color", Style.onActive.textColor);

                    EditorGUILayout.LabelField("Image", EditorStyles.boldLabel);
                    Style.imagePosition = (ImagePosition)EditorGUILayout.EnumPopup("Position", Style.imagePosition);

                    _leftScrollPosition = scroll.scrollPosition;
                }
            }

            using (new GUILayout.AreaScope(_splitter.RightSide))
            {
                using (var scroll = new EditorGUILayout.ScrollViewScope(_rightScrollPosition))
                {
                    EditorGUILayout.LabelField("Content", EditorStyles.boldLabel);

                    Content.image   = (Texture)EditorGUILayout.ObjectField("Image Content", Content.image, typeof(Texture), false);
                    Content.text    = GUILayout.TextArea(Content.text);
                    Color           = EditorGUILayout.ColorField("Color", Color);
                    BackgroundColor = EditorGUILayout.ColorField("Background Color", BackgroundColor);
                    ContentColor    = EditorGUILayout.ColorField("Content Color", ContentColor);

                    EditorGUILayout.LabelField("Layout Options", EditorStyles.boldLabel);

                    if (FloatLayoutOptionField("Width", Width, ref _useWidth, ref _width))
                    {
                        Width = _useWidth ? GUILayout.Width(_width) : null;
                    }
                    if (FloatLayoutOptionField("Height", Height, ref _useHeight, ref _height))
                    {
                        Height = _useHeight ? GUILayout.Height(_height) : null;
                    }
                    if (FloatLayoutOptionField("Minimum Width", MinWidth, ref _useMinWidth, ref _minWidth))
                    {
                        MinWidth = _useMinWidth ? GUILayout.MinWidth(_minWidth) : null;
                    }
                    if (FloatLayoutOptionField("Minimum Height", MinHeight, ref _useMinHeight, ref _minHeight))
                    {
                        MinHeight = _useMinHeight ? GUILayout.MinHeight(_minHeight) : null;
                    }
                    if (FloatLayoutOptionField("Maximum Width", MaxWidth, ref _useMaxWidth, ref _maxWidth))
                    {
                        MaxWidth = _useMaxWidth ? GUILayout.MaxWidth(_maxWidth) : null;
                    }
                    if (FloatLayoutOptionField("Maximum Height", MaxHeight, ref _useMaxHeight, ref _maxHeight))
                    {
                        MaxHeight = _useMaxHeight ? GUILayout.MaxHeight(_maxHeight) : null;
                    }
                    if (BoolLayoutOptionField("Expand Width", ExpandWidth, ref _useExpandWidth, ref _expandWidth))
                    {
                        ExpandWidth = _useExpandWidth ? GUILayout.ExpandWidth(_expandWidth) : null;
                    }
                    if (BoolLayoutOptionField("Expand Height", ExpandHeight, ref _useExpandHeight, ref _expandHeight))
                    {
                        ExpandHeight = _useExpandHeight ? GUILayout.ExpandHeight(_expandHeight) : null;
                    }

                    EditorGUILayout.LabelField("Preview", EditorStyles.boldLabel);
                    _previewControl = EditorGUILayout.Popup("Control Type", _previewControl, _controlTypes);
                    _useLayout      = EditorGUILayout.Toggle("Use Layout", _useLayout);

                    if (!_useLayout)
                    {
                        _area = EditorGUILayout.Vector2Field("Size", _area);
                    }

                    EditorHelper.Separator(Color.black);

                    var color           = GUI.color;
                    var backgroundColor = GUI.backgroundColor;
                    var contentColor    = GUI.contentColor;

                    GUI.color           = Color;
                    GUI.backgroundColor = BackgroundColor;
                    GUI.contentColor    = ContentColor;

                    var rect = new Rect();

                    if (!_useLayout)
                    {
                        rect        = GUILayoutUtility.GetRect(0, 0);
                        rect.width  = _area.x;
                        rect.height = _area.y;
                        GUI.DrawTexture(rect, Texture2D.whiteTexture);
                    }

                    switch (_previewControl)
                    {
                    case 0: DrawBox(rect); break;

                    case 1: DrawButton(rect); break;

                    case 2: DrawHorizontalScrollbar(rect); break;

                    case 3: DrawHorizontalSlider(rect); break;

                    case 4: DrawLabel(rect); break;

                    case 5: DrawPasswordField(rect); break;

                    case 6: DrawRepeatButton(rect); break;

                    case 7: DrawSelectionGrid(rect); break;

                    case 8: DrawTextArea(rect); break;

                    case 9: DrawTextField(rect); break;

                    case 10: DrawToggle(rect); break;

                    case 11: DrawToolbar(rect); break;

                    case 12: DrawVerticalScrollbar(rect); break;

                    case 13: DrawVerticalSlider(rect); break;

                    case 14: DrawWindow(rect); break;

                    case 15: DrawEditorBoundsField(rect); break;

                    case 16: DrawEditorBoundsIntField(rect); break;

                    case 17: DrawEditorColorField(rect); break;

                    case 18: DrawEditorCurveField(rect); break;

                    case 19: DrawEditorDoubleField(rect); break;

                    case 20: DrawEditorDropDownButton(rect); break;

                    case 21: DrawEditorDropShadowLabel(rect); break;

                    case 22: DrawEditorEnumFlagsField(rect); break;

                    case 23: DrawEditorEnumPopup(rect); break;

                    case 24: DrawEditorFloatField(rect); break;

                    case 25: DrawEditorFoldout(rect); break;

                    case 26: DrawEditorHelpBox(rect); break;

                    case 27: DrawEditorInspectorTitlebar(rect); break;

                    case 28: DrawEditorIntField(rect); break;

                    case 29: DrawEditorIntPopup(rect); break;

                    case 30: DrawEditorIntSlider(rect); break;

                    case 31: DrawEditorLabelField(rect); break;

                    case 32: DrawEditorLayerField(rect); break;

                    case 33: DrawEditorLongField(rect); break;

                    case 34: DrawEditorMaskField(rect); break;

                    case 35: DrawEditorMinMaxSlider(rect); break;

                    case 36: DrawEditorObjectField(rect); break;

                    case 37: DrawEditorPasswordField(rect); break;

                    case 38: DrawEditorPopup(rect); break;

                    case 39: DrawEditorPrefixLabel(rect); break;

                    case 40: DrawEditorProgressBar(rect); break;

                    case 41: DrawEditorRectField(rect); break;

                    case 42: DrawEditorRectIntField(rect); break;

                    case 43: DrawEditorSelectableLabel(rect); break;

                    case 44: DrawEditorSlider(rect); break;

                    case 45: DrawEditorTagField(rect); break;

                    case 46: DrawEditorTextArea(rect); break;

                    case 47: DrawEditorTextField(rect); break;

                    case 48: DrawEditorToggle(rect); break;

                    case 49: DrawEditorToggleLeft(rect); break;

                    case 50: DrawEditorVector2Field(rect); break;

                    case 51: DrawEditorVector2IntField(rect); break;

                    case 52: DrawEditorVector3Field(rect); break;

                    case 53: DrawEditorVector3IntField(rect); break;

                    case 54: DrawEditorVector4Field(rect); break;
                    }

                    GUI.color           = color;
                    GUI.backgroundColor = backgroundColor;
                    GUI.contentColor    = contentColor;

                    _rightScrollPosition = scroll.scrollPosition;
                }
            }
        }