protected override void DrawPropertyLayout(GUIContent label)
        {
            Rect labelRect;
            Rect contentRect = SirenixEditorGUI.BeginHorizontalPropertyLayout(label, out labelRect);

            {
                var showLabels = !this.isMatrixChild && SirenixEditorFields.ResponsiveVectorComponentFields && contentRect.width >= 100;

                if (label != null)
                {
                    GUILayout.Space(3); // Ugh, better than nothing
                }

                var options = GUILayoutOptions.Height(EditorGUIUtility.singleLineHeight);

                GUIHelper.PushLabelWidth(SirenixEditorFields.SingleLetterStructLabelWidth);
                EditorGUILayout.BeginVertical(options);
                this.ValueEntry.Property.Children[0].Draw(showLabels ? GUIHelper.TempContent("X") : null);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(options);
                this.ValueEntry.Property.Children[1].Draw(showLabels ? GUIHelper.TempContent("Y") : null);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(options);
                this.ValueEntry.Property.Children[2].Draw(showLabels ? GUIHelper.TempContent("Z") : null);
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(options);
                this.ValueEntry.Property.Children[3].Draw(showLabels ? GUIHelper.TempContent("W") : null);
                EditorGUILayout.EndVertical();
                GUIHelper.PopLabelWidth();
            }
            SirenixEditorGUI.EndHorizontalPropertyLayout();
        }
Exemple #2
0
        protected override void DrawEditors()
        {
            SirenixEditorGUI.DrawSolidRect(new Rect(0, 0, this.position.width, this.position.height), SirenixGUIStyles.DarkEditorBackground);

            // Draw top pager:
            Rect rect = GUIHelper.GetCurrentLayoutRect().AlignTop(34);

            SirenixEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.EditorWindowBackgroundColor);
            SirenixEditorGUI.DrawBorders(rect, 0, 0, 0, 1);
            this.pager.DrawPageNavigation(rect.AlignCenterY(20).HorizontalPadding(10));

            // Draw pages:
            this.pager.BeginGroup();
            int i = 0;

            foreach (SlidePageNavigationHelper <object> .Page page in this.pager.EnumeratePages)
            {
                if (page.BeginPage())
                {
                    GUILayout.BeginVertical(GUILayoutOptions.ExpandHeight(true));
                    GUILayout.Space(30);
                    this.DrawEditor(i);
                    GUILayout.EndVertical();
                }
                page.EndPage();
                i++;
            }
            this.pager.EndGroup();
        }
Exemple #3
0
    protected override void DrawEditor(int index)
    {
        fileName = EditorGUILayout.TextArea(fileName);
        if (string.IsNullOrEmpty(fileName))
        {
            EditorGUILayout.LabelField("You need to give a file name");
            return;
        }

        this.scroll = GUILayout.BeginScrollView(this.scroll);
        {
            base.DrawEditor(index);
        }
        GUILayout.EndScrollView();

        if (this.previewObject)
        {
            GUILayout.FlexibleSpace();
            SirenixEditorGUI.HorizontalLineSeparator(1);

            if (GUILayout.Button("Create Asset", GUILayoutOptions.Height(30)))
            {
                this.CreateAsset();
            }
        }
    }
Exemple #4
0
 private void DrawPage(Page page)
 {
     for (int i = 0; i < page.Sections.Count; i++)
     {
         var section = page.Sections[i];
         int colNum  = (this.position.width < 470f) ? 1 : section.ColCount;
         if (string.IsNullOrEmpty(section.Title) == false)
         {
             GUILayout.Label(new GUIContent(section.Title), sectionTitleLabelStyle);
         }
         if (section.Cards.Count != 0)
         {
             bool flag = false;
             for (int j = 0; j < section.Cards.Count; j++)
             {
                 if (j % colNum == 0)
                 {
                     if (j != 0 && colNum != 0)
                     {
                         EditorGUILayout.EndHorizontal();
                         GUILayout.Space(10f);
                     }
                     Rect rect = EditorGUILayout.BeginHorizontal(new GUIStyle
                     {
                         padding = new RectOffset(5, 4, 0, 0)
                     });
                     this.currSectionRect = rect;
                     flag = true;
                 }
                 if (colNum == 0)
                 {
                     GUILayout.FlexibleSpace();
                 }
                 Rect cardBoxRect = EditorGUILayout.BeginVertical(cardStylePadding,
                                                                  GUILayoutOptions.Width(this.width / (float)colNum - 12f));
                 if (Event.current.type == EventType.Repaint)
                 {
                     GUIHelper.PushColor(new Color(1f, 1f, 1f, EditorGUIUtility.isProSkin ? 0.25f : 0.45f), false);
                     cardStyle.Draw(cardBoxRect, GUIContent.none, 0);
                     GUIHelper.PopColor();
                 }
                 this.DrawCard(section.Cards[j]);
                 EditorGUILayout.EndVertical();
                 if (j % colNum == 0)
                 {
                     GUILayout.FlexibleSpace();
                 }
             }
             if (flag)
             {
                 EditorGUILayout.EndHorizontal();
             }
         }
         GUILayout.Space(8f);
         if (i != page.Sections.Count - 1)
         {
             SirenixEditorGUI.DrawThickHorizontalSeparator(10f, 0f);
         }
     }
 }
 private void DrawPages()
 {
     GUIHelper.PushLabelWidth(10);
     this.scrollPoss = EditorGUILayout.BeginScrollView(this.scrollPoss, GUILayoutOptions.ExpandHeight(true));
     {
         var rect = EditorGUILayout.BeginVertical();
         if (this.width == 0 || Event.current.type == EventType.Repaint)
         {
             this.width = rect.width;
         }
         this.pager.BeginGroup();
         foreach (var page in this.pager.EnumeratePages)
         {
             if (page.BeginPage())
             {
                 DrawPage(page.Value);
             }
             page.EndPage();
         }
         this.pager.EndGroup();
         EditorGUILayout.EndVertical();
     }
     EditorGUILayout.EndScrollView();
     GUIHelper.PopLabelWidth();
 }
        private GUILayoutOption[] GetOuterRectLayoutOptions()
        {
            if (this.DrawScrollView == false)
            {
                return(GUILayoutOptions.Height(this.contentRect.height));
            }

            var g = GUILayoutOptions.ExpandHeight(false);

            if (this.MinScrollViewHeight > 0)
            {
                g = g.MinHeight(Mathf.Min(this.MinScrollViewHeight, this.contentRect.height));
            }

            if (this.MaxScrollViewHeight > 0)
            {
                g = g.MaxHeight(Mathf.Min(this.MaxScrollViewHeight, this.contentRect.height));
            }
            else
            {
                g = g.MaxHeight(Mathf.Min(99999, this.contentRect.height));
            }

            return(g);
            //return GUILayoutOptions.MinHeight(minHeight).MaxHeight(maxHeight);
        }
Exemple #7
0
        /// <summary>
        /// Begins the page.
        /// </summary>
        public bool BeginPage()
        {
            if (this.tabGroup.FixedHeight && this.isMessured == false)
            {
                this.IsVisible = true;
            }

            this.isSeen = true;

            if (this.IsVisible)
            {
                var rect = EditorGUILayout.BeginVertical(InnerContainerStyle, GUILayoutOptions.Width(this.tabGroup.InnerContainerWidth));

                GUIHelper.PushHierarchyMode(false);
                GUIHelper.PushLabelWidth(this.tabGroup.LabelWidth - 4);

                if (Event.current.type == EventType.Repaint)
                {
                    this.Rect = rect;
                }
                if (this.tabGroup.IsAnimating)
                {
                    this.prevColor = GUI.color;
                    var col = this.prevColor;
                    col.a    *= this.tabGroup.CurrentPage == this ? this.tabGroup.T : 1 - this.tabGroup.T;
                    GUI.color = col;
                }
            }
            return(this.IsVisible);
        }
Exemple #8
0
        /// <summary>
        /// Draws the Odin Editor Window.
        /// </summary>
        protected virtual void OnGUI()
        {
            if (Event.current.type == EventType.Layout)
            {
                bool setActive = this.menuTree == null;
                if (this.menuTree == null)
                {
                    this.ForceMenuTreeRebuild();
                    if (setActive)
                    {
                        OdinMenuTree.ActiveMenuTree = this.menuTree;
                    }

//                    if (UnityEditorEventUtility.HasOnProjectChanged)
//                    {
//                        UnityEditorEventUtility.OnProjectChanged -= ProjectWindowChanged;
//                        UnityEditorEventUtility.OnProjectChanged += ProjectWindowChanged;
//                    }
//                    else
//                    {
//#pragma warning disable 0618
//                        EditorApplication.projectWindowChanged -= ProjectWindowChanged;
//                        EditorApplication.projectWindowChanged += ProjectWindowChanged;
//#pragma warning restore 0618
//                    }
                }
            }

            Rect menuBorderRect;

            GUILayout.BeginVertical(GUILayoutOptions.Width(this.MenuWidth).ExpandHeight());
            {
                var rect = GUIHelper.GetCurrentLayoutRect();

                EditorGUI.DrawRect(rect, SirenixGUIStyles.MenuBackgroundColor);
                menuBorderRect       = rect;
                menuBorderRect.xMin  = rect.xMax - 4;
                menuBorderRect.xMax += 4;

                if (this.ResizableMenuWidth)
                {
                    EditorGUIUtility.AddCursorRect(menuBorderRect, MouseCursor.ResizeHorizontal);
                    this.MenuWidth += SirenixEditorGUI.SlideRect(menuBorderRect).x;
                }

                this.DrawMenu();
            }
            GUILayout.EndVertical();

            EditorGUI.DrawRect(menuBorderRect.AlignCenter(1), SirenixGUIStyles.BorderColor);

            if (this.menuTree != null)
            {
                this.menuTree.HandleKeybaordMenuNavigation();

                // TODO: Handle scroll to selected menu items...
                // this.menuTree.Selection.Last() is the latest selected item.
            }
        }
Exemple #9
0
        public void DrawOverview()
        {
            if (Event.current.type == EventType.Layout && this.nextDisplay != null)
            {
                this.Display     = this.nextDisplay.Value;
                this.nextDisplay = null;
                this.Update();
            }

            if (Event.current.type == EventType.Layout && this.shouldSort)
            {
                this.shouldSort = false;
                this.Sort();
            }

            EnumBtnStyle = EnumBtnStyle ?? new GUIStyle(EditorStyles.toolbarDropDown);
            EnumBtnStyle.stretchHeight = true;
            EnumBtnStyle.fixedHeight   = this.Tree.Config.SearchToolbarHeight;

            GUILayout.BeginHorizontal(GUILayoutOptions.ExpandHeight());
            {
                var rect       = GUIHelper.GetCurrentLayoutRect();
                var columnRect = rect.AddYMin(this.Tree.Config.SearchToolbarHeight);

                GUILayout.BeginVertical(GUILayoutOptions.Width(rect.width).ExpandHeight());
                {
                    EditorGUI.DrawRect(columnRect.AddYMin(this.Tree.Config.DefaultMenuStyle.Height), SirenixGUIStyles.EditorWindowBackgroundColor);

                    GUILayout.BeginHorizontal();
                    this.Tree.DrawSearchToolbar();
                    var displayRect = GUILayoutUtility.GetRect(95, this.Tree.Config.SearchToolbarHeight, GUILayoutOptions.Width(95));
                    displayRect.height = this.Tree.Config.SearchToolbarHeight;
                    displayRect.width -= 1;

                    var newDisplay = EnumSelector <DisplayOptions> .DrawEnumField(displayRect, null, GUIHelper.TempContent("Data Columns"), this.Display, EnumBtnStyle);

                    if (newDisplay != this.Display)
                    {
                        this.nextDisplay = newDisplay;
                    }

                    GUILayout.EndHorizontal();

                    GUITableUtilities.ResizeColumns(columnRect, this.columns);
                    this.DrawColumnHeaders();
                    this.Tree.DrawMenuTree();
                }

                GUILayout.EndVertical();
                GUITableUtilities.DrawColumnHeaderSeperators(columnRect, this.columns, SirenixGUIStyles.BorderColor);

                GUILayout.Space(-5);
            }
            GUILayout.EndHorizontal();
        }
 private GUILayoutOption[] GetScrollViewOptions(bool drawScrollBars)
 {
     if (drawScrollBars)
     {
         return(GUILayoutOptions.ExpandHeight(false));
     }
     else
     {
         return(GUILayoutOptions.Height(this.contentRect.height));
     }
 }
Exemple #11
0
        private void DrawSerializationInfoTree()
        {
            EditorGUILayout.BeginVertical(GUILayoutOptions.ExpandHeight());
            this.CreateMenuTree(false);

            if (this.serializationInfoTree != null)
            {
                this.serializationInfoTree.DrawMenuTree();
            }
            EditorGUILayout.EndVertical();
        }
Exemple #12
0
        private void DrawInfos()
        {
            if (this.serializationInfoTree == null)
            {
                return;
            }

            if (this.noteStyle == null)
            {
                this.noteStyle = new GUIStyle(SirenixGUIStyles.MultiLineLabel);
                this.noteStyle.active.textColor    = this.noteStyle.normal.textColor;
                this.noteStyle.onActive.textColor  = this.noteStyle.normal.textColor;
                this.noteStyle.onFocused.textColor = this.noteStyle.normal.textColor;
                this.noteStyle.focused.textColor   = this.noteStyle.normal.textColor;
                this.noteStyle.margin  = new RectOffset(20, 4, 0, 4);
                this.noteStyle.padding = new RectOffset(0, 0, 0, 0);
            }

            if (this.serializationInfoTree.Selection.Count > 0)
            {
                var info = this.serializationInfoTree.Selection[0].Value as MemberSerializationInfo;

                GUILayout.Space(10);
                GUILayout.BeginHorizontal();
                {
                    var bgRect = GUIHelper.GetCurrentLayoutRect().Expand(0, 10);
                    SirenixEditorGUI.DrawSolidRect(bgRect, SirenixGUIStyles.DarkEditorBackground);
                    SirenixEditorGUI.DrawBorders(bgRect, 0, 0, 1, 0);

                    // Note text.
                    GUILayout.BeginVertical(GUILayoutOptions.MinHeight(80));
                    {
                        foreach (var note in info.Notes)
                        {
                            Rect noteRect = GUILayoutUtility.GetRect(GUIHelper.TempContent(note), this.noteStyle);
                            var  dot      = noteRect;
                            dot.x     -= 8;
                            dot.y     += 5;
                            dot.height = 4;
                            dot.width  = 4;
                            SirenixEditorGUI.DrawSolidRect(dot, EditorGUIUtility.isProSkin ? Color.white : Color.black);
                            EditorGUI.SelectableLabel(noteRect, note, this.noteStyle);
                            GUILayout.Space(4);
                        }
                    }
                    GUILayout.EndVertical();

                    var r = GUIHelper.GetCurrentLayoutRect();
                    SirenixEditorGUI.DrawVerticalLineSeperator(r.x, r.y, r.height);
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(10);
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            EditorGUI.BeginChangeCheck();
            string s = new string(this.ValueEntry.SmartValue, 1);

            s = SirenixEditorFields.DelayedTextField(label, s, GUILayoutOptions.MinWidth(0));

            if (EditorGUI.EndChangeCheck() && s.Length > 0)
            {
                this.ValueEntry.SmartValue = s[0];
            }
        }
 protected override void DrawEditors()
 {
     GUILayout.BeginArea(new Rect(4f, 0f, Mathf.Max(300f, base.position.width - this.MenuWidth - 4f), base.position.height));
     this.scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, GUILayoutOptions.ExpandWidth(false));
     GUILayout.Space(4f);
     if (this.exampleItem != null)
     {
         this.exampleItem.Draw();
     }
     GUILayout.EndScrollView();
     GUILayout.EndArea();
 }
Exemple #15
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            decimal value = this.ValueEntry.SmartValue;
            string  str   = value.ToString();

            str = SirenixEditorFields.DelayedTextField(label, str, GUILayoutOptions.MinWidth(0));

            if (GUI.changed && decimal.TryParse(str, out value))
            {
                this.ValueEntry.SmartValue = value;
            }
        }
Exemple #16
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            GUILayout.BeginHorizontal();
            {
                GUILayout.BeginVertical();
                {
                    this.CallNextDrawer(label);
                }
                GUILayout.EndVertical();

                GUILayout.Label("SyncVar", EditorStyles.miniLabel, GUILayoutOptions.Width(52f));
            }
            GUILayout.EndHorizontal();
        }
Exemple #17
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            ulong  value = this.ValueEntry.SmartValue;
            string str   = value.ToString();

            str = label == null?
                  EditorGUILayout.DelayedTextField(str, GUILayoutOptions.MinWidth(0)) :
                      EditorGUILayout.DelayedTextField(label, str, GUILayoutOptions.MinWidth(0));

            if (GUI.changed && ulong.TryParse(str, out value))
            {
                this.ValueEntry.SmartValue = value;
            }
        }
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <bool> entry, GUIContent label)
        {
            // EditorGUI.Toggle will always return false, regardless of the given input when EditorGUI.showMixedValue is set to true.
            // Hence BeginChangeCheck.
            EditorGUI.BeginChangeCheck();

            bool value = label == null?
                         EditorGUILayout.Toggle(entry.SmartValue, GUILayoutOptions.ExpandWidth(false).Width(22)) :
                             EditorGUILayout.Toggle(label, entry.SmartValue);

            if (EditorGUI.EndChangeCheck())
            {
                entry.SmartValue = value;
            }
        }
Exemple #19
0
    public void Draw(float cardWidth)
    {
        Rect cardBoxRect = EditorGUILayout.BeginVertical(this.cardStylePadding,
                                                         GUILayoutOptions.Width(cardWidth));

        if (Event.current.type == EventType.Repaint)
        {
            GUIHelper.PushColor(new Color(1f, 1f, 1f, EditorGUIUtility.isProSkin ? 0.25f : 0.45f), false);
            cardStyle.Draw(cardBoxRect, GUIContent.none, 0);
            GUIHelper.PopColor();
        }
        this.DrawCard();
        SirenixEditorGUI.DrawVerticalLineSeperator(cardBoxRect.x, cardBoxRect.y, cardBoxRect.height);
        EditorGUILayout.EndVertical();
    }
Exemple #20
0
        internal static bool DrawColorPaletteColorPicker(object key, ColorPalette colorPalette, ref Color color, bool drawAlpha, bool stretchPalette, float width = 20, float height = 20, float margin = 0)
        {
            bool result = false;

            var rect = SirenixEditorGUI.BeginHorizontalAutoScrollBox(key, GUILayoutOptions.ExpandWidth(true).ExpandHeight(false));

            {
                if (stretchPalette)
                {
                    rect.width -= margin * colorPalette.Colors.Count - margin;
                    width       = Mathf.Max(width, rect.width / colorPalette.Colors.Count);
                }

                bool  isMouseDown = Event.current.type == EventType.MouseDown;
                var   innerRect   = GUILayoutUtility.GetRect((width + margin) * colorPalette.Colors.Count, height, GUIStyle.none);
                float spacing     = width + margin;
                var   cellRect    = innerRect;
                cellRect.width = width;

                for (int i = 0; i < colorPalette.Colors.Count; i++)
                {
                    cellRect.x = spacing * i;

                    if (drawAlpha)
                    {
                        EditorGUIUtility.DrawColorSwatch(cellRect, colorPalette.Colors[i]);
                    }
                    else
                    {
                        var c = colorPalette.Colors[i];
                        c.a = 1;
                        SirenixEditorGUI.DrawSolidRect(cellRect, c);
                    }

                    if (isMouseDown && cellRect.Contains(Event.current.mousePosition))
                    {
                        color       = colorPalette.Colors[i];
                        result      = true;
                        GUI.changed = true;
                        Event.current.Use();
                    }
                }
            }
            SirenixEditorGUI.EndHorizontalAutoScrollBox();
            return(result);
        }
 protected override void DrawEditor(int index)
 {
     scroll = GUILayout.BeginScrollView(scroll);
     {
         base.DrawEditor(index);
     }
     GUILayout.EndScrollView();
     if (previewObject)
     {
         GUILayout.FlexibleSpace();
         SirenixEditorGUI.HorizontalLineSeparator(1);
         if (GUILayout.Button("Create Asset", GUILayoutOptions.Height(30)))
         {
             CreateAsset();
         }
     }
 }
        private void DrawNormalButton()
        {
            Rect btnRect = this.buttonHeight > 0 ?
                           GUILayoutUtility.GetRect(GUIContent.none, style, GUILayoutOptions.Height(this.buttonHeight)) :
                           GUILayoutUtility.GetRect(GUIContent.none, style);

            btnRect = EditorGUI.IndentedRect(btnRect);

            var tmp = GUI.color;

            GUI.color = this.btnColor;
            if (GUI.Button(btnRect, this.label != null ? this.label : GUIHelper.TempContent(string.Empty), this.style))
            {
                InvokeButton();
            }
            GUI.color = tmp;
        }
        private void DrawFoldoutButton()
        {
            Rect btnRect = this.buttonHeight > 0 ?
                           GUILayoutUtility.GetRect(GUIContent.none, style, GUILayoutOptions.Height(this.buttonHeight)) :
                           GUILayoutUtility.GetRect(GUIContent.none, style);

            btnRect = EditorGUI.IndentedRect(btnRect);

            GUIHelper.PushColor(this.btnColor);

            var foldoutRect = btnRect.AlignRight(20);

            if (GUI.Button(foldoutRect, GUIContent.none, toggleBtnStyle))
            {
                this.toggle.Value = !this.toggle.Value;
            }

            btnRect.width -= foldoutRect.width;
            if (!this.toggle.Value)
            {
                foldoutRect.x    -= 1;
                foldoutRect.yMin -= 1;
            }

            if (this.toggle.Value)
            {
                EditorIcons.TriangleDown.Draw(foldoutRect, 16);
            }
            else
            {
                EditorIcons.TriangleLeft.Draw(foldoutRect, 16);
            }

            if (GUI.Button(btnRect, this.label, this.style))
            {
                this.InvokeButton();
            }

            GUIHelper.PopColor();

            EditorGUI.indentLevel++;
            this.DrawParameters(false);
            EditorGUI.indentLevel--;
        }
    protected override void DrawEditor(int index)
    {
        //scroll 内容滑动条的XY坐标
        scroll = GUILayout.BeginScrollView(scroll);
        {
            base.DrawEditor(index);
        }
        GUILayout.EndScrollView();

        if (this.previewObject)
        {
            GUILayout.FlexibleSpace();                   //插入一个空隙
            SirenixEditorGUI.HorizontalLineSeparator(5); //插入一个水平分割线
            if (GUILayout.Button("Create Asset", GUILayoutOptions.Height(30)))
            {
                CreateAsset();
            }
        }
    }
Exemple #25
0
        protected virtual void DrawMenuTree()
        {
            var rect = GUIHelper.GetCurrentLayoutRect();

            GUITableUtilities.ResizeColumns(rect, this.columns);
            rect = EditorGUILayout.BeginVertical(GUILayoutOptions.Width(this.MenuColumn.ColWidth));
            EditorGUI.DrawRect(rect, SirenixGUIStyles.DarkEditorBackground);
            this.tree = this.tree ?? this.BuildMenuTree();
            if (this.tree != null)
            {
                this.tree.Config.AutoHandleKeyboardNavigation = true;
                this.tree.DrawMenuTree();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
            GUILayout.Space(this.ContentPadding.x);
            SirenixEditorGUI.DrawBorders(rect, 1);
            GUILayout.BeginVertical();
            GUILayout.Space(this.ContentPadding.y);
        }
            protected override void DrawPropertyLayout(GUIContent label)
            {
                var entry = this.ValueEntry;

                if (entry.SmartValue.AutoToggle)
                {
#pragma warning disable 0618 // Type or member is obsolete
                    SirenixEditorGUI.ObjectField(null, entry.SmartValue.Object, entry.SmartValue.Object.GetType(), false, true);
#pragma warning restore 0618 // Type or member is obsolete
                }
                else
                {
                    var rect            = GUILayoutUtility.GetRect(16, 16, GUILayoutOptions.ExpandWidth(true));
                    var toggleRect      = new Rect(rect.x, rect.y, 16, 16);
                    var objectFieldRect = new Rect(rect.x + 20, rect.y, rect.width - 20, 16);

                    if (Event.current.type != EventType.Repaint)
                    {
                        toggleRect.x      -= 5;
                        toggleRect.y      -= 5;
                        toggleRect.width  += 10;
                        toggleRect.height += 10;
                    }
                    var prevChanged = GUI.changed;

                    entry.SmartValue.Toggled = GUI.Toggle(toggleRect, entry.SmartValue.Toggled, "");

                    if (prevChanged != GUI.changed)
                    {
                        entry.ApplyChanges();
                    }

                    GUIHelper.PushGUIEnabled(entry.SmartValue.Toggled);

#pragma warning disable 0618 // Type or member is obsolete
                    SirenixEditorGUI.ObjectField(objectFieldRect, null, entry.SmartValue.Object, entry.SmartValue.Object.GetType(), false, true);
#pragma warning restore 0618 // Type or member is obsolete

                    GUIHelper.PopGUIEnabled();
                }
            }
        private void LogEntriesGUI()
        {
            var evt     = Event.current;
            var evtType = evt.type;

            var options = GUILayoutOptions.Get(GUILayoutOptionType.MinHeight)
                          .SetValue(GUILayoutOptionType.MinHeight, 40);

            using (var scroll = new EditorGUILayout.ScrollViewScope(logEntriesScrollPosition, options))
            {
                using (new EditorGUILayout.VerticalScope())
                {
                    foreach (var entry in LogEntries)
                    {
                        bool selected = entry == SelectedLogEntry;
                        EditorGUILayout.LabelField(entry.Message, GetLogEntryStyle(selected));
                        var rect = GUILayoutUtility.GetLastRect();

                        int index = entry.Index;
                        if (evtType == EventType.MouseDown && rect.Contains(evt.mousePosition))
                        {
                            scheduledGUIActions.ScheduleAction(() => SelectedLogEntryIndex = index);
                            Repaint();
                        }
                    }
                }
                logEntriesScrollPosition = scroll.scrollPosition;
            }

            GUIEx.HorizontalLine(position.width);

            if (SelectedLogEntry != null)
            {
                SelectedLogEntry.StackTraceControl.GUI();
            }
        }
Exemple #28
0
        private void OnGUI()
        {
            if (this.behaviourValidationInfos == null)
            {
                this.FullScan();
            }

            if (Event.current.type == EventType.Layout)
            {
                if (this.validationInfoToSelect != null)
                {
                    this.selectedValidationInfo = this.validationInfoToSelect;
                    this.validationInfoToSelect = null;
                }
            }

            this.DrawToolbar();

            EditorGUILayout.BeginHorizontal();
            {
                var rect = EditorGUILayout.BeginVertical(GUILayoutOptions.Width(300 + this.offsetLeftSide));
                {
                    this.scrollLeftSide = EditorGUILayout.BeginScrollView(this.scrollLeftSide);
                    this.DrawHierachy();
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                {
                    SirenixEditorGUI.DrawSolidRect(GUIHelper.GetCurrentLayoutRect(), SirenixGUIStyles.DarkEditorBackground);
                    this.scrollRightRightSide = EditorGUILayout.BeginScrollView(this.scrollRightRightSide);
                    this.DrawPropertyTree();
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();

                rect.xMin = rect.xMax - 4;
                rect.x   += 4;
                SirenixEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.BorderColor);
                rect.xMin          -= 2;
                rect.xMax          += 2;
                this.offsetLeftSide = this.offsetLeftSide + SirenixEditorGUI.SlideRect(rect).x;
            }
            EditorGUILayout.EndHorizontal();

            if (this.isScanning && (Event.current.type == EventType.Repaint))
            {
                this.warningCount = 0;
                this.errorCount   = 0;
                this.validCount   = 0;

                for (int i = 0; i < this.behaviourValidationInfos.Count; i++)
                {
                    var o = this.behaviourValidationInfos[i];
                    if (o.ErrorCount == 0 && o.WarningCount == 0)
                    {
                        this.validCount++;
                    }
                    this.errorCount   += o.ErrorCount;
                    this.warningCount += o.WarningCount;
                }
                this.behaviourValidationInfos = this.behaviourValidationInfos.OrderByDescending(x => x.ErrorCount).ThenByDescending(x => x.WarningCount).ThenBy(x => x.Name).ToList();
                this.isScanning = false;
            }
            else if (this.triggerScan && Event.current.type == EventType.Repaint)
            {
                this.isScanning  = true;
                this.triggerScan = false;
                this.Repaint();
            }

            this.RepaintIfRequested();
        }
Exemple #29
0
        private void DrawDropdown()
        {
            IEnumerable <object> newResult = null;

            //if (this.Attribute.InlineSelector)
            //{
            //    bool recreateBecauseOfListChange = false;

            //    if (Event.current.type == EventType.Layout)
            //    {
            //        var _newCol = this.rawGetter.GetValue();
            //        if (_newCol != this.rawPrevGettedValue)
            //        {
            //            this.ReloadDropdownCollections();
            //            recreateBecauseOfListChange = true;
            //        }

            //        var iList = _newCol as IList;
            //        if (iList != null)
            //        {
            //            if (iList.Count != this.rawPrevGettedValueCount)
            //            {
            //                this.ReloadDropdownCollections();
            //                recreateBecauseOfListChange = true;
            //            }

            //            this.rawPrevGettedValueCount = iList.Count;
            //        }

            //        this.rawPrevGettedValue = _newCol;
            //    }

            //    if (this.inlineSelector == null || recreateBecauseOfListChange)
            //    {
            //        this.inlineSelector = this.CreateSelector();
            //        this.inlineSelector.SelectionChanged += (x) =>
            //        {
            //            this.nextResult = x;
            //        };
            //    }

            //    this.inlineSelector.OnInspectorGUI();

            //    if (this.nextResult != null)
            //    {
            //        newResult = this.nextResult;
            //        this.nextResult = null;
            //    }
            //}
            //else if (this.Attribute.AppendNextDrawer && !this.isList)
            if (this.Attribute.AppendNextDrawer && !this.isList)
            {
                GUILayout.BeginHorizontal();
                {
                    var width = 15f;
                    if (this.label != null)
                    {
                        width += GUIHelper.BetterLabelWidth;
                    }

                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, GUIContent.none, this.ShowSelector, GUIStyle.none, GUILayoutOptions.Width(width));

                    if (Event.current.type == EventType.Repaint)
                    {
                        var btnRect = GUILayoutUtility.GetLastRect().AlignRight(15);
                        btnRect.y += 4;
                        SirenixGUIStyles.PaneOptions.Draw(btnRect, GUIContent.none, 0);
                    }

                    GUILayout.BeginVertical();
                    bool disable = this.Attribute.DisableGUIInAppendedDrawer;
                    if (disable)
                    {
                        GUIHelper.PushGUIEnabled(false);
                    }
                    this.CallNextDrawer(null);
                    if (disable)
                    {
                        GUIHelper.PopGUIEnabled();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                string valueName = GetCurrentValueName();

                if (this.Attribute.HideChildProperties == false && this.Property.Children.Count > 0)
                {
                    Rect valRect;
                    this.isToggled.Value = SirenixEditorGUI.Foldout(this.isToggled.Value, this.label, out valRect);
                    newResult            = GenericSelector <object> .DrawSelectorDropdown(valRect, valueName, this.ShowSelector);

                    if (SirenixEditorGUI.BeginFadeGroup(this, this.isToggled.Value))
                    {
                        EditorGUI.indentLevel++;
                        for (int i = 0; i < this.Property.Children.Count; i++)
                        {
                            var child = this.Property.Children[i];
                            child.Draw(child.Label);
                        }
                        EditorGUI.indentLevel--;
                    }
                    SirenixEditorGUI.EndFadeGroup();
                }
                else
                {
                    newResult = GenericSelector <object> .DrawSelectorDropdown(this.label, valueName, this.ShowSelector);
                }
            }

            if (newResult != null && newResult.Any())
            {
                this.AddResult(newResult);
            }
        }
Exemple #30
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(GUIContent label)
        {
            var property  = this.Property;
            var attribute = this.Attribute;

            var context = property.Context.Get(this, "Context", (Context)null);

            if (context.Value == null)
            {
                context.Value = new Context();
                if (attribute.Title != null)
                {
                    context.Value.TitleHelper = new StringMemberHelper(property, attribute.Title);
                }

                context.Value.Widths      = new float[property.Children.Count];
                context.Value.MinWidths   = new float[property.Children.Count];
                context.Value.MaxWidths   = new float[property.Children.Count];
                context.Value.LabelWidths = new float[property.Children.Count];
                context.Value.Margins     = new Vector2[property.Children.Count];
                context.Value.Paddings    = new Vector2[property.Children.Count];

                float percentageAllocated = 0;
                for (int i = 0; i < property.Children.Count; i++)
                {
                    var child = property.Children[i];
                    var attr  = child.Children.Recurse()
                                .AppendWith(child)
                                .SelectMany(a => a.GetAttributes <HorizontalGroupAttribute>())
                                .FirstOrDefault(x => x.GroupID == attribute.GroupID);

                    if (attr == null)
                    {
                        context.Value.Widths[i] = -1;
                    }
                    else
                    {
                        context.Value.Widths[i]      = attr.Width;
                        context.Value.MinWidths[i]   = attr.MinWidth;
                        context.Value.MaxWidths[i]   = attr.MaxWidth;
                        context.Value.LabelWidths[i] = attr.LabelWidth;

                        if (attr.Width > 0 && attr.Width < 1)
                        {
                            context.Value.ContainsPercentageWidth++;
                            percentageAllocated += attr.Width;

                            // If we allocate 100% there is no way to resize the window down.
                            // In those cases, we convert the attribute to adjust itself automatically and Unity will ensure that
                            // that it reaches the 100% for us.
                            if (percentageAllocated >= 0.97)
                            {
                                percentageAllocated    -= attr.Width;
                                context.Value.Widths[i] = 0;
                                attr.Width = 0;
                            }
                        }

                        if (attr.MinWidth > 0 && attr.MinWidth <= 1)
                        {
                            context.Value.ContainsPercentageWidth++;

                            percentageAllocated += attr.MinWidth;
                            // Same thing for MinWidth.
                            if (percentageAllocated >= 0.97)
                            {
                                percentageAllocated       -= attr.MinWidth;
                                context.Value.MinWidths[i] = 0;
                                attr.MinWidth = 0;
                            }
                        }

                        context.Value.Margins[i]  = new Vector2(attr.MarginLeft, attr.MarginRight);
                        context.Value.Paddings[i] = new Vector2(attr.PaddingLeft, attr.PaddingRight);
                    }
                }
            }

            if (context.Value.TitleHelper != null)
            {
                if (context.Value.TitleHelper.ErrorMessage != null)
                {
                    SirenixEditorGUI.ErrorMessageBox(context.Value.TitleHelper.ErrorMessage);
                }
                else
                {
                    SirenixEditorGUI.Title(context.Value.TitleHelper.GetString(property), null, TextAlignment.Left, false);
                }
            }

            SirenixEditorGUI.BeginIndentedHorizontal();
            // GUILayout.BeginHorizontal();
            {
                if (attribute.LabelWidth > 0)
                {
                    GUIHelper.PushLabelWidth(attribute.LabelWidth);
                }

                var prevFieldWidth = EditorGUIUtility.fieldWidth;
                EditorGUIUtility.fieldWidth = 40;

                for (int i = 0; i < property.Children.Count; i++)
                {
                    float   width, minWidth, maxWidth;
                    Vector2 padding, margin;

                    if (context.Value.ContainsPercentageWidth > 1 && context.Value.TotalWidth == 0)
                    {
                        width    = 20; // Start small and expand next frame. Instead of starting to big and slowly getting smaller.
                        minWidth = 0;
                        maxWidth = 0;
                        padding  = new Vector2();
                        margin   = new Vector2();
                    }
                    else
                    {
                        width    = context.Value.Widths[i];
                        minWidth = context.Value.MinWidths[i];
                        maxWidth = context.Value.MaxWidths[i];
                        margin   = context.Value.Margins[i];
                        padding  = context.Value.Paddings[i];

                        if (padding.x > 0 && padding.x <= 1)
                        {
                            padding.x = padding.x * context.Value.TotalWidth;
                        }
                        if (padding.y > 0 && padding.y <= 1)
                        {
                            padding.y = padding.y * context.Value.TotalWidth;
                        }
                        if (margin.x > 0 && margin.x <= 1)
                        {
                            margin.x = margin.x * context.Value.TotalWidth;
                        }
                        if (margin.y > 0 && margin.y <= 1)
                        {
                            margin.y = margin.y * context.Value.TotalWidth;
                        }

                        if (width <= 1)
                        {
                            width = width * context.Value.TotalWidth;
                        }

                        width -= padding.x + padding.y;

                        if (minWidth > 0)
                        {
                            if (minWidth <= 1)
                            {
                                minWidth = minWidth * context.Value.TotalWidth;
                            }
                            minWidth -= padding.x + padding.y;
                        }

                        if (maxWidth > 0)
                        {
                            if (maxWidth <= 1)
                            {
                                maxWidth = maxWidth * context.Value.TotalWidth;
                            }
                            maxWidth -= padding.x + padding.y;
                        }
                    }

                    GUILayoutOptions.GUILayoutOptionsInstance options = null;

                    if (minWidth > 0)
                    {
                        options = GUILayoutOptions.MinWidth(minWidth);
                    }
                    if (maxWidth > 0)
                    {
                        options = options == null?GUILayoutOptions.MaxWidth(maxWidth) : options.MaxWidth(maxWidth);
                    }
                    if (options == null)
                    {
                        options = GUILayoutOptions.Width(width < 0 ? 0 : width);
                    }

                    if ((margin.x + padding.x) != 0)
                    {
                        GUILayout.Space(margin.x + padding.x);
                    }

                    GUILayout.BeginVertical(options);
                    property.Children[i].Draw(property.Children[i].Label);
                    GUILayout.Space(-3);
                    GUILayout.EndVertical();

                    if ((margin.y + padding.y) != 0)
                    {
                        GUILayout.Space(margin.y + padding.y);
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    var newWidth = GUIHelper.GetCurrentLayoutRect().width;

                    if (context.Value.TotalWidth != newWidth)
                    {
                        GUIHelper.RequestRepaint();
                    }

                    context.Value.TotalWidth = newWidth;
                }

                EditorGUIUtility.fieldWidth = prevFieldWidth;
                if (attribute.LabelWidth > 0)
                {
                    GUIHelper.PopLabelWidth();
                }
            }
            // GUILayout.EndHorizontal();
            SirenixEditorGUI.EndIndentedHorizontal();
        }