Exemplo n.º 1
0
        static void DisableEditing(ISelectionGroup group)
        {
            var isLocked = false;

            foreach (var g in group.Members)
            {
                if (g.hideFlags.HasFlag(HideFlags.NotEditable))
                {
                    isLocked = true;
                }
            }
            if (isLocked)
            {
                foreach (var g in group.Members)
                {
                    g.hideFlags &= ~HideFlags.NotEditable;
                }
            }
            else
            {
                foreach (var g in group.Members)
                {
                    g.hideFlags |= HideFlags.NotEditable;
                }
            }
        }
        internal static void Open(ISelectionGroup group, SelectionGroupEditorWindow parentWindow)
        {
            var dialog = EditorWindow.GetWindow <SelectionGroupConfigurationDialog>();

            dialog.group             = group;
            dialog.parentWindow      = parentWindow;
            dialog.refreshQuery      = true;
            dialog.titleContent.text = $"Configure {group.Name}";
            dialog.ShowPopup();
            dialog.debugInformation = null;
        }
Exemplo n.º 3
0
 static void ToggleVisibility(ISelectionGroup group)
 {
     foreach (var g in group.Members)
     {
         var go = g as GameObject;
         if (go == null)
         {
             continue;
         }
         SceneVisibilityManager.instance.ToggleVisibility(go, false);
     }
 }
        public static void ExecuteQuery(ISelectionGroup group)
        {
            var executor = new GoQLExecutor();
            var code     = GoQL.Parser.Parse(group.Query, out GoQL.ParseResult parseResult);

            if (parseResult == GoQL.ParseResult.OK)
            {
                executor.Code = group.Query;
                var objects = executor.Execute();
                group.SetMembers(objects);
            }
        }
Exemplo n.º 5
0
 void OnDeleteSelectionGroup(ISelectionGroup group)
 {
     if (group is Unity.SelectionGroups.Runtime.SelectionGroup runtimeGroup)
     {
         toDestroy.Add(runtimeGroup.gameObject);
     }
     if (group is SelectionGroup editorGroup)
     {
         Undo.RegisterCompleteObjectUndo(this, "Delete Editor Selection Group");
         editorGroups.Remove(editorGroup);
     }
     EditorApplication.delayCall += Save;
 }
Exemplo n.º 6
0
        void RegisterUndo(ISelectionGroup @group, string msg)
        {
            if (group is SelectionGroups.Runtime.SelectionGroup runtimeGroup)
            {
                Undo.RegisterCompleteObjectUndo(runtimeGroup, msg);
                EditorUtility.SetDirty(runtimeGroup);
            }

            if (group is SelectionGroup editorGroup)
            {
                SelectionGroupPersistenceManager.RegisterUndo(msg);
            }
        }
Exemplo n.º 7
0
        private ISelectionGroup <RadioButton> GetDefaultGroup()
        {
            if (LogicalParent == null)
            {
                return(null);
            }

            ISelectionGroup <RadioButton> group = (ISelectionGroup <RadioButton>)LogicalParent.GetValue(SelectionGroupProperty);

            if (group == null)
            {
                group = new SelectionGroup <RadioButton>();
                LogicalParent.SetValue(SelectionGroupProperty, group);
            }

            return(group);
        }
        void ShowGroupContextMenu(Rect rect, string groupName, ISelectionGroup group)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Select All"), false, () =>
            {
                Selection.objects = activeSelectionGroup.Members.ToArray();
                UpdateActiveSelection();
            });
            menu.AddSeparator(string.Empty);
            menu.AddItem(new GUIContent("Clear Group"), false, () =>
            {
                group.Clear();
            });
            menu.AddItem(new GUIContent("Configure Group"), false, () => SelectionGroupConfigurationDialog.Open(group, this));
            if (!string.IsNullOrEmpty(group.Query))
            {
                menu.AddItem(new GUIContent("Update Query Results"), false, () => SelectionGroupManager.ExecuteQuery(group));
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Update Query Results"), false);
            }
            if (group.Scope == SelectionGroupDataLocation.Editor)
            {
                menu.AddItem(new GUIContent("Move to Scene"), false, () =>
                {
                    SelectionGroupManager.ChangeGroupScope(group, SelectionGroupDataLocation.Scene);
                });
            }
            else
            {
                menu.AddItem(new GUIContent("Move to Editor"), false, () =>
                {
                    SelectionGroupManager.ChangeGroupScope(group, SelectionGroupDataLocation.Editor);
                });
            }

            menu.AddItem(new GUIContent("Delete Group"), false, () =>
            {
                SelectionGroupManager.Delete(group);
            });
            menu.DropDown(rect);
        }
        void ShowGameObjectContextMenu(Rect rect, ISelectionGroup group, UnityEngine.Object g, bool allowRemove)
        {
            var menu    = new GenericMenu();
            var content = new GUIContent("Remove From Group");

            if (allowRemove)
            {
                menu.AddItem(content, false, () =>
                {
                    RegisterUndo(group, "Remove Member");
                    group.Query = "";
                    group.Remove(Selection.objects);
                });
            }
            else
            {
                menu.AddDisabledItem(content);
            }
            menu.DropDown(rect);
        }
        void DrawTools(float rightAlignedX, float y, ISelectionGroup group)
        {
            Assert.Greater(group.EnabledTools.Count, 0);
            const int TOOL_X_DIFF     = 18;
            const int TOOL_HEIGHT     = 18;
            int       numEnabledTools = group.EnabledTools.Count;

            Rect rect = new Rect(0, y, TOOL_X_DIFF, TOOL_HEIGHT);
            int  i    = 0;

            foreach (string toolId in group.EnabledTools)
            {
                SelectionGroupToolAttribute attr = null;
                MethodInfo methodInfo            = null;

                bool found = SelectionGroupToolAttributeCache.TryGetAttribute(toolId, out attr);
                Assert.IsTrue(found);
                found = SelectionGroupToolAttributeCache.TryGetMethodInfo(toolId, out methodInfo);
                Assert.IsTrue(found);

                GUIContent content = EditorGUIUtility.IconContent(attr.icon);
                content.tooltip = attr.description;

                rect.x = rightAlignedX - ((numEnabledTools - i) * TOOL_X_DIFF);
                if (GUI.Button(rect, content, miniButtonStyle))
                {
                    try
                    {
                        methodInfo.Invoke(null, new object[] { group });
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogException(e);
                    }
                }

                ++i;
            }
        }
        void HandleHeaderMouseEvents(Rect rect, string groupName, ISelectionGroup 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.Members.ToArray();
                    e.Use();
                    break;
                }
            }
        }
        Rect DrawAllGroupMembers(Rect rect, ISelectionGroup group, bool allowRemove)
        {
            rect.height = EditorGUIUtility.singleLineHeight;
            foreach (Object i in group.Members)
            {
                if (i == null)
                {
                    continue;
                }

                //if rect is below window, early out.
                if (rect.yMin - scroll.y > position.height)
                {
                    return(rect);
                }
                //if rect is in window, draw.
                if (rect.yMax - scroll.y > 0)
                {
                    DrawGroupMember(rect, group, i, allowRemove);
                }
                rect.y += rect.height;
            }
            return(rect);
        }
Exemplo n.º 13
0
 internal SelectionGroupDebugInformation(ISelectionGroup group)
 {
     text = EditorJsonUtility.ToJson(group, prettyPrint: true);
 }
        Rect DrawHeader(Rect cursor, ISelectionGroup group, out bool showChildren)
        {
            bool isPaint = Event.current.type == EventType.Repaint;
            Rect rect    = new Rect(cursor)
            {
                x = 0,
            };
            bool       isAvailableInEditMode = true;
            GUIContent content;

            if (group.Scope == SelectionGroupDataLocation.Editor)
            {
                content = editorHeaderContent;
            }
            else
            {
                content = sceneHeaderContent;
            }

            //Editor groups don't work in play mode, as GetGloBALoBJECTiD does not work in play mode.
            if (group.Scope == SelectionGroupDataLocation.Editor && EditorApplication.isPlayingOrWillChangePlaymode)
            {
                content.text          = $"{group.Name} (Not available in play mode)";
                isAvailableInEditMode = false;
            }
            else
            {
                content.text = $"{group.Name}";
            }

            //
            const float FOLDOUT_WIDTH    = 16;
            const float COLOR_WIDTH      = 128;
            const float SEPARATOR_WIDTH  = 8;
            float       currentViewWidth = EditorGUIUtility.currentViewWidth;

            //background
            Color backgroundColor = group == activeSelectionGroup ? Color.white * 0.6f : Color.white * 0.3f;

            if (isPaint)
            {
                rect.width = currentViewWidth - RightMargin - COLOR_WIDTH;
                EditorGUI.DrawRect(rect, backgroundColor);
            }

            //foldout and label
            float labelWidth = currentViewWidth
                               - (COLOR_WIDTH + FOLDOUT_WIDTH + RightMargin + SEPARATOR_WIDTH);

            {
                rect.width        = FOLDOUT_WIDTH;
                group.ShowMembers = EditorGUI.Toggle(rect, group.ShowMembers, EditorStyles.foldout);
                rect.x           += FOLDOUT_WIDTH;
                rect.width        = labelWidth;
            }
            if (isAvailableInEditMode)
            {
                HandleHeaderMouseEvents(rect, group.Name, group);
            }
            if (isPaint)
            {
                Label.normal.textColor = EditorGUIUtility.isProSkin ? ProTextColor: Color.black;
                GUI.Label(rect, content, Label);
            }

            rect.x += rect.width;

            if (group.EnabledTools.Count > 0)
            {
                DrawTools(rect.x, rect.y, group);
            }

            rect.x    += SEPARATOR_WIDTH;
            rect.width = COLOR_WIDTH;

            if (isPaint)
            {
                EditorGUI.DrawRect(rect, new Color(group.Color.r, group.Color.g, group.Color.b));
            }

            showChildren = isAvailableInEditMode ? group.ShowMembers : false;
            rect.x       = cursor.x;
            rect.y      += rect.height;
            rect.width   = cursor.width;
            return(rect);
        }
        void DrawGroupMember(Rect rect, ISelectionGroup group, UnityEngine.Object g, bool allowRemove)
        {
            Assert.IsNotNull(g);
            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;
            var isPaint                = e.type == EventType.Repaint;

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

            if (isLeftMouseDown)
            {
                hotMember            = g;
                activeSelectionGroup = group;
                e.Use();
            }

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

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

                if (g.hideFlags.HasFlag(HideFlags.NotEditable))
                {
                    var icon  = 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);
                e.Use();
            }

            if (updateSelectionObjects)
            {
                Selection.objects = activeSelection.ToArray();
            }
        }
Exemplo n.º 16
0
        bool HandleDragEvents(Rect rect, ISelectionGroup group)
        {
            Event evt = Event.current;

            if (!rect.Contains(evt.mousePosition))
            {
                return(false);
            }

            switch (evt.type)
            {
            case EventType.DragExited:
            case EventType.DragPerform:
            case EventType.DragUpdated:
            case EventType.MouseDrag:
                // Debug.Log($"{evt.type} {group.Name}");
                break;
            }

            switch (evt.type)
            {
            case EventType.MouseDrag:
                //This event occurs when dragging inside the EditorWindow which contains this OnGUI method.
                //It would be better named DragStarted.
                // Debug.Log($"Start Drag: {group.Name}");
                DragAndDrop.PrepareStartDrag();
                if (hotMember != null)
                {
                    DragAndDrop.objectReferences = new[] { hotMember }
                }
                ;
                else
                {
                    DragAndDrop.objectReferences = Selection.objects;
                }

                DragAndDrop.StartDrag("Selection Group");
                evt.Use();
                break;

            case EventType.DragExited:
                //This event occurs when MouseUp occurs, or the cursor leaves the EditorWindow.
                ////The cursor may come back into the EditorWindow, however MouseDrag will not be triggered.
                break;

            case EventType.DragUpdated:
                //This event can occur ay any time. VisualMode must be assigned a value other than Rejected, else
                //the DragPerform event will not be triggered.
                var canDrop = string.IsNullOrEmpty(group.Query);
                if (!canDrop || isReadOnly)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                evt.Use();
                break;

            case EventType.DragPerform:
                //This will only get called when a valid Drop occurs (determined by the above DragUpdated code)
                if (!isReadOnly)
                {
                    DragAndDrop.AcceptDrag();
                    RegisterUndo(group, "Add Members");
                    try
                    {
                        group.Add(DragAndDrop.objectReferences);
                    }
                    catch (SelectionGroupException e)
                    {
                        ShowNotification(new GUIContent(e.Message));
                    }
                    evt.Use();
                }

                break;
            }
            return(false);
        }
Exemplo n.º 17
0
 void RepaintOnDelete(ISelectionGroup @group) =>
 Repaint();
 public static void Register(ISelectionGroup @group)
 {
     Unregister(@group);
     groups.Add(group);
 }
 public static void Unregister(ISelectionGroup @group)
 {
     groups.Remove(group);
 }
 public static void ChangeGroupScope(ISelectionGroup @group, SelectionGroupDataLocation scope)
 {
     Create(scope, @group.Name, @group.Query, @group.Color, @group.Members);
     Delete(@group);
 }
 static void OnDelete(ISelectionGroup group)
 {
     Unregister(group);
 }
Exemplo n.º 22
0
 private void SetCurrentGroup()
 {
     CurrentGroup = !GroupName.IsNullOrEmpty() ? GetGroup(GroupName) : GetDefaultGroup();
 }
Exemplo n.º 23
0
 private void SetCurrentGroup()
 {
     CurrentGroup = !GroupName.IsNullOrEmpty() ? GetGroup(GroupName) : GetDefaultGroup();
 }