Ejemplo n.º 1
0
        public static bool HasConflictingMembers(Type type, IGameObjectDrawer target)
        {
            if (type == null)
            {
                return(false);
            }

            Type[] conflictingTypes;
            if (!ConflictingTypes.TryGetValue(type, out conflictingTypes))
            {
                return(false);
            }

            foreach (var componentDrawer in target)
            {
                var memberType = componentDrawer.Type;
                for (int t = conflictingTypes.Length - 1; t >= 0; t--)
                {
                    var conflictingType = conflictingTypes[t];
                    if (conflictingType.IsAssignableFrom(memberType))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the Add Component Menu Window if it doesn't already exist.
        /// </summary>
        /// <param name="inspector">   The inspector which contains the target. </param>
        /// <param name="target">	   Target onto which components should be added. </param>
        /// <param name="unrollPosition">The position above or below which the window should open. </param>
        /// <param name="onClosed">	   This action is invoked when the editor window is closed. </param>
        public static void Create(IInspector inspector, IGameObjectDrawer target, Rect unrollPosition, Action onClosed)
        {
            if (instance != null)
            {
                return;
            }
            instance = CreateInstance <AddComponentMenuWindow>();

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(instance.IsVisible());
                        #endif

            try
            {
                instance.Setup(inspector, target, unrollPosition, onClosed);
            }
                        #if DEV_MODE
            catch (Exception e)
            {
                Debug.LogError(e);
                        #else
            catch
            {
                        #endif
                if (instance != null)
                {
                    Destroy(instance);
                }
                RestoreClickControls();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates the Add Component Menu Window if in editor mode.
 /// This is attached to the Add Component button being clicked.
 /// </summary>
 /// <param name="inspector"> The inspector which contains the target. </param>
 /// <param name="target"> Target onto which components should be added. </param>
 /// <param name="unrollPosition"> The position above or below which the window should open. </param>
 /// <param name="onClosed"> This action is invoked when the editor window is closed. </param>
 public static void CreateIfInEditorMode(IInspector inspector, IGameObjectDrawer target, Rect unrollPosition, Action onClosed)
 {
     if (Platform.EditorMode)
     {
         Create(inspector, target, unrollPosition, onClosed);
     }
 }
Ejemplo n.º 4
0
        public void Setup(IInspector setInspector, IGameObjectDrawer setTarget, Rect openPosition, Action setOnClosed)
        {
            onClosed = setOnClosed;
            SetTarget(setInspector, setTarget);

            Open(openPosition);
            setFilter = FilterString;
        }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="inspector"> Inspector that contains the drawers. </param>
        /// <returns> The drawer instance, ready to be used. </returns>
        public static AddComponentButtonDrawer Create([NotNull] IGameObjectDrawer parent, [NotNull] IInspector inspector)
        {
            AddComponentButtonDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new AddComponentButtonDrawer();
            }
            result.Setup(parent, null, inspector);
            result.LateSetup();
            return(result);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets list of existing components drawers on GameObject drawer that prevent component of given type from being added to the target gameobject(s).
 /// </summary>
 /// <param name="type"> Component type to check. </param>
 /// <param name="target"> GameObject drawer. </param>
 /// <param name="conflictingMembers"> Any found conflicting drawers will be added to this list </param>
 public static void GetConflictingMembers(Type type, IGameObjectDrawer target, [NotNull] ref List <IComponentDrawer> conflictingMembers)
 {
     Type[] conflictingTypes;
     if (ConflictingTypes.TryGetValue(type, out conflictingTypes))
     {
         foreach (var componentDrawer in target)
         {
             var memberType = componentDrawer.Type;
             for (int t = conflictingTypes.Length - 1; t >= 0; t--)
             {
                 var conflictingType = conflictingTypes[t];
                 if (conflictingType.IsAssignableFrom(memberType))
                 {
                     conflictingMembers.Add(componentDrawer);
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 public void SetTarget(IInspector setInspector, IGameObjectDrawer value)
 {
     target    = value;
     inspector = setInspector;
     RebuildIntructionsInChildren();
 }
Ejemplo n.º 9
0
 public void SetupWithoutOpening(IInspector setInspector, IGameObjectDrawer setTarget)
 {
     SetTarget(setInspector, setTarget);
     setFilter = "";
 }
Ejemplo n.º 10
0
        public static AddComponentMenuDrawer CreateNewBackgroundInstance(IInspector setInspector, IGameObjectDrawer target)
        {
            var result = new AddComponentMenuDrawer();

            result.SetupWithoutOpening(setInspector, target);
            return(result);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Sets up the drawer so that it is ready to be used.
 /// LateSetup should be called right after this.
 /// </summary>
 /// <param name="setParent"> Drawer whose member these Drawer are. Can be null. </param>
 /// <param name="setLabel"> The label (name) of the field. Can be null. </param>
 /// <param name="setInspector"> Inspector that contains the drawers. </param>
 private void Setup([NotNull] IGameObjectDrawer setParent, [CanBeNull] GUIContent setLabel, IInspector setInspector)
 {
     open      = false;
     inspector = setInspector;
     base.Setup(setParent, setLabel != null ? setLabel : GUIContentPool.Create("Add Component"));
 }
Ejemplo n.º 12
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));
        }