예제 #1
0
        private void DrawCompactBoxButton()
        {
            SirenixEditorGUI.BeginBox();
            var rect = SirenixEditorGUI.BeginToolbarBoxHeader().AlignRight(70).Padding(1);

            rect.height -= 1;

            GUIHelper.PushColor(this.btnColor);

            if (GUI.Button(rect, "Invoke"))
            {
                this.InvokeButton();
            }

            GUIHelper.PopColor();

            if (this.expanded)
            {
                EditorGUILayout.LabelField(this.label);
            }
            else
            {
                this.toggle.Value = SirenixEditorGUI.Foldout(this.toggle.Value, this.label);
            }

            SirenixEditorGUI.EndToolbarBoxHeader();
            this.DrawParameters(false);
            SirenixEditorGUI.EndToolbarBox();
        }
    private void DrawPageSlider(GUIContent label)
    {
        try
        {
            if (this.slider == null)
            {
                this.slider = new SlidePageNavigationHelper<InspectorProperty>();
                this.slider.PushPage(this.Property, Guid.NewGuid().ToString());
                this.page = this.slider.EnumeratePages.Last();
                this.page.Name = this.GetLabelText(label);
            }

            currentSlider = this.slider;

            SirenixEditorGUI.BeginBox();
            SirenixEditorGUI.BeginToolbarBoxHeader();
            {
                var rect = GUILayoutUtility.GetRect(0, 20);
                rect.x -= 5;
                this.slider.DrawPageNavigation(rect);
            }
            SirenixEditorGUI.EndToolbarBoxHeader();
            {
                this.slider.BeginGroup();
                foreach (var p in this.slider.EnumeratePages)
                {
                    if (p.BeginPage())
                    {
                        if (p.Value == this.Property)
                        {
                            this.CallNextDrawer(null);
                        }
                        else
                        {
                            currentDrawingPageProperty = p.Value;
                            if (p.Value.Tree != this.Property.Tree)
                            {
                                InspectorUtilities.BeginDrawPropertyTree(p.Value.Tree, true);
                            }
                            p.Value.Draw(null);

                            if (p.Value.Tree != this.Property.Tree)
                            {
                                InspectorUtilities.EndDrawPropertyTree(p.Value.Tree);
                            }
                            currentDrawingPageProperty = null;
                        }
                    }
                    p.EndPage();
                }
                this.slider.EndGroup();
            }
            SirenixEditorGUI.EndBox();

        }
        finally
        {
            currentSlider = null;
        }
    }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry = this.ValueEntry;

            if (Event.current.type == EventType.Layout)
            {
                this.drawAsReference = entry.ValueState == PropertyValueState.Reference;
            }

            if (this.drawAsReference)
            {
                var targetProp = entry.Property.Tree.GetPropertyAtPath(entry.TargetReferencePath);

                if (targetProp == null)
                {
                    GUILayout.Label("Reference to " + entry.TargetReferencePath + ". But no property was found at path, which is a problem.");
                    return;
                }

                var isInReference = targetProp.Context.GetGlobal("is_in_reference", false);

                bool drawReferenceBox = true;

                if (!isInReference.Value)
                {
                    drawReferenceBox = !this.hideReferenceBox;
                }

                if (drawReferenceBox)
                {
                    SirenixEditorGUI.BeginToolbarBox();
                    SirenixEditorGUI.BeginToolbarBoxHeader();
                    Rect valueRect;
                    this.isToggled.Value = SirenixEditorGUI.Foldout(this.isToggled.Value, label, out valueRect);
                    GUI.Label(valueRect, "Reference to " + targetProp.Path, SirenixGUIStyles.LeftAlignedGreyMiniLabel);
                    SirenixEditorGUI.EndToolbarBoxHeader();
                    if (SirenixEditorGUI.BeginFadeGroup(entry.Context.Get(this, "k", 0), this.isToggled.Value))
                    {
                        bool previous = isInReference.Value;
                        isInReference.Value = true;
                        targetProp.Draw(label);
                        isInReference.Value = previous;
                    }
                    SirenixEditorGUI.EndFadeGroup();
                    SirenixEditorGUI.EndToolbarBox();
                }
                else
                {
                    bool previous = isInReference.Value;
                    isInReference.Value = true;
                    targetProp.Draw(label);
                    isInReference.Value = previous;
                }
            }
            else
            {
                this.CallNextDrawer(label);
            }
        }
예제 #4
0
    protected override void DrawPropertyLayout(GUIContent label)
    {
        SirenixEditorGUI.BeginBox();
        {
            SirenixEditorGUI.BeginToolbarBoxHeader();
            {
                var rect = GUILayoutUtility.GetRect(0, 19);
                var unityObjectFieldRect = rect.Padding(2).AlignLeft(rect.width / 2);
                var methodSelectorRect   = rect.Padding(2).AlignRight(rect.width / 2 - 5);
                var dInfo    = this.GetDelegateInfo();
                var intlabel = new GUIContent("some type");

                EditorGUI.BeginChangeCheck();
                var someType = SirenixEditorFields.Dropdown(intlabel, tempType, SupportedReturnTypes);
                /*public static bool Dropdown<T>(Rect rect, IList<int> selected, IList<T> items, bool multiSelection)*/
                var newTarget = SirenixEditorFields.UnityObjectField(unityObjectFieldRect, dInfo.Target, typeof(UnityEngine.Object), true);
                if (EditorGUI.EndChangeCheck())
                {
                    this.tmpTarget = newTarget;
                    this.tempType  = someType;
                }

                EditorGUI.BeginChangeCheck();
                var selectorText = (dInfo.Method == null || this.tmpTarget) ? "Select a method" : dInfo.Method.Name;
                var newMethod    = MethodSelector.DrawSelectorDropdown(methodSelectorRect, selectorText, this.CreateSelector);
                if (EditorGUI.EndChangeCheck())
                {
                    this.CreateAndAssignNewDelegate(newMethod.FirstOrDefault());
                    this.tmpTarget = null;
                }
            }
            SirenixEditorGUI.EndToolbarBoxHeader();

            // Draws the rest of the ICustomEvent, and since we've drawn the label, we simply pass along null.
            for (int i = 0; i < this.Property.Children.Count; i++)
            {
                var child = this.Property.Children[i];
                if (child.Name == "Result")
                {
                    continue;
                }
                child.Draw();
            }
        }
        SirenixEditorGUI.EndBox();
    }
예제 #5
0
        private void DrawBoxButton()
        {
            SirenixEditorGUI.BeginBox();
            SirenixEditorGUI.BeginToolbarBoxHeader();

            if (this.expanded)
            {
                EditorGUILayout.LabelField(this.label);
            }
            else
            {
                this.toggle.Value = SirenixEditorGUI.Foldout(this.toggle.Value, this.label);
            }

            SirenixEditorGUI.EndToolbarBoxHeader();
            this.DrawParameters(true);
            SirenixEditorGUI.EndToolbarBox();
        }
예제 #6
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry     = this.ValueEntry;
            var isEditing = entry.Property.Context.Get(this, "isEditing", false);

            entry.SmartValue.Name = entry.SmartValue.Name ?? "Palette Name";

            SirenixEditorGUI.BeginBox();
            {
                SirenixEditorGUI.BeginToolbarBoxHeader();
                {
                    GUILayout.Label(entry.SmartValue.Name);
                    GUILayout.FlexibleSpace();
                    if (SirenixEditorGUI.IconButton(EditorIcons.Pen))
                    {
                        isEditing.Value = !isEditing.Value;
                    }
                }
                SirenixEditorGUI.EndToolbarBoxHeader();

                if (entry.SmartValue.Colors == null)
                {
                    entry.SmartValue.Colors = new List <Color>();
                }

                if (SirenixEditorGUI.BeginFadeGroup(entry.SmartValue, entry, isEditing.Value))
                {
                    this.CallNextDrawer(null);
                }
                SirenixEditorGUI.EndFadeGroup();

                if (SirenixEditorGUI.BeginFadeGroup(entry.SmartValue, entry.SmartValue, isEditing.Value == false))
                {
                    Color col = default(Color);

                    var stretch = ColorPaletteManager.Instance.StretchPalette;
                    var size    = ColorPaletteManager.Instance.SwatchSize;
                    var margin  = ColorPaletteManager.Instance.SwatchSpacing;
                    ColorPaletteAttributeDrawer.DrawColorPaletteColorPicker(entry, entry.SmartValue, ref col, entry.SmartValue.ShowAlpha, stretch, size, 20, margin);
                }
                SirenixEditorGUI.EndFadeGroup();
            }
            SirenixEditorGUI.EndToolbarBox();
        }
예제 #7
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var entry     = this.ValueEntry;
            var attribute = this.Attribute;

            SirenixEditorGUI.BeginIndentedHorizontal();
            {
                var hideLabel = label == null;
                if (hideLabel == false)
                {
                    GUILayout.Label(label, GUILayoutOptions.Width(GUIHelper.BetterLabelWidth - 4).ExpandWidth(false));
                }
                else
                {
                    GUILayout.Space(5);
                }

                //var colorPaletDropDown = entry.Context.Get(this, "colorPalette", 0);
                //var currentName = entry.Context.Get(this, "currentName", attribute.PaletteName);
                //var showAlpha = entry.Context.Get(this, "showAlpha", attribute.ShowAlpha);
                //var names = ColorPaletteManager.Instance.GetColorPaletteNames();

                ColorPalette colorPalette;
                var          rect = EditorGUILayout.BeginHorizontal();
                {
                    rect.x    -= 3;
                    rect.width = 25;

                    entry.SmartValue = SirenixEditorGUI.DrawColorField(rect, entry.SmartValue, false, this.ShowAlpha);
                    bool openInEditorShown = false;
                    GUILayout.Space(28);
                    SirenixEditorGUI.BeginInlineBox();
                    {
                        if (attribute.PaletteName == null || ColorPaletteManager.Instance.ShowPaletteName)
                        {
                            SirenixEditorGUI.BeginToolbarBoxHeader();
                            {
                                if (attribute.PaletteName == null)
                                {
                                    var newValue = EditorGUILayout.Popup(this.PaletteIndex, this.Names, GUILayoutOptions.ExpandWidth(true));
                                    if (this.PaletteIndex != newValue)
                                    {
                                        this.PaletteIndex         = newValue;
                                        this.CurrentName          = this.Names[newValue];
                                        this.PersistentName.Value = this.CurrentName;
                                        GUIHelper.RemoveFocusControl();
                                    }
                                }
                                else
                                {
                                    GUILayout.Label(this.CurrentName);
                                    GUILayout.FlexibleSpace();
                                }
                                openInEditorShown = true;
                                if (SirenixEditorGUI.IconButton(EditorIcons.SettingsCog))
                                {
                                    ColorPaletteManager.Instance.OpenInEditor();
                                }
                            }
                            SirenixEditorGUI.EndToolbarBoxHeader();
                        }

                        if (attribute.PaletteName == null)
                        {
                            colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == this.Names[this.PaletteIndex]);
                        }
                        else
                        {
                            colorPalette = ColorPaletteManager.Instance.ColorPalettes.FirstOrDefault(x => x.Name == this.NameGetter.GetString(entry));
                        }

                        if (colorPalette == null)
                        {
                            GUILayout.BeginHorizontal();
                            {
                                if (attribute.PaletteName != null)
                                {
                                    if (GUILayout.Button("Create color palette: " + this.NameGetter.GetString(entry)))
                                    {
                                        ColorPaletteManager.Instance.ColorPalettes.Add(new ColorPalette()
                                        {
                                            Name = this.NameGetter.GetString(entry)
                                        });
                                        ColorPaletteManager.Instance.OpenInEditor();
                                    }
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        else
                        {
                            this.CurrentName = colorPalette.Name;
                            this.ShowAlpha   = attribute.ShowAlpha && colorPalette.ShowAlpha;
                            if (openInEditorShown == false)
                            {
                                GUILayout.BeginHorizontal();
                            }
                            var color   = entry.SmartValue;
                            var stretch = ColorPaletteManager.Instance.StretchPalette;
                            var size    = ColorPaletteManager.Instance.SwatchSize;
                            var margin  = ColorPaletteManager.Instance.SwatchSpacing;
                            if (DrawColorPaletteColorPicker(entry, colorPalette, ref color, colorPalette.ShowAlpha, stretch, size, 20, margin))
                            {
                                entry.SmartValue = color;
                                //entry.ApplyChanges();
                            }
                            if (openInEditorShown == false)
                            {
                                GUILayout.Space(4);
                                if (SirenixEditorGUI.IconButton(EditorIcons.SettingsCog))
                                {
                                    ColorPaletteManager.Instance.OpenInEditor();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    SirenixEditorGUI.EndInlineBox();
                }
                EditorGUILayout.EndHorizontal();
            }

            SirenixEditorGUI.EndIndentedHorizontal();
        }
        // Token: 0x06000A26 RID: 2598 RVA: 0x00031018 File Offset: 0x0002F218
        public void Draw(bool drawCodeExample)
        {
            if (TrickOverViewPreview.exampleGroupStyle == null)
            {
                TrickOverViewPreview.exampleGroupStyle = new GUIStyle(GUIStyle.none)
                {
                    padding = new RectOffset(1, 1, 10, 0)
                };
            }
            if (TrickOverViewPreview.previewStyle == null)
            {
                TrickOverViewPreview.previewStyle = new GUIStyle(GUIStyle.none)
                {
                    padding = new RectOffset(0, 0, 0, 0)
                };
            }
            GUILayout.BeginVertical(TrickOverViewPreview.exampleGroupStyle, new GUILayoutOption[0]);
            GUILayout.Label("Preview:", SirenixGUIStyles.BoldTitle, new GUILayoutOption[0]);
            GUILayout.BeginVertical(TrickOverViewPreview.previewStyle, GUILayoutOptions.ExpandWidth(true));
            Rect rect = GUIHelper.GetCurrentLayoutRect().Expand(4f, 0f);

            SirenixEditorGUI.DrawSolidRect(rect, EditorGUIUtility.isProSkin ? TrickOverViewPreview.previewBackgroundColorDark : TrickOverViewPreview.previewBackgroundColorLight, true);
            SirenixEditorGUI.DrawBorders(rect, 1, true);
            GUILayout.Space(8f);

            m_DrawCallbaclAction.Invoke(rect);
            this.tree = (this.tree ?? PropertyTree.Create(this.ExampleInfo.PreviewObject));
            this.tree.Draw(false);

            GUILayout.Space(8f);
            GUILayout.EndVertical();
            if (drawCodeExample && this.ExampleInfo.Code != null)
            {
                GUILayout.Space(12f);
                GUILayout.Label("Code", SirenixGUIStyles.BoldTitle, new GUILayoutOption[0]);
                Rect rect2 = SirenixEditorGUI.BeginToolbarBox(new GUILayoutOption[0]);
                SirenixEditorGUI.DrawSolidRect(rect2.HorizontalPadding(1f), SyntaxHighlighter.BackgroundColor, true);
                SirenixEditorGUI.BeginToolbarBoxHeader(22f);
                if (SirenixEditorGUI.ToolbarButton(this.showRaw ? "Highlighted" : "Raw", false))
                {
                    this.showRaw = !this.showRaw;
                }
                GUILayout.FlexibleSpace();
                if (SirenixEditorGUI.ToolbarButton("Copy", false))
                {
                    Clipboard.Copy <string>(this.ExampleInfo.Code);
                }
                SirenixEditorGUI.EndToolbarBoxHeader();
                if (TrickOverViewPreview.codeTextStyle == null)
                {
                    TrickOverViewPreview.codeTextStyle = new GUIStyle(SirenixGUIStyles.MultiLineLabel);
                    TrickOverViewPreview.codeTextStyle.normal.textColor  = SyntaxHighlighter.TextColor;
                    TrickOverViewPreview.codeTextStyle.active.textColor  = SyntaxHighlighter.TextColor;
                    TrickOverViewPreview.codeTextStyle.focused.textColor = SyntaxHighlighter.TextColor;
                    TrickOverViewPreview.codeTextStyle.wordWrap          = false;
                }
                GUIContent content = GUIHelper.TempContent(this.showRaw ? this.ExampleInfo.Code.TrimEnd(new char[]
                {
                    '\n',
                    '\r'
                }) : this.highlightedCode);
                Vector2 vector = TrickOverViewPreview.codeTextStyle.CalcSize(content);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(-3f);
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                GUIHelper.PushEventType((Event.current.type == EventType.ScrollWheel) ? EventType.Used : Event.current.type);
                this.scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, true, false, GUI.skin.horizontalScrollbar, GUIStyle.none, new GUILayoutOption[]
                {
                    GUILayout.MinHeight(vector.y + 20f)
                });
                Rect rect3 = GUILayoutUtility.GetRect(vector.x + 50f, vector.y).AddXMin(4f).AddY(2f);
                if (this.showRaw)
                {
                    EditorGUI.SelectableLabel(rect3, this.ExampleInfo.Code, TrickOverViewPreview.codeTextStyle);
                    GUILayout.Space(-14f);
                }
                else
                {
                    GUI.Label(rect3, content, TrickOverViewPreview.codeTextStyle);
                }
                GUILayout.EndScrollView();
                GUIHelper.PopEventType();
                GUILayout.EndVertical();
                GUILayout.Space(-3f);
                GUILayout.EndHorizontal();
                GUILayout.Space(-3f);
                SirenixEditorGUI.EndToolbarBox();
            }
            GUILayout.EndVertical();
        }
예제 #9
0
        private void DrawPageSlider(GUIContent label)
        {
            try
            {
                if (slider == null)
                {
                    slider = new SlidePageNavigationHelper <InspectorProperty>();
                    slider.PushPage(Property, Guid.NewGuid().ToString());
                    page      = slider.EnumeratePages.Last();
                    page.Name = GetLabelText(label);
                }

                currentSlider = slider;

                SirenixEditorGUI.BeginBox();
                SirenixEditorGUI.BeginToolbarBoxHeader();
                {
                    Rect rect = GUILayoutUtility.GetRect(0, 20);
                    rect.x -= 5;
                    slider.DrawPageNavigation(rect);
                }
                SirenixEditorGUI.EndToolbarBoxHeader();
                {
                    slider.BeginGroup();
                    foreach (SlidePageNavigationHelper <InspectorProperty> .Page p in slider.EnumeratePages)
                    {
                        if (p.BeginPage())
                        {
                            if (p.Value == Property)
                            {
                                CallNextDrawer(null);
                            }
                            else
                            {
                                currentDrawingPageProperty = p.Value;
                                if (p.Value.Tree != Property.Tree)
                                {
                                    p.Value.Tree.BeginDraw(true);
                                }

                                p.Value.Draw(null);

                                if (p.Value.Tree != Property.Tree)
                                {
                                    p.Value.Tree.EndDraw();
                                }

                                currentDrawingPageProperty = null;
                            }
                        }

                        p.EndPage();
                    }

                    slider.EndGroup();
                }
                SirenixEditorGUI.EndBox();
            }
            finally
            {
                currentSlider = null;
            }
        }
예제 #10
0
        private void DrawElements(IPropertyValueEntry <TDictionary> entry, GUIContent label)
        {
            for (int i = this.paging.StartIndex; i < this.paging.EndIndex; i++)
            {
                var keyValuePairProperty = entry.Property.Children[i];
                var keyValuePairValue    = (keyValuePairProperty.ValueEntry as IPropertyValueEntry <EditableKeyValuePair <TKey, TValue> >).SmartValue;

                Rect rect = SirenixEditorGUI.BeginListItem(false, listItemStyle);
                {
                    if (this.attrSettings.DisplayMode != DictionaryDisplayOptions.OneLine)
                    {
                        bool defaultExpanded;
                        switch (this.attrSettings.DisplayMode)
                        {
                        case DictionaryDisplayOptions.CollapsedFoldout:
                            defaultExpanded = false;
                            break;

                        case DictionaryDisplayOptions.ExpandedFoldout:
                            defaultExpanded = true;
                            break;

                        default:
                            defaultExpanded = SirenixEditorGUI.ExpandFoldoutByDefault;
                            break;
                        }
                        var isExpanded = keyValuePairProperty.Context.GetPersistent(this, "Expanded", defaultExpanded);

                        SirenixEditorGUI.BeginBox();
                        SirenixEditorGUI.BeginToolbarBoxHeader();
                        {
                            if (keyValuePairValue.IsInvalidKey)
                            {
                                GUIHelper.PushColor(Color.red);
                            }
                            var btnRect = GUIHelper.GetCurrentLayoutRect().AlignLeft(HeaderMargin.margin.left);
                            btnRect.y += 1;
                            GUILayout.BeginVertical(HeaderMargin);
                            GUIHelper.PushIsDrawingDictionaryKey(true);

                            GUIHelper.PushLabelWidth(this.keyLabelWidth);

                            var keyProperty = keyValuePairProperty.Children[0];
                            var keyLabel    = GUIHelper.TempContent(" ");
                            DrawKeyProperty(keyProperty, keyLabel);

                            GUIHelper.PopLabelWidth();

                            GUIHelper.PopIsDrawingDictionaryKey();
                            GUILayout.EndVertical();
                            if (keyValuePairValue.IsInvalidKey)
                            {
                                GUIHelper.PopColor();
                            }
                            isExpanded.Value = SirenixEditorGUI.Foldout(btnRect, isExpanded.Value, this.keyLabel);
                        }
                        SirenixEditorGUI.EndToolbarBoxHeader();

                        if (SirenixEditorGUI.BeginFadeGroup(isExpanded, isExpanded.Value))
                        {
                            keyValuePairProperty.Children[1].Draw(null);
                        }
                        SirenixEditorGUI.EndFadeGroup();

                        SirenixEditorGUI.EndToolbarBox();
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.BeginVertical(GUILayoutOptions.Width(this.keyWidthOffset));
                        {
                            var keyProperty = keyValuePairProperty.Children[0];

                            if (keyValuePairValue.IsInvalidKey)
                            {
                                GUIHelper.PushColor(Color.red);
                            }

                            if (this.attrSettings.IsReadOnly)
                            {
                                GUIHelper.PushGUIEnabled(false);
                            }

                            GUIHelper.PushIsDrawingDictionaryKey(true);
                            GUIHelper.PushLabelWidth(10);

                            DrawKeyProperty(keyProperty, null);

                            GUIHelper.PopLabelWidth();
                            GUIHelper.PopIsDrawingDictionaryKey();

                            if (this.attrSettings.IsReadOnly)
                            {
                                GUIHelper.PopGUIEnabled();
                            }

                            if (keyValuePairValue.IsInvalidKey)
                            {
                                GUIHelper.PopColor();
                            }
                        }
                        GUILayout.EndVertical();
                        GUILayout.BeginVertical(OneLineMargin);
                        {
                            GUIHelper.PushHierarchyMode(false);
                            var valueEntry = keyValuePairProperty.Children[1];
                            var tmp        = GUIHelper.ActualLabelWidth;
                            GUIHelper.BetterLabelWidth = 150;
                            valueEntry.Draw(null);
                            GUIHelper.BetterLabelWidth = tmp;
                            GUIHelper.PopHierarchyMode();
                        }
                        GUILayout.EndVertical();
                        GUILayout.EndHorizontal();
                    }

                    if (entry.IsEditable && !this.attrSettings.IsReadOnly && SirenixEditorGUI.IconButton(new Rect(rect.xMax - 24 + 5, rect.y + 4 + ((int)rect.height - 23) / 2, 14, 14), EditorIcons.X))
                    {
                        this.dictionaryResolver.QueueRemoveKey(Enumerable.Range(0, entry.ValueCount).Select(n => this.dictionaryResolver.GetKey(n, i)).ToArray());
                        EditorApplication.delayCall += () => this.newKeyIsValid = null;
                        GUIHelper.RequestRepaint();
                    }
                }
                SirenixEditorGUI.EndListItem();
            }

            if (this.paging.IsOnLastPage && entry.ValueState == PropertyValueState.CollectionLengthConflict)
            {
                SirenixEditorGUI.BeginListItem(false);
                GUILayout.Label(GUIHelper.TempContent("------"), EditorStyles.centeredGreyMiniLabel);
                SirenixEditorGUI.EndListItem();
            }
        }
        public void Draw(bool drawCodeExample)
        {
            if (exampleGroupStyle == null)
            {
                exampleGroupStyle = new GUIStyle(GUIStyle.none)
                {
                    padding = new RectOffset(1, 1, 10, 0)
                };
            }
            if (previewStyle == null)
            {
                previewStyle = new GUIStyle(GUIStyle.none)
                {
                    padding = new RectOffset(0, 0, 0, 0),
                };
            }

            GUILayout.BeginVertical(exampleGroupStyle);

            if (this.ExampleInfo.Description != null)
            {
                SirenixEditorGUI.BeginBox();
                GUILayout.BeginHorizontal();
                GUILayout.Space(23);
                GUILayout.Label(this.ExampleInfo.Description, SirenixGUIStyles.MultiLineLabel);

                var rect = GUILayoutUtility.GetLastRect();
                EditorIcons.X.Draw(rect.SubX(26).SetWidth(26).AlignCenterXY(20), EditorIcons.Info.Active);

                GUILayout.EndHorizontal();
                SirenixEditorGUI.EndBox();

                GUILayout.Space(12);
            }

            GUILayout.Label("Interactive Preview", SirenixGUIStyles.BoldTitle);
            GUILayout.BeginVertical(previewStyle, GUILayoutOptions.ExpandWidth(true));
            {
                Rect rect = GUIHelper.GetCurrentLayoutRect().Expand(4, 0);
                SirenixEditorGUI.DrawSolidRect(rect, EditorGUIUtility.isProSkin ? previewBackgroundColorDark : previewBackgroundColorLight);
                SirenixEditorGUI.DrawBorders(rect, 1);

                GUILayout.Space(8);
                this.tree = this.tree ?? PropertyTree.Create(this.ExampleInfo.PreviewObject);
                this.tree.Draw(false);
                GUILayout.Space(8);
            }
            GUILayout.EndVertical();

            if (drawCodeExample && this.ExampleInfo.Code != null)
            {
                GUILayout.Space(12);
                GUILayout.Label("Code", SirenixGUIStyles.BoldTitle);

                Rect rect = SirenixEditorGUI.BeginToolbarBox();
                SirenixEditorGUI.DrawSolidRect(rect.HorizontalPadding(1), SyntaxHighlighter.BackgroundColor);

                SirenixEditorGUI.BeginToolbarBoxHeader();
                {
                    if (SirenixEditorGUI.ToolbarButton(this.showRaw ? "Highlighted" : "Raw"))
                    {
                        this.showRaw = !this.showRaw;
                    }

                    GUILayout.FlexibleSpace();
                    if (SirenixEditorGUI.ToolbarButton("Copy"))
                    {
                        Clipboard.Copy(this.ExampleInfo.Code);
                    }
                }
                SirenixEditorGUI.EndToolbarBoxHeader();

                if (codeTextStyle == null)
                {
                    codeTextStyle = new GUIStyle(SirenixGUIStyles.MultiLineLabel);
                    codeTextStyle.normal.textColor  = SyntaxHighlighter.TextColor;
                    codeTextStyle.active.textColor  = SyntaxHighlighter.TextColor;
                    codeTextStyle.focused.textColor = SyntaxHighlighter.TextColor;
                    codeTextStyle.wordWrap          = false;
                }

                GUIContent codeContent = GUIHelper.TempContent(this.showRaw ? this.ExampleInfo.Code.TrimEnd('\n', '\r') : this.highlightedCode);
                Vector2    size        = codeTextStyle.CalcSize(codeContent);

                GUILayout.BeginHorizontal();
                GUILayout.Space(-3);
                GUILayout.BeginVertical();
                {
                    GUIHelper.PushEventType(Event.current.type == EventType.ScrollWheel ? EventType.Used : Event.current.type); // Prevent the code horizontal scroll view from eating the scroll event.

                    this.scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, true, false, GUI.skin.horizontalScrollbar, GUIStyle.none, GUILayout.MinHeight(size.y + 20));
                    var codeRect = GUILayoutUtility.GetRect(size.x + 50, size.y).AddXMin(4).AddY(2);

                    if (this.showRaw)
                    {
                        EditorGUI.SelectableLabel(codeRect, this.ExampleInfo.Code, codeTextStyle);
                        GUILayout.Space(-14);
                    }
                    else
                    {
                        GUI.Label(codeRect, codeContent, codeTextStyle);
                    }

                    GUILayout.EndScrollView();

                    GUIHelper.PopEventType();
                }
                GUILayout.EndVertical();
                GUILayout.Space(-3);
                GUILayout.EndHorizontal();
                GUILayout.Space(-3);

                SirenixEditorGUI.EndToolbarBox();
            }
            GUILayout.EndVertical();
        }
예제 #12
0
        public void Draw(bool drawCodeExample)
        {
            if (this.ExampleInfo.Description != null)
            {
                SirenixEditorGUI.BeginBox();
                GUILayout.Label(this.ExampleInfo.Description, SirenixGUIStyles.MultiLineLabel);
                SirenixEditorGUI.EndBox();
            }

            SirenixEditorGUI.BeginBox();
            {
                this.tree = this.tree ?? PropertyTree.Create(this.ExampleInfo.PreviewObject);
                this.tree.Draw(false);
            }
            SirenixEditorGUI.EndBox();

            if (drawCodeExample && this.ExampleInfo.Code != null)
            {
                GUILayout.Space(15);

                Rect rect = SirenixEditorGUI.BeginToolbarBox();
                SirenixEditorGUI.DrawSolidRect(rect.HorizontalPadding(1), SyntaxHighlighter.BackgroundColor);

                SirenixEditorGUI.BeginToolbarBoxHeader();
                {
                    if (SirenixEditorGUI.ToolbarButton(this.showRaw ? "Highlighted" : "Raw"))
                    {
                        this.showRaw = !this.showRaw;
                    }

                    GUILayout.FlexibleSpace();
                    if (SirenixEditorGUI.ToolbarButton("Copy"))
                    {
                        Clipboard.Copy(this.ExampleInfo.Code);
                    }
                }
                SirenixEditorGUI.EndToolbarBoxHeader();

                if (codeStyle == null)
                {
                    codeStyle = new GUIStyle(SirenixGUIStyles.MultiLineLabel);
                    codeStyle.normal.textColor  = SyntaxHighlighter.TextColor;
                    codeStyle.active.textColor  = SyntaxHighlighter.TextColor;
                    codeStyle.focused.textColor = SyntaxHighlighter.TextColor;
                    codeStyle.wordWrap          = false;
                }

                GUIContent codeContent = GUIHelper.TempContent(this.showRaw ? this.ExampleInfo.Code : this.highlightedCode);
                Vector2    size        = codeStyle.CalcSize(codeContent);

                this.scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, true, false, GUI.skin.horizontalScrollbar, GUIStyle.none, GUILayoutOptions.MinHeight(size.y + 20));
                var codeRect = GUILayoutUtility.GetRect(size.x + 50, size.y);

                if (this.showRaw)
                {
                    EditorGUI.SelectableLabel(codeRect, this.ExampleInfo.Code, codeStyle);
                }
                else
                {
                    GUI.Label(codeRect, codeContent, codeStyle);
                }

                GUILayout.EndScrollView();

                SirenixEditorGUI.EndToolbarBox();
            }
        }