public static AddComponentMenuDrawer CreateNewBackgroundInstance(IInspector setInspector, IGameObjectDrawer target)
        {
            var result = new AddComponentMenuDrawer();

            result.SetupWithoutOpening(setInspector, target);
            return(result);
        }
Beispiel #2
0
        private void QuickAddComponent(Type type)
        {
            var gameObjectDrawer = (IGameObjectDrawer)parent;
            var adder            = AddComponentMenuDrawer.CreateNewBackgroundInstance(inspector, gameObjectDrawer);

            adder.SetTarget(inspector, gameObjectDrawer);
            adder.AddComponent(type);
        }
 public static AddComponentMenuDrawer Create(IInspector setInspector, IGameObjectDrawer target, Rect openPosition, Action onClosed)
 {
     if (instance == null)
     {
         instance = new AddComponentMenuDrawer();
     }
     instance.Setup(setInspector, target, openPosition, onClosed);
     return(instance);
 }
Beispiel #4
0
        /// <summary>
        /// Setup the newly created instance.
        /// </summary>
        /// <param name="setInspector">  The inspector which contains the target. </param>
        /// <param name="target"> Target onto which components should be added Target onto which components should be added. </param>
        /// <param name="unrollPosition">The button position. </param>
        /// <param name="onClosed">
        /// This action is invoked
        /// when the editor window is
        /// closed. </param>
        private void Setup(IInspector setInspector, IGameObjectDrawer target, Rect unrollPosition, Action onClosed)
        {
            inspector = setInspector;
            var inspectorDrawer = inspector.InspectorDrawer;

            this.onClosed = onClosed;

            inspector.InspectorDrawer.Manager.IgnoreAllMouseInputs = true;

            var unrollPosScreenSpace = unrollPosition;

            //menu should open underneath the button
            unrollPosScreenSpace.y += unrollPosition.height - 1f;

            // add inspector y-axis position to open position
            // so that if this is a split view, the menu is opened
            // with the correct offset
            unrollPosScreenSpace.y += inspector.State.WindowRect.y;

            //TO DO: if it's off-screen, scroll to it!
            //if it's hidden via filter field, maybe clear the filter?
            //or maybe never hide it via the filter field?
            //or maybe disable the keyboard shortcut if it's hidden
            //even trigger it via the addcomponentmenu item?
            if (setInspector.IsOutsideViewport(unrollPosScreenSpace))
            {
                unrollPosScreenSpace.y = inspectorDrawer.position.y + inspectorDrawer.position.height - AddComponentMenuDrawer.TotalHeight;
            }
            else
            {
                unrollPosScreenSpace.y += inspectorDrawer.position.y - setInspector.State.ScrollPos.y + 20f;
            }

            var screenHeight = Screen.currentResolution.height;

            //if there's not enough screen estate to draw the menu below
            //the add component button then draw it above
            if (unrollPosScreenSpace.y + AddComponentMenuDrawer.TotalHeight > screenHeight)
            {
                unrollPosScreenSpace.y -= AddComponentMenuDrawer.TotalHeight + unrollPosition.height + 2f;
            }

            unrollPosScreenSpace.x = Mathf.CeilToInt(inspectorDrawer.position.x + setInspector.State.WindowRect.width * 0.5f - AddComponentMenuDrawer.Width * 0.5f);

            // if the inspector window is docked, the positions need to be adjusted somewhat to be accurate
            var inspectorWindow = setInspector.InspectorDrawer as EditorWindow;

            if (inspectorWindow != null)
            {
                if (inspectorWindow.IsDocked())
                {
                    unrollPosScreenSpace.x += 2f;
                    unrollPosScreenSpace.y -= 4f;
                }
            }

            if (drawer == null)
            {
                drawer = AddComponentMenuDrawer.Create(inspector, target, unrollPosition, Close);
            }
            else
            {
                drawer.Setup(inspector, target, unrollPosition, Close);
            }

            ShowAsDropDown(unrollPosScreenSpace, new Vector2(AddComponentMenuDrawer.Width, AddComponentMenuDrawer.TotalHeight));
        }