Exemplo n.º 1
0
        /// <summary>
        /// Draws the table.
        /// </summary>
        public void DrawTable()
        {
            var e = Event.current.type;

            if (this.minTalbeSize.y == 0 || this.isDirty)
            {
                this.ReCalculateSizes();
            }

            // If there are not auto-width columns it means that the table has a fixed width, and doesn't expand.
            // Otherwise it does expand.
            // Here we also make sure that we allocate atleast 10 pixels per auto-width column.
            GUILayoutOptions.GUILayoutOptionsInstance guiLayoutOptions;
            if (this.numOfAutoWidthColumns == 0)
            {
                guiLayoutOptions = GUILayoutOptions.ExpandWidth(false).Width(this.minTalbeSize.x);
            }
            else
            {
                guiLayoutOptions = GUILayoutOptions.ExpandWidth().MinWidth(this.minTalbeSize.x + this.numOfAutoWidthColumns * 10);
            }

            var newRect = GUILayoutUtility.GetRect(0, this.minTalbeSize.y > 0 ? this.minTalbeSize.y : 10, guiLayoutOptions);

            // Recalcualte sizes if resized.
            if (e == EventType.Repaint)
            {
                if (this.tableRect.width != newRect.width || this.tableRect.x != newRect.x || this.tableRect.y != newRect.y)
                {
                    this.tableRect = newRect;
                    this.ReCalculateSizes();
                }
                else
                {
                    this.tableRect = newRect;
                }
            }

            // Handle resizing:
            for (int x = 0; x < this.ColumnCount - 1; x++)
            {
                if (x < this.ColumnCount - 1 && this.columnInfos[x + 1].Resizable == false)
                {
                    continue;
                }
                if (this.columnInfos[x].Resizable == false)
                {
                    continue;
                }

                GUITableCell resizeCell = null;
                for (int y = 0; y < this.RowCount; y++)
                {
                    var candidate = this.cells[x, y];
                    if (candidate != null && candidate.SpanX == false)
                    {
                        resizeCell = candidate;
                        break;
                    }
                }

                if (resizeCell != null)
                {
                    var rect = resizeCell.Rect;
                    rect.x     = rect.xMax - 5;
                    rect.width = 10;

                    var mouseDelta = AllEditorGUI.SlideRect(rect).x;
                    if (mouseDelta != 0)
                    {
                        if (mouseDelta > 0)
                        {
                            var        ci = this.columnInfos[x];
                            ColumnInfo nextResizableCol = null;

                            for (int j = x + 1; j < this.ColumnCount; j++)
                            {
                                if (this.columnInfos[j].Resizable)
                                {
                                    nextResizableCol = this.columnInfos[j];
                                    break;
                                }
                            }

                            if (nextResizableCol != null)
                            {
                                float remaining = nextResizableCol.ColumnWidth - nextResizableCol.ColumnMinWidth;
                                if (nextResizableCol != null && remaining > 0)
                                {
                                    mouseDelta       = Mathf.Min(mouseDelta, remaining);
                                    ci.ResizeOffset += mouseDelta;
                                    nextResizableCol.ResizeOffset -= mouseDelta;
                                }

                                this.ReCalculateSizes();
                            }
                        }
                        else
                        {
                            var ci = this.columnInfos[x + 1];
                            mouseDelta *= -1;
                            ColumnInfo prevResizableCol = null;

                            for (int j = x; j >= 0; j--)
                            {
                                if (this.columnInfos[j].Resizable)
                                {
                                    prevResizableCol = this.columnInfos[j];
                                    break;
                                }
                            }

                            if (prevResizableCol != null)
                            {
                                float remaining = prevResizableCol.ColumnWidth - prevResizableCol.ColumnMinWidth;
                                if (prevResizableCol != null && remaining > mouseDelta)
                                {
                                    mouseDelta       = Mathf.Min(mouseDelta, remaining);
                                    ci.ResizeOffset += mouseDelta;
                                    prevResizableCol.ResizeOffset -= mouseDelta;
                                }
                            }

                            this.ReCalculateSizes();
                        }
                    }
                }
            }

            // Draw Cells:
            for (int x = 0; x < this.ColumnCount; x++)
            {
                for (int y = 0; y < this.RowCount; y++)
                {
                    var cell = this.cells[x, y];
                    if (cell != null)
                    {
                        cell.Draw();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the ODIN Editor Window.
        /// </summary>
        protected override void OnGUI()
        {
            if (Event.current.type == EventType.Layout)
            {
                if (this.menuTree == null || this.isDirty)
                {
                    this.ForceMenuTreeRebuild();

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

                    this.isDirty = false;
                }

                // Try select object.
                if (this.trySelectObject != null && this.menuTree != null)
                {
                    var menuItem = this.menuTree.EnumerateTree()
                                   .FirstOrDefault(x => x.ObjectInstance == this.trySelectObject);

                    if (menuItem != null)
                    {
                        this.menuTree.Selection.Clear();
                        menuItem.Select();
                        this.trySelectObject = null;
                    }
                }
            }

            Rect menuBorderRect;
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayoutOptions.Width(this.MenuWidth));
            {
                Rect 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 += AllEditorGUI.SlideRect(menuBorderRect).x;
                }
                // 左边的菜单编辑在这里
                this.DrawMenu();
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            {
                var rect = GUIHelper.GetCurrentLayoutRect();
                EditorGUI.DrawRect(rect, SirenixGUIStyles.DarkEditorBackground);
                base.OnGUI();
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            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.
            }
        }
Exemplo n.º 3
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();
                {
                    AllEditorGUI.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;
                AllEditorGUI.DrawSolidRect(rect, SirenixGUIStyles.BorderColor);
                rect.xMin          -= 2;
                rect.xMax          += 2;
                this.offsetLeftSide = this.offsetLeftSide + AllEditorGUI.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();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TDictionary> entry, GUIContent label)
        {
            var context = entry.Property.Context.Get(this, "context", (Context)null);

            if (context.Value == null)
            {
                context.Value                = new Context();
                context.Value.Toggled        = entry.Context.GetPersistent(this, "Toggled", GeneralDrawerConfig.Instance.OpenListsByDefault);
                context.Value.KeyWidthOffset = 130;
                context.Value.Label          = label ?? new GUIContent(typeof(TDictionary).GetNiceName());
                context.Value.AttrSettings   = entry.Property.Info.GetAttribute <DictionaryDrawerSettings>() ?? new DictionaryDrawerSettings();
                context.Value.DisableAddKey  = entry.Property.Tree.HasPrefabs && !entry.GetDictionaryHandler().SupportsPrefabModifications;

                if (!context.Value.DisableAddKey)
                {
                    context.Value.TempKeyValue = new TempKeyValue();

                    var tree = PropertyTree.Create(context.Value.TempKeyValue);
                    tree.UpdateTree();

                    context.Value.TempKeyEntry   = (IPropertyValueEntry <TKey>)tree.GetPropertyAtPath("Key").ValueEntry;
                    context.Value.TempValueEntry = (IPropertyValueEntry <TValue>)tree.GetPropertyAtPath("Value").ValueEntry;
                }
            }

            context.Value.DictionaryHandler           = (DictionaryHandler <TDictionary, TKey, TValue>)entry.GetDictionaryHandler();
            context.Value.Config                      = GeneralDrawerConfig.Instance;
            context.Value.Paging.NumberOfItemsPerPage = context.Value.Config.NumberOfItemsPrPage;
            context.Value.ListItemStyle.padding.right = !entry.IsEditable || context.Value.AttrSettings.IsReadOnly ? 4 : 20;

            //if (!IsSupportedKeyType)
            //{
            //    var message = entry.Property.Context.Get(this, "error_message", (string)null);
            //    var detailedMessage = entry.Property.Context.Get(this, "error_message_detailed", (string)null);
            //    var folded = entry.Property.Context.Get(this, "error_message_folded", true);

            //    if (message.Value == null)
            //    {
            //        string str = "";

            //        if (label != null)
            //        {
            //            str += label.text + "\n\n";
            //        }

            //        str += "The dictionary key type '" + typeof(TKey).GetNiceFullName() + "' is not supported in prefab instances. Expand this box to see which key types are supported.";

            //        message.Value = str;
            //    }

            //    if (detailedMessage.Value == null)
            //    {
            //        var sb = new StringBuilder("The following key types are supported:");

            //        sb.AppendLine()
            //          .AppendLine();

            //        foreach (var type in DictionaryKeyUtility.GetPersistentPathKeyTypes())
            //        {
            //            sb.AppendLine(type.GetNiceName());
            //        }

            //        sb.AppendLine("Enums of any type");

            //        detailedMessage.Value = sb.ToString();
            //    }

            //    folded.Value = AllEditorGUI.DetailedMessageBox(message.Value, detailedMessage.Value, MessageType.Error, folded.Value);

            //    return;
            //}

            AllEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            {
                context.Value.Paging.Update(elementCount: entry.Property.Children.Count);
                this.DrawToolbar(entry, context.Value);
                context.Value.Paging.Update(elementCount: entry.Property.Children.Count);

                if (!context.Value.DisableAddKey && context.Value.AttrSettings.IsReadOnly == false)
                {
                    this.DrawAddKey(entry, context.Value);
                }

                float t;
                GUIHelper.BeginLayoutMeasuring();
                if (AllEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(entry.Property, this), context.Value.Toggled.Value, out t))
                {
                    var rect = AllEditorGUI.BeginVerticalList(false);
                    if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine)
                    {
                        var maxWidth = rect.width - 90;
                        rect.xMin = context.Value.KeyWidthOffset + 22;
                        rect.xMax = rect.xMin + 10;
                        context.Value.KeyWidthOffset = context.Value.KeyWidthOffset + AllEditorGUI.SlideRect(rect).x;

                        if (Event.current.type == EventType.Repaint)
                        {
                            context.Value.KeyWidthOffset = Mathf.Clamp(context.Value.KeyWidthOffset, 90, maxWidth);
                        }

                        if (context.Value.Paging.ElementCount != 0)
                        {
                            var headerRect = AllEditorGUI.BeginListItem(false);
                            {
                                GUILayout.Space(14);
                                if (Event.current.type == EventType.Repaint)
                                {
                                    GUI.Label(headerRect.SetWidth(context.Value.KeyWidthOffset), context.Value.AttrSettings.KeyLabel, SirenixGUIStyles.LabelCentered);
                                    GUI.Label(headerRect.AddXMin(context.Value.KeyWidthOffset), context.Value.AttrSettings.ValueLabel, SirenixGUIStyles.LabelCentered);
                                    AllEditorGUI.DrawSolidRect(headerRect.AlignBottom(1), SirenixGUIStyles.BorderColor);
                                }
                            }
                            AllEditorGUI.EndListItem();
                        }
                    }

                    this.DrawElements(entry, label, context.Value);
                    AllEditorGUI.EndVerticalList();
                }
                AllEditorGUI.EndFadeGroup();

                // Draw borders
                var outerRect = GUIHelper.EndLayoutMeasuring();
                if (t > 0.01f && Event.current.type == EventType.Repaint)
                {
                    Color col = SirenixGUIStyles.BorderColor;
                    outerRect.yMin -= 1;
                    AllEditorGUI.DrawBorders(outerRect, 1, col);
                    col.a *= t;
                    if (context.Value.AttrSettings.DisplayMode == DictionaryDisplayOptions.OneLine)
                    {
                        // Draw Slide Rect Border
                        outerRect.width = 1;
                        outerRect.x    += context.Value.KeyWidthOffset + 13;
                        AllEditorGUI.DrawSolidRect(outerRect, col);
                    }
                }
            }
            AllEditorGUI.EndIndentedVertical();
        }