Beispiel #1
0
        /// <summary> Opens menu to specify search type. </summary>
        /// <param name="position"> The position of the menu. </param>
        private void OpenFilteringMethodMenu(Rect position)
        {
                        #if DEV_MODE
            Debug.Log("OpenFilteringMethodMenu");
                        #endif

            var menu = Menu.Create();

            var currentFilteringMethod = inspector.State.filter.FilteringMethod;

            menu.Add("Any", SetFilteringMethodToAll, currentFilteringMethod == FilteringMethod.Any);
            menu.AddSeparator();
            menu.Add("Label", SetFilteringMethodToLabel, currentFilteringMethod == FilteringMethod.Label);
            menu.Add("Type", SetFilteringMethodToType, currentFilteringMethod == FilteringMethod.Type);
            menu.Add("Value", SetFilteringMethodToValue, currentFilteringMethod == FilteringMethod.Value);
            menu.AddSeparator();
            menu.Add("Class", SetFilteringMethodToClass, currentFilteringMethod == FilteringMethod.Class);
            menu.Add("Scene", SetFilteringMethodToScene, currentFilteringMethod == FilteringMethod.Scene);
            menu.Add("Asset", SetFilteringMethodToAsset, currentFilteringMethod == FilteringMethod.Asset);
            menu.Add("Window", SetFilteringMethodToWindow, currentFilteringMethod == FilteringMethod.Window);
            menu.Add("Icon", SetFilteringMethodToIcon, currentFilteringMethod == FilteringMethod.Icon);
            menu.AddSeparator();
            menu.Add("Help", OpenDocumentationPage);

            ContextMenuUtility.OpenAt(menu, position, true, inspector, InspectorPart.Toolbar, null, SearchBoxPart.Dropdown, OnFilteringMethodMenuClosed);
        }
Beispiel #2
0
        protected bool OpenContextMenu([NotNull] Event inputEvent, bool extendedMenu)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(inputEvent != null);
            Debug.Assert(!inputEvent.isMouse || !inspector.IgnoreToolbarMouseInputs());
                        #endif

            var menu = Menu.Create();
            BuildContextMenu(ref menu, extendedMenu);

                        #if DEV_MODE && UNITY_EDITOR
            if (extendedMenu)
            {
                AddDevModeDebuggingEntriesToRightClickMenu(ref menu);
            }
                        #endif

            if (menu.Count == 0)
            {
                menu.Dispose();
                return(false);
            }

            if (inputEvent.type != EventType.Used)
            {
                inputEvent.Use();
            }

            ContextMenuUtility.OpenAt(menu, Bounds, true, inspector, InspectorPart.Toolbar, null, this);
            return(true);
        }
Beispiel #3
0
        private void OnToggleSnapToGridIconRightClicked(IUnityObjectDrawer containingDrawer, Rect buttonRect, Event inputEvent)
        {
            var menu = Menu.Create();

            menu.Insert(0, "Edit Snap Settings...", () => DrawGUI.ExecuteMenuItem("Edit/Snap Settings..."));
            ContextMenuUtility.OpenAt(menu, buttonRect, this, (Part)TransformHeaderPart.ToggleSnapToGridButton);
        }
Beispiel #4
0
        private void ShowTextEditorPopupMenu(IInspector inspector)
        {
            var menu = Menu.Create();

            if (editor.hasSelection && !editor.isPasswordField)
            {
                menu.Add("Cut", () =>
                {
                    Clipboard.Copy(editor.SelectedText);
                    editor.DeleteSelection();
                });
                menu.Add("Copy", () => Clipboard.Copy(editor.SelectedText));
            }
            if (editor.CanPaste())
            {
                menu.Add("Paste", () => editor.Paste());
            }

            var searchBox = inspector.Toolbar.GetItemByType(typeof(ISearchBoxToolbarItem));

            if (searchBox != null && inspector.Manager.MouseoveredInspectorPart == InspectorPart.Toolbar || inspector.Manager.SelectedInspectorPart == InspectorPart.Toolbar)
            {
                ContextMenuUtility.Open(menu, true, inspector, InspectorPart.Toolbar, null, searchBox);
            }
            else
            {
                                #if DEV_MODE
                Debug.LogWarning("Filter.ShowTextEditorPopupMenu called but subject was not ISearchBoxToolbarItem on inspector toolbar. Calling ContextMenuUtility with a null subject.");
                                #endif

                ContextMenuUtility.Open(menu, null);
            }
        }
Beispiel #5
0
 /// <inheritdoc />
 public override bool OnRightClick(Event inputEvent)
 {
     if (MouseoveredHeaderPart == (HeaderPart)TransformHeaderPart.ToggleSnapToGridButton)
     {
         var menu = Menu.Create();
         menu.Insert(0, "Edit Snap Settings...", () => DrawGUI.ExecuteMenuItem("Edit/Snap Settings..."));
         ContextMenuUtility.OpenAt(menu, ToggleSnapToGridIconPosition, this, (Part)TransformHeaderPart.ToggleSnapToGridButton);
         return(true);
     }
     return(base.OnRightClick(inputEvent));
 }
        /// <summary> Opens execute method menu. </summary>
        public static void OpenExecuteMethodMenu([NotNull] IUnityObjectDrawer subject, Rect position, bool includeInvisible)
        {
            var menu = GenerateExecuteMethodMenu(subject.UnityObject, subject.Type, includeInvisible);

            if (menu.Count > 0)
            {
                ContextMenuUtility.OpenAt(menu, position, subject, Part.MethodInvokerButton);
            }
                        #if DEV_MODE
            else
            {
                Debug.LogWarning(subject + ".GenerateExecuteMethodMenu with type " + StringUtils.ToString(subject.Type) + " returned zero menu items");
            }
                        #endif
        }
Beispiel #7
0
        private void DisplayTargetSelectMenu()
        {
            var menu = Menu.Create();

            menu.Add("Clear", SetValueFromMenu, Color.clear);
            menu.Add("White", SetValueFromMenu, Color.white);
            menu.Add("Black", SetValueFromMenu, Color.black);
            menu.Add("Gray", SetValueFromMenu, Color.gray);
            menu.Add("Red", SetValueFromMenu, Color.red);
            menu.Add("Yellow", SetValueFromMenu, Color.yellow);
            menu.Add("Blue", SetValueFromMenu, Color.blue);
            menu.Add("Green", SetValueFromMenu, Color.green);
            menu.Add("Cyan", SetValueFromMenu, Color.cyan);
            menu.Add("Magenta", SetValueFromMenu, Color.magenta);

            ContextMenuUtility.Open(menu, this);
        }
        /// <inheritdoc />
        public sealed override bool DrawPrefix(Rect position)
        {
            bool dirty = base.DrawPrefix(position);

            if (DrawSnapIcon)
            {
                var snapButtonRect = SnappingIconPosition;
                var settings       = InspectorUtility.Preferences;
                var graphics       = settings.graphics;

                if (Event.current.type == EventType.Repaint)
                {
                    if (SnappingEnabled)
                    {
                        GUI.DrawTexture(snapButtonRect, graphics.SnappingOnIcon, ScaleMode.StretchToFill);
                    }
                    else
                    {
                        var guiColorWas = GUI.color;
                        var setGuiColor = guiColorWas;
                        setGuiColor.a = 0.5f;
                        GUI.color     = setGuiColor;
                        GUI.DrawTexture(snapButtonRect, graphics.SnappingOffIcon, ScaleMode.StretchToFill);
                        GUI.color = guiColorWas;
                    }
                }

                if (GUI.Button(snapButtonRect, GUIContent.none, DrawGUI.prefixLabel))
                {
                    if (Event.current.button == 0)
                    {
                        ToggleSnapping();
                        return(true);
                    }
                    if (Event.current.button == 1)
                    {
                        var menu = Menu.Create();
                        menu.Insert(0, "Edit Snap Settings...", () => DrawGUI.ExecuteMenuItem("Edit/Snap Settings..."));
                        ContextMenuUtility.OpenAt(menu, snapButtonRect, this, (Part)TransformHeaderPart.ToggleSnapToGridButton);
                        return(true);
                    }
                }
            }

            return(dirty);
        }
Beispiel #9
0
        /// <inheritdoc/>
        public override bool DrawPrefix(Rect position)
        {
            if (Event.current.type == EventType.Repaint)
            {
                //hide prefix resizer line behind the field
                DrawGUI.Active.ColorRect(lastDrawPosition, DrawGUI.Active.InspectorBackgroundColor);

                if (backgroundRect.width > 0f)
                {
                    GUI.Label(backgroundRect, "", InspectorPreferences.Styles.MethodBackground);
                }
            }

            bool drawBackgroundBehindFoldoutsWas = DrawGUI.drawBackgroundBehindFoldouts;

            DrawGUI.drawBackgroundBehindFoldouts = false;

            var prefixDrawRect      = PrefixLabelPosition;
            var clipLabelInsideRect = prefixDrawRect;

            clipLabelInsideRect.width += clipLabelInsideRect.x;
            clipLabelInsideRect.x      = 0f;
            prefixDrawRect.y           = 0f;

            //use BeginArea to prevent foldout text clipping past the Button
            GUILayout.BeginArea(clipLabelInsideRect);
            bool dirty = base.DrawPrefix(prefixDrawRect);

            GUILayout.EndArea();

            DrawGUI.drawBackgroundBehindFoldouts = drawBackgroundBehindFoldoutsWas;

            bool selected    = Selected;
            var  guiColorWas = GUI.color;

            bool isInvoking;

            if (isCoroutine && Application.isPlaying)
            {
                if (monoBehaviour != null)
                {
                    isInvoking = monoBehaviour.IsInvoking(memberInfo.MethodInfo.Name);
                }
                else
                {
                    isInvoking = StaticCoroutine.IsInvoking(memberInfo.MethodInfo.Name);
                }
            }
            else
            {
                isInvoking = false;
            }

            if (isInvoking)
            {
                GUI.color = Color.green;
            }
            else if (selected)
            {
                var col = preferences.theme.ButtonSelected;
                GUI.color = col;
            }

            if (GUI.Button(buttonRect, buttonLabel, Style))
            {
                DrawGUI.UseEvent();
                if (Event.current.button == 0)
                {
                    dirty = true;
                    Invoke();
                    Select(ReasonSelectionChanged.ControlClicked);
                }
                else if (Event.current.button == 1)
                {
                    var menu = Menu.Create();

                    menu.Add(Menu.Item("Invoke", () => Invoke(false, false, false, false)));

                    if (hasReturnValue)
                    {
                                                #if !POWER_INSPECTOR_LITE
                        menu.AddSeparator();
                        menu.Add(Menu.Item("Copy Return Value", () => Invoke(false, false, true, false)));
                                                #endif
                        if (UnityObjectExtensions.IsUnityObjectOrUnityObjectCollectionType(Type))
                        {
                            menu.Add(Menu.Item("Ping Return Value", () => Invoke(true, false, false, false)));
                            menu.Add(Menu.Item("Select Return Value", () => Invoke(false, false, false, true)));
                        }
                    }

                    if (isCoroutine)
                    {
                        menu.AddSeparator();

                        var    monoBehaviour = UnityObject as MonoBehaviour;
                        string methodName    = MethodInfo.Name;

                        if (monoBehaviour != null && Application.isPlaying)
                        {
                            menu.Add("Invoke Repeating/Every Second", () => monoBehaviour.InvokeRepeating(MethodInfo.Name, 1f, 1f));
                            menu.Add("Invoke Repeating/Every 5 Seconds", () => monoBehaviour.InvokeRepeating(MethodInfo.Name, 5f, 5f));
                            menu.Add("Invoke Repeating/Every 10 Seconds", () => monoBehaviour.InvokeRepeating(MethodInfo.Name, 10f, 10f));

                            if (monoBehaviour.IsInvoking(methodName))
                            {
                                menu.Add("Stop Coroutine", () => monoBehaviour.StopCoroutine(MethodInfo.Name));
                                menu.Add("Cancel Invoke", () => monoBehaviour.CancelInvoke(MethodInfo.Name));
                            }
                        }
                    }

                    ContextMenuUtility.Open(menu, this);
                }
                else if (Event.current.button == 2)
                {
                    Invoke(true, false, true, false);
                }
            }

            GUI.color = guiColorWas;

            return(dirty);
        }