Пример #1
0
        public override void OnInspectorGUI()
        {
            var group = (ISelectionGroup)target;
            var scope = group.Scope;
            var query = group.Query;

            base.OnInspectorGUI();
            if (group.Query != query)
            {
                SelectionGroupManager.ExecuteQuery(group);
            }
            if (group.Scope != scope)
            {
                SelectionGroupManager.ChangeGroupScope(group, group.Scope);
            }
        }
        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 OnGUI()
        {
            if (group == null)
            {
                Close();
                return;
            }
            using (var cc = new EditorGUI.ChangeCheckScope())
            {
                GUILayout.Label("Selection Group Properties", EditorStyles.largeLabel);
                group.Name  = EditorGUILayout.TextField("Group Name", group.Name);
                group.Color = EditorGUILayout.ColorField("Color", group.Color);
                EditorGUILayout.LabelField("GameObject Query");
                var q = group.Query;
                group.Query  = EditorGUILayout.TextField(group.Query);
                refreshQuery = refreshQuery || (q != group.Query);
                if (refreshQuery)
                {
                    var code = GoQL.Parser.Parse(group.Query, out GoQL.ParseResult parseResult);
                    if (parseResult == GoQL.ParseResult.OK)
                    {
                        executor.Code = group.Query;
                        var objects = executor.Execute();
                        message = $"{objects.Length} results.";
                        @group.SetMembers(objects);
                        parentWindow.Repaint();
                    }
                    else
                    {
                        message = parseResult.ToString();
                    }
                    refreshQuery = false;
                }
                if (message != string.Empty)
                {
                    GUILayout.Space(5);
                    EditorGUILayout.HelpBox(message, MessageType.Info);
                }
                GUILayout.Space(5);
                var scope = @group.Scope;
                scope = (SelectionGroupDataLocation)EditorGUILayout.EnumPopup(@group.Scope);
                if (scope != @group.Scope)
                {
                    SelectionGroupManager.ChangeGroupScope(group, scope);
                    Close();
                }
                GUILayout.BeginVertical("box");
                GUILayout.Label("Enabled Toolbar Buttons", EditorStyles.largeLabel);
                foreach (var i in TypeCache.GetMethodsWithAttribute <SelectionGroupToolAttribute>())
                {
                    var attr     = i.GetCustomAttribute <SelectionGroupToolAttribute>();
                    var enabled  = group.EnabledTools.Contains(attr.toolId);
                    var content  = EditorGUIUtility.IconContent(attr.icon);
                    var _enabled = EditorGUILayout.ToggleLeft(content, enabled, "button");
                    if (enabled && !_enabled)
                    {
                        group.EnabledTools.Remove(attr.toolId);
                    }
                    if (!enabled && _enabled)
                    {
                        group.EnabledTools.Add(attr.toolId);
                    }
                }
                GUILayout.EndVertical();

                showDebug = GUILayout.Toggle(showDebug, "Show Debug Info", "button");
                if (showDebug)
                {
                    if (debugInformation == null)
                    {
                        debugInformation = new SelectionGroupDebugInformation(group);
                    }
                    EditorGUILayout.TextArea(debugInformation.text);
                }
                else
                {
                    debugInformation = null;
                }
            }
        }