Exemplo n.º 1
0
        private void DrawColorPicker(Rect rect)
        {
            int   rows    = 2;
            int   columns = 10;
            float width   = rect.width / columns;
            float height  = rect.height / rows;

            for (int x = 0; x < columns; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    Rect colorRect = new Rect(rect)
                    {
                        x = rect.x + (width * x), y = rect.y + (height * y), width = width, height = height
                    };
                    int   index = x + (y * columns);
                    Color color = HierarchyProEditorNoteWindow.colors[index];
                    EditorGUI.DrawRect(colorRect, color);
                    if (GUI.Button(colorRect, GUIContent.none, GUIStyle.none))
                    {
                        this.note.ColorBackground = color;
                        EditorApplication.RepaintHierarchyWindow();
                        HierarchyProEditorGroupWindow.Redraw();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void Delete(object userdata)
        {
            HierarchyProGroup group = (HierarchyProGroup)userdata;

            HierarchyProGroupLibrary.Delete(group);
            HierarchyProEditorGroupWindow.Redraw();
        }
Exemplo n.º 3
0
        private void DrawHeader(Rect rect)
        {
            Rect iconRect = new Rect(rect)
            {
                x = rect.x + 5, width = 16
            };

            foreach (Texture icon in HierarchyProEditorNoteWindow.Icons)
            {
                if (this.note.Icon == icon)
                {
                    EditorGUI.DrawRect(iconRect, GUI.skin.settings.selectionColor);
                }

                if (icon != null)
                {
                    GUI.DrawTexture(iconRect.GetCenteredIconRect(icon, 16, 16), icon);
                }

                if (GUI.Button(iconRect, GUIContent.none, GUIStyle.none))
                {
                    this.note.Icon = icon;
                    EditorApplication.RepaintHierarchyWindow();
                    HierarchyProEditorGroupWindow.Redraw();
                }

                iconRect = new Rect(iconRect)
                {
                    x = iconRect.x + 16
                };
            }

            float x         = iconRect.x + 5;
            Rect  colorFore = new Rect(rect)
            {
                x = x, width = rect.width - x - 26
            };

            this.DrawColorPicker(colorFore);

            Rect rectDelete = new Rect(colorFore)
            {
                x = colorFore.x + colorFore.width + 5, width = 16
            };

            GUI.color = new Color(0.3f, 0.3f, 0.3f);
            GUI.DrawTexture(rectDelete.GetCenteredIconRect(HierarchyProEditorIcons.Delete), HierarchyProEditorIcons.Delete);
            GUI.color = Color.white;
            if (GUI.Button(rectDelete, GUIContent.none, GUIStyle.none))
            {
                if (EditorUtility.DisplayDialog("Are you sure?", "Are you sure you want to delete this note?", "Yes", "No"))
                {
                    this.editorWindow.Close();
                    HierarchyProNotesLibrary.Delete(this.note);
                    EditorApplication.RepaintHierarchyWindow();
                    HierarchyProEditorGroupWindow.Redraw();
                }
            }
        }
        private void OnGUI()
        {
            Rect window  = this.position;
            Rect toolbar = new Rect(0, 0, window.width, 18);
            Rect rect    = new Rect(0, toolbar.yMax, window.width, window.height - toolbar.yMax);

            GUI.Label(toolbar, GUIContent.none, HierarchyProEditorStyles.ToolbarHorizontal);
            this.DrawToolbar(toolbar);

            if (HierarchyProGroupLibrary.Count == 0)
            {
                HierarchyProEditorGroupWindow.DrawNoGroupsMessage(rect);
                return;
            }

            this.groupData = HierarchyProEditorGroupWindow.StackGroups(rect).ToList();
            float height     = (this.groupData != null) && this.groupData.Any() ? this.groupData.Max(x => x.Rect.yMax) - rect.y : 0;
            Rect  scrollRect = new Rect(rect)
            {
                width = rect.width - 18, height = height
            };

            this.scrollPosition = GUI.BeginScrollView(rect, this.scrollPosition, scrollRect);

            this.trackDrag.Update(Event.current);
            this.HandleNativeDrag();

            bool hasScrollbar = scrollRect.height > rect.height;

            foreach (HierarchyProEditorGroupLine line in this.groupData)
            {
                bool dragOver = false;
                if (this.dragging != null)
                {
                    Rect dropRect = line.Rect;
                    if (line.Group == this.dragging)
                    {
                        dropRect.width = 16;
                    }
                    if (dropRect.Contains(this.dragPosition))
                    {
                        dragOver = true;
                    }
                }

                line.Draw(hasScrollbar, dragOver);
            }
            if (GUI.Button(rect, GUIContent.none, GUIStyle.none))
            {
                HierarchyProEditorGroupWindow.Selected = null;
                this.renaming = null;
                this.Repaint();
            }

            GUI.EndScrollView();
        }
        private void OnEnable()
        {
            HierarchyProEditorGroupWindow.instance = this;
            this.trackDrag           = new HierarchyProEditorTrackDrag();
            this.trackDrag.Drag     += this.TrackDragOnDrag;
            this.trackDrag.Drop     += this.TrackDragOnDrop;
            this.trackDrag.Dragging += this.TrackDragOnDragging;

            this.wantsMouseMove = true;
        }
 private static void Update()
 {
     if (HierarchyPro.RedrawPending)
     {
         EditorApplication.RepaintHierarchyWindow();
     }
     if (HierarchyProEditorGroupWindow.RedrawPending)
     {
         HierarchyProEditorGroupWindow.Redraw();
     }
 }
        private static IEnumerable <HierarchyProEditorGroupLine> StackGroups(Rect rect)
        {
            Rect lineRect = new Rect(rect)
            {
                height = 16
            };
            List <HierarchyProEditorGroupLine> lines = new List <HierarchyProEditorGroupLine>();

            foreach (HierarchyProGroup group in HierarchyProGroupLibrary.RootGroups)
            {
                HierarchyProEditorGroupWindow.StackGroupsRecursive(ref lines, ref lineRect, group);
            }
            return(lines);
        }
        private static void StackGroupsRecursive(ref List <HierarchyProEditorGroupLine> lines, ref Rect lineRect, HierarchyProGroup group, int indent = 0)
        {
            lines.Add(HierarchyProEditorGroupLine.Create(group, lineRect, indent));
            lineRect.y += lineRect.height;

            if (group.ShowChildren)
            {
                IEnumerable <HierarchyProGroup> children = HierarchyProGroupLibrary.FindChildren(group).ToList();
                group.HasChildren = children.Any();
                foreach (HierarchyProGroup child in children)
                {
                    HierarchyProEditorGroupWindow.StackGroupsRecursive(ref lines, ref lineRect, child, indent + 1);
                }
            }
        }
        public static void Create()
        {
            HierarchyProEditorGroupWindow window = EditorWindow.GetWindow <HierarchyProEditorGroupWindow>();

            GUIContent titleContent = new GUIContent("Groups", HierarchyProEditorIcons.Group);

#if UNITY_5_1 || UNITY_5_2 || UNITY_5_3_OR_NEWER
            window.titleContent = titleContent;
#else
            window.title = titleContent.text;

            PropertyInfo titleInfo = window.GetType().GetProperty("cachedTitleContent", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField);
            GUIContent   title     = titleInfo.GetValue(window, null) as GUIContent;
            title.image = titleContent.image;
#endif
            window.autoRepaintOnSceneChange = true;

            window.Show();
        }
Exemplo n.º 10
0
        public void Draw(bool hasScrollbar, bool dragOver)
        {
            Rect lineRect = this.Rect;

            if (hasScrollbar)
            {
                lineRect.width -= 18;
            }

            if (HierarchyProEditorGroupWindow.Renaming == this.Group)
            {
                HierarchyProEditorGroupWindow.RenamingName = GUI.TextField(new Rect(lineRect)
                {
                    x = lineRect.x + 16, width = lineRect.width - 16
                }, HierarchyProEditorGroupWindow.RenamingName);
                if ((Event.current.keyCode == KeyCode.Return) || (Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    this.Group.Name = HierarchyProEditorGroupWindow.RenamingName;
                    HierarchyProEditorGroupWindow.Renaming = null;
                    HierarchyProEditorGroupWindow.Redraw();
                }
                if (Event.current.keyCode == KeyCode.Escape)
                {
                    HierarchyProEditorGroupWindow.Renaming = null;
                    HierarchyProEditorGroupWindow.Redraw();
                }
                return;
            }

            if (lineRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.keyCode == KeyCode.Delete)
                {
                    HierarchyProGroupLibrary.Delete(this.Group);
                    Event.current.Use();
                }
            }

            if (HierarchyProEditorGroupWindow.Selected == this.Group)
            {
                EditorGUI.DrawRect(lineRect, GUI.skin.settings.selectionColor);
            }

            Rect labelRect = new Rect(lineRect)
            {
                x = 16 + (this.Indent * 16)
            };

            if (this.group.HasChildren)
            {
                this.group.ShowChildren = EditorGUI.Foldout(new Rect(labelRect)
                {
                    x = labelRect.x - 16, width = 16
                }, this.group.ShowChildren, GUIContent.none);
            }
            GUI.Label(labelRect, this.Name);

            bool collapseCount = HierarchyProEditorGroupWindow.Width <= 225;
            Rect rectActive    = new Rect(lineRect)
            {
                x = lineRect.xMax - 16, width = 16
            };
            Rect rectLocked = new Rect(rectActive)
            {
                x = rectActive.x - 16
            };
            Rect rectNotes = new Rect(rectLocked)
            {
                x = rectLocked.x - 12
            };
            Rect rectDivider1 = new Rect(rectNotes)
            {
                x = rectNotes.x - 2, width = 1
            };
            Rect rectCount = new Rect(lineRect)
            {
                x = rectDivider1.x - 56, width = 56
            };
            Rect rectDivider2 = new Rect(rectCount)
            {
                x = rectCount.x - 4, width = 1
            };
            Rect rectSelect = new Rect(lineRect)
            {
                x = (collapseCount ? rectDivider1 : rectDivider2).x - 12, width = 12
            };
            Rect rectAddRemove = new Rect(rectActive)
            {
                x = rectSelect.x - 24, width = 24
            };
            Rect rectControlArea = new Rect(lineRect)
            {
                xMin = rectAddRemove.x, xMax = rectActive.xMax
            };

            EditorGUI.DrawRect(rectControlArea, HierarchyProEditorColors.Background);

            this.DrawActive(rectActive);
            this.DrawLocked(rectLocked);
            HierarchyProEditorNotes.Draw(rectNotes, this.group);

            EditorGUI.DrawRect(rectDivider1, EditorGUIUtility.isProSkin ? new Color(0.1f, 0.1f, 0.1f) : new Color(0.6f, 0.6f, 0.6f));

            if (!collapseCount)
            {
                this.DrawCount(rectCount);
                EditorGUI.DrawRect(rectDivider2, EditorGUIUtility.isProSkin ? new Color(0.1f, 0.1f, 0.1f) : new Color(0.6f, 0.6f, 0.6f));
            }

            this.DrawSelect(rectSelect);
            this.DrawAddRemove(rectAddRemove);

            if (GUI.Button(new Rect(labelRect)
            {
                width = rectSelect.x - labelRect.x
            }, GUIContent.none, GUIStyle.none))
            {
                HierarchyProEditorGroupWindow.Selected = this.Group;
                if (Event.current.button == 1)
                {
                    this.ShowContextMenu();
                }
            }

            if (dragOver)
            {
                if (HierarchyProEditorGroupWindow.Dragging == this.group)
                {
                    GUI.Label(new Rect(lineRect)
                    {
                        width = 16
                    }, GUIContent.none, HierarchyProEditorStyles.DropHighlight);
                }
                else
                {
                    GUI.Label(lineRect, GUIContent.none, HierarchyProEditorStyles.DropHighlight);
                }
            }
        }