상속: IElementAdderMenu
예제 #1
0
        private void AddConcreteTypesToMenu(GenericElementAdderMenu menu, Type[] concreteTypes)
        {
            if (concreteTypes.Length == 0)
            {
                return;
            }

            if (!menu.IsEmpty)
            {
                menu.AddSeparator();
            }

            foreach (Type concreteType in concreteTypes)
            {
                GUIContent content = new GUIContent(_typeDisplayNameFormatter(concreteType));
                if (_elementAdder != null && _elementAdder.CanAddElement(concreteType))
                {
                    menu.AddItem(content, () => {
                        if (_elementAdder.CanAddElement(concreteType))
                        {
                            _elementAdder.AddElement(concreteType);
                        }
                    });
                }
                else
                {
                    menu.AddDisabledItem(content);
                }
            }
        }
예제 #2
0
        public IElementAdderMenu GetMenu()
        {
            GenericElementAdderMenu menu = new GenericElementAdderMenu();

            AddCommandsToMenu(menu, _customCommands);

            if (_contractType != null)
            {
                AddCommandsToMenu(menu, ElementAdderMeta.GetMenuCommands <TContext>(_contractType));
                AddConcreteTypesToMenu(menu, ElementAdderMeta.GetConcreteElementTypes(_contractType, _typeFilters.ToArray()));
            }

            return(menu);
        }
예제 #3
0
        private void AddCommandsToMenu(GenericElementAdderMenu menu, IList <IElementAdderMenuCommand <TContext> > commands)
        {
            if (commands.Count == 0)
            {
                return;
            }

            if (!menu.IsEmpty)
            {
                menu.AddSeparator();
            }

            foreach (var command in commands)
            {
                if (_elementAdder != null && command.CanExecute(_elementAdder))
                {
                    menu.AddItem(command.Content, () => command.Execute(_elementAdder));
                }
                else
                {
                    menu.AddDisabledItem(command.Content);
                }
            }
        }