Rect DrawTools(Rect rect, SelectionGroup group)
        {
            rect.width  = 18;
            rect.height = 18;
            foreach (var i in TypeCache.GetMethodsWithAttribute <SelectionGroupToolAttribute>())
            {
                var attr = i.GetCustomAttribute <SelectionGroupToolAttribute>();
                if (!group.enabledTools.Contains(attr.ToolID))
                {
                    continue;
                }
                var content = EditorGUIUtility.IconContent(attr.icon);
                content.tooltip = attr.description;
                if (GUI.Button(rect, content, miniButtonStyle))
                {
                    try
                    {
                        i.Invoke(null, new object[] { group });
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
                rect.x += rect.width;
            }

            return(rect);
        }
        bool DrawHeader(Rect rect, SelectionGroup group, bool isActive)
        {
            // if (group == null) return false;
            var content = EditorGUIUtility.IconContent("LODGroup Icon");

            content.text = $"{group.name} ({group.Count}/{group.TotalCount})";
            var backgroundColor = group == activeSelectionGroup ? Color.white * 0.6f : Color.white * 0.3f;

            EditorGUI.DrawRect(rect, backgroundColor);


            rect.width        = 16;
            group.showMembers = EditorGUI.Toggle(rect, group.showMembers, "foldout");
            rect.x           += 16;
            rect.width        = EditorGUIUtility.currentViewWidth - 128;

            HandleHeaderMouseEvents(rect, group.name, group);
            GUI.Label(rect, content, "label");

            rect.x   += rect.width;
            rect      = DrawTools(rect, group);
            rect.x   += 8;
            rect.xMax = position.xMax;

            EditorGUI.DrawRect(rect, new Color(group.color.r, group.color.g, group.color.b));

            return(group.showMembers);
        }
        static void DisableEditing(SelectionGroup group)
        {
            var isLocked = false;

            foreach (var g in group)
            {
                if (g.hideFlags.HasFlag(HideFlags.NotEditable))
                {
                    isLocked = true;
                }
            }
            if (isLocked)
            {
                foreach (var g in group)
                {
                    g.hideFlags &= ~HideFlags.NotEditable;
                }
            }
            else
            {
                foreach (var g in group)
                {
                    g.hideFlags |= HideFlags.NotEditable;
                }
            }
        }
 static void ToggleVisibility(SelectionGroup group)
 {
     foreach (var g in group)
     {
         var go = g as GameObject;
         if (go == null)
         {
             continue;
         }
         SceneVisibilityManager.instance.ToggleVisibility(go, false);
     }
 }
        public static void Open(SelectionGroup group, SelectionGroupEditorWindow parentWindow)
        {
            var dialog = EditorWindow.GetWindow <SelectionGroupConfigurationDialog>();

            // var dialog = ScriptableObject.CreateInstance(typeof(SelectionGroupConfigurationDialog)) as SelectionGroupConfigurationDialog;
            dialog.groupId      = group.groupId;
            dialog.parentWindow = parentWindow;
            dialog.refreshQuery = true;
            // dialog.ShowModalUtility();
            dialog.titleContent.text = $"Configure {group.name}";
            dialog.ShowPopup();
            dialog.debugInformation = null;
        }
 void DrawAllGroupMembers(Rect rect, SelectionGroup group, bool allowRemove)
 {
     rect.height = EditorGUIUtility.singleLineHeight;
     foreach (var i in group)
     {
         //if rect is below window, early out.
         if (rect.yMin - scroll.y > position.height)
         {
             return;
         }
         //if rect is in window, draw.
         if (rect.yMax - scroll.y > 0)
         {
             DrawGroupMember(rect, group, i, allowRemove);
         }
         rect.y += rect.height;
     }
 }
        void ShowGroupContextMenu(Rect rect, string groupName, SelectionGroup group)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Duplicate Group"), false, () =>
            {
                SelectionGroupManager.instance.DuplicateGroup(group.groupId);
            });
            menu.AddItem(new GUIContent("Clear Group"), false, () =>
            {
                Undo.RegisterCompleteObjectUndo(SelectionGroupManager.instance, "Clear");
                group.Clear();
            });
            menu.AddItem(new GUIContent("Configure Group"), false, () => SelectionGroupConfigurationDialog.Open(group, this));
            menu.AddItem(new GUIContent("Delete Group"), false, () =>
            {
                SelectionGroupManager.instance.RemoveGroup(group.groupId);
            });
            menu.DropDown(rect);
        }
        void ShowGameObjectContextMenu(Rect rect, SelectionGroup group, Object g, bool allowRemove)
        {
            // Selection.activeObject = g;
            var menu    = new GenericMenu();
            var content = new GUIContent("Remove From Group");

            if (allowRemove)
            {
                menu.AddItem(content, false, () =>
                {
                    Undo.RegisterCompleteObjectUndo(SelectionGroupManager.instance, "Remove");
                    group.Remove(Selection.objects);
                });
            }
            else
            {
                menu.AddDisabledItem(content);
            }
            menu.DropDown(rect);
        }
        void HandleHeaderMouseEvents(Rect rect, string groupName, SelectionGroup group)
        {
            var e = Event.current;

            if (rect.Contains(e.mousePosition))
            {
                switch (e.type)
                {
                case EventType.MouseDown:
                    switch (e.button)
                    {
                    case RIGHT_MOUSE_BUTTON:
                        ShowGroupContextMenu(rect, groupName, group);
                        break;

                    case LEFT_MOUSE_BUTTON:
                        if (e.clickCount == 1)
                        {
                            activeSelectionGroup = group;
                        }
                        else
                        {
                            SelectionGroupConfigurationDialog.Open(group, this);
                        }
                        break;
                    }

                    break;

                case EventType.MouseDrag:
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.StartDrag(groupName);
                    DragAndDrop.objectReferences = group.ToArray();
                    e.Use();
                    break;
                }
            }
        }
Пример #10
0
        public bool HandleGroupDragEvents(Rect rect, SelectionGroup group)
        {
            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (!rect.Contains(evt.mousePosition))
                {
                    return(false);
                }

                var canDrop = string.IsNullOrEmpty(group.query);

                if (!canDrop)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }

                hotRect = rect;

                if (evt.type == EventType.DragPerform && canDrop)
                {
                    DragAndDrop.AcceptDrag();
                    Undo.RegisterCompleteObjectUndo(SelectionGroupManager.instance, "Add to group");
                    group.Add(DragAndDrop.objectReferences);
                    hotRect = null;
                }
                break;
            }
            return(false);
        }
 public SelectionGroupDebugInformation(SelectionGroup group)
 {
     text = EditorJsonUtility.ToJson(group, prettyPrint: true);
 }
        void DrawGroupMember(Rect rect, SelectionGroup group, Object g, bool allowRemove)
        {
            if (g == null)
            {
                return;
            }
            var e                      = Event.current;
            var content                = EditorGUIUtility.ObjectContent(g, g.GetType());
            var isInSelection          = activeSelection.Contains(g);
            var isMouseOver            = rect.Contains(e.mousePosition);
            var isMouseDrag            = e.type == EventType.MouseDrag;
            var isManySelected         = activeSelection.Count > 1;
            var isAnySelected          = activeSelection.Count > 0;
            var isLeftButton           = e.button == LEFT_MOUSE_BUTTON;
            var isRightButton          = e.button == RIGHT_MOUSE_BUTTON;
            var isMouseDown            = e.type == EventType.MouseDown;
            var isMouseUp              = e.type == EventType.MouseUp;
            var isNoSelection          = activeSelection.Count == 0;
            var isControl              = e.control;
            var isShift                = e.shift;
            var isLeftMouseDown        = isMouseOver && isLeftButton && isMouseDown;
            var isLeftMouseUp          = isMouseOver && isLeftButton && isMouseUp;
            var isHotMember            = g == hotMember;
            var updateSelectionObjects = false;

            if (isMouseOver)
            {
                EditorGUI.DrawRect(rect, HOVER_COLOR);
            }

            if (isLeftMouseDown)
            {
                hotMember = g;
            }


            if (isControl)
            {
                if (isLeftMouseUp && isHotMember && isInSelection)
                {
                    activeSelection.Remove(g);
                    activeSelectionGroup   = group;
                    updateSelectionObjects = true;
                }
                if (isLeftMouseUp && isHotMember && !isInSelection)
                {
                    activeSelection.Add(g);
                    activeSelectionGroup   = group;
                    updateSelectionObjects = true;
                }
            }
            else if (isShift)
            {
                if (isLeftMouseUp && isHotMember)
                {
                    activeSelection.Add(g);
                    int firstIndex = -1, lastIndex = -1;
                    for (var i = 0; i < group.Count; i++)
                    {
                        if (activeSelection.Contains(group[i]))
                        {
                            if (firstIndex < 0)
                            {
                                firstIndex = i;
                            }
                            lastIndex = i;
                        }
                    }
                    for (var i = firstIndex; i < lastIndex; i++)
                    {
                        activeSelection.Add(group[i]);
                    }
                    updateSelectionObjects = true;
                }
            }
            else
            {
                if (isLeftMouseUp && isHotMember)
                {
                    if (isInSelection && isManySelected)
                    {
                        activeSelection.Clear();
                        activeSelection.Add(g);
                        updateSelectionObjects = true;
                    }
                    else if (!isInSelection)
                    {
                        activeSelection.Clear();
                        activeSelection.Add(g);
                        updateSelectionObjects = true;
                    }
                    else
                    {
                        //TODO: add a rename overlay
                    }
                }
            }

            if (isInSelection)
            {
                EditorGUI.DrawRect(rect, SELECTION_COLOR);
            }

            if (g.hideFlags.HasFlag(HideFlags.NotEditable))
            {
                var icon  = EditorGUIUtility.IconContent("InspectorLock");
                var irect = rect;
                irect.width  = 16;
                irect.height = 14;
                GUI.DrawTexture(irect, icon.image);
            }
            rect.x          += 24;
            GUI.contentColor = allowRemove ? Color.white : Color.Lerp(Color.white, Color.yellow, 0.25f);
            GUI.Label(rect, content);
            GUI.contentColor = Color.white;

            if (isRightButton && isMouseOver && isMouseDown && isInSelection)
            {
                ShowGameObjectContextMenu(rect, group, g, allowRemove);
            }


            if (isMouseOver && isMouseDrag)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = Selection.objects;
                DragAndDrop.StartDrag(g.name);
            }

            if (updateSelectionObjects)
            {
                Selection.objects = activeSelection.ToArray();
            }
        }