/// <summary>
        /// Waits until the active inspector has finished rendering and then opens the menu.
        /// Delaying the opening of the menu like this can help avoid with some graphical glitches that can happen if the menu is opened in the middle of an inspector being drawn.
        /// </summary>
        /// <param name="menu"> Menu that should be opened. </param>
        /// <param name="disposeAfter"> Should the menu object be disposed after menu has been opened? Set this to false if the Menu is cached and reused, otherwise set this true. </param>
        /// <param name="inspector"> Inspector for which the context menu is being opened. Null if not opening for any inspector. </param>
        /// <param name="inspectorPart"> Part of the inspector for which the context menu is being opened. None if not opening for any inspector. </param>
        /// <param name="subject"> IDrawer for which the context menu is opened. Null if context menu doesn't belong to any IDrawer (e.g. toolbar menu item). </param>
        /// <param name="part"> Part of the subject for which the context menu is opened. E.g. reference to the targeted toolbar item. Can be null. </param>
        /// <param name="doOnMenuClosed"> Delegate to be called once menu has closed. Set to ContextMenuUtility.SelectLastContextMenuSubject to select the context menu subject once the context menu window has been closed. </param>
        public static void Open([NotNull] Menu menu, bool disposeAfter, [CanBeNull] IInspector inspector, InspectorPart inspectorPart, [CanBeNull] IDrawer subject, [CanBeNull] object part, Action <object> doOnMenuClosed = null)
        {
                        #if DEV_MODE
            Debug.Assert(menu.Count > 0);
            Debug.Assert(inspector != null || subject == null);
                        #endif

            openingMenu              = menu;
            openingMenuInspector     = inspector;
            openingMenuInspectorPart = inspectorPart;
            openingMenuSubject       = new DrawerTarget(subject);
            openingMenuPart          = part;
            openingMenuPosition      = null;
            disposeMenuAfterOpening  = disposeAfter;
            onMenuClosed             = doOnMenuClosed;

            if (IsSafeToChangeInspectorContents || inspector == null)
            {
                                #if DEV_MODE
                Debug.Log("Opening context menu immediately");
                                #endif
                OpenContextMenu();
            }
            else
            {
                openDelayCounter = 2;
            }
        }
        /// <summary>
        /// Waits until the active inspector has finished rendering and then opens the menu
        /// at the given position as a dropdown menu.
        /// Delaying the opening of the menu like this can help avoid with some graphical glitches that
        /// can happen if the menu is opened in the middle of an inspector being drawn
        /// </summary>
        /// <param name="menu"> Menu that should be opened. </param>
        /// <param name="position"> Position where menu should be opened. </param>
        /// <param name="disposeAfter">
        /// Should the menu object be disposed after menu has been opened?
        /// Set this to false if the Menu is cached and reused, otherwise set this true.
        /// </param>
        /// <param name="inspector"> Inspector for which the context menu is being opened. Null if not opening for any inspector. </param>
        /// <param name="inspectorPart"> Part of the inspector for which the context menu is being opened. None if not opening for any inspector. </param>
        /// <param name="subject"> IDrawer whose context menu is being opened. Null if context menu doesn't belong to any IDrawer (e.g. toolbar menu item). </param>
        /// <param name="part"> Can contain the part of the subject for which the context menu is opened. E.g. reference to the targeted toolbar item. </param>
        /// <param name="doOnMenuClosed"> Delegate to be called once menu has closed. Set to ContextMenuUtility.SelectLastContextMenuSubject to select the context menu subject once the context menu window has been closed. Can be null. </param>
        public static void OpenAt([NotNull] Menu menu, Rect position, bool disposeAfter, [CanBeNull] IInspector inspector, InspectorPart inspectorPart, [CanBeNull] IDrawer subject, [CanBeNull] object part, [CanBeNull] Action <object> doOnMenuClosed)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(menu != null);
            Debug.Assert(menu.Count > 0);
            Debug.Assert(position.x >= 0f);
            Debug.Assert(position.y >= 0f);
            Debug.Assert(position.x < Screen.currentResolution.width);
            Debug.Assert(position.y < Screen.currentResolution.height);
            if (subject != null)
            {
                Debug.Assert(inspector != null);
                Debug.Assert(inspector == subject.Inspector);
                Debug.Assert(inspectorPart == InspectorPart.Viewport);
            }
            Debug.Assert(inspectorPart != InspectorPart.None || inspector == null);
            Debug.Assert(inspectorPart == InspectorPart.None || inspector != null);
                        #endif

            openingMenu              = menu;
            openingMenuInspector     = inspector;
            openingMenuInspectorPart = inspectorPart;
            openingMenuSubject       = new DrawerTarget(subject);
            openingMenuPart          = part;
            disposeMenuAfterOpening  = disposeAfter;
            onMenuClosed             = doOnMenuClosed;

            var openAtLocalPoint  = position.position;
            var openAtScreenPoint = GUIUtility.GUIToScreenPoint(openAtLocalPoint);
            position.position   = openAtScreenPoint;
            openingMenuPosition = position;

            if (IsSafeToChangeInspectorContents || inspector == null)
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + position + " immediately.");
                                #endif
                OpenContextMenu();
            }
            else
            {
                                #if DEV_MODE && DEBUG_OPEN_MENU
                Debug.Log("Opening context menu @ " + position + " delayed... inspector.State.WindowRect.y=" + inspector.State.WindowRect.y + ", LocalDrawAreaOffset=" + DrawGUI.GetLocalDrawAreaOffset());
                                #endif

                openDelayCounter = 2;
                inspector.RefreshView();
            }
        }
 public DrawerDelayableTargetedAction(IDrawer targetDrawer, Action <IDrawer> delayedAction)
 {
     targetInstance = new DrawerTarget(targetDrawer);
     action         = delayedAction;
 }
Beispiel #4
0
 public bool Equals([CanBeNull] DrawerTarget test)
 {
     return(ReferenceEquals(test.drawer, drawer) && test.instanceId.Equals(instanceId));
 }