Beispiel #1
0
        void SpawnActions()
        {
            IEnumerable <Type> actionTypes = ObjectUtils.GetImplementationsOfInterface(typeof(IAction));

            foreach (Type actionType in actionTypes)
            {
                // Don't treat vanilla actions or tool actions as first class actions
                if (actionType.IsNested || !typeof(MonoBehaviour).IsAssignableFrom(actionType))
                {
                    continue;
                }

                var action    = ObjectUtils.AddComponent(actionType, gameObject) as IAction;
                var attribute = (ActionMenuItemAttribute)actionType.GetCustomAttributes(typeof(ActionMenuItemAttribute), false).FirstOrDefault();

                this.ConnectInterfaces(action);

                if (attribute != null)
                {
                    var actionMenuData = new ActionMenuData()
                    {
                        name        = attribute.name,
                        sectionName = attribute.sectionName,
                        priority    = attribute.priority,
                        action      = action,
                    };

                    m_MenuActions.Add(actionMenuData);
                }

                m_Actions.Add(action);
            }

            m_MenuActions.Sort((x, y) => y.priority.CompareTo(x.priority));
        }
Beispiel #2
0
        void SpawnActions()
        {
            m_SpatialMenuData.Clear();
            var spatialMenuActions = new List <SpatialMenu.SpatialMenuElementContainer>();
            var spatialMenuData    = new SpatialMenu.SpatialMenuData("Actions", "Perform actions on selected object", spatialMenuActions);

            m_SpatialMenuData.Add(spatialMenuData);

            m_MenuActions.Clear();
            var actionTypes = CollectionPool <List <Type>, Type> .GetCollection();

            typeof(IAction).GetImplementationsOfInterface(actionTypes);
            foreach (var actionType in actionTypes)
            {
                // Don't treat vanilla actions or tool actions as first class actions
                if (actionType.IsNested || !typeof(MonoBehaviour).IsAssignableFrom(actionType))
                {
                    continue;
                }

                var action = EditorXRUtils.AddComponent(actionType, gameObject) as IAction;
                this.ConnectInterfaces(action);
                this.InjectFunctionalitySingle(action);

                var defaultActionAttribute = (ActionMenuItemAttribute)actionType.GetCustomAttributes(typeof(ActionMenuItemAttribute), false).FirstOrDefault();
                if (defaultActionAttribute != null)
                {
                    var actionMenuData = new ActionMenuData()
                    {
                        name        = defaultActionAttribute.name,
                        sectionName = defaultActionAttribute.sectionName,
                        priority    = defaultActionAttribute.priority,
                        action      = action,
                    };

                    m_MenuActions.Add(actionMenuData);
                }

                var spatialMenuAttribute = (SpatialMenuItemAttribute)actionType.GetCustomAttributes(typeof(SpatialMenuItemAttribute), false).FirstOrDefault();
                if (spatialMenuAttribute != null)
                {
                    spatialMenuActions.Add(new SpatialMenu.SpatialMenuElementContainer(spatialMenuAttribute.name, spatialMenuAttribute.description, (node) => action.ExecuteAction()));
                }

                m_Actions.Add(action);
            }

            CollectionPool <List <Type>, Type> .RecycleCollection(actionTypes);

            m_MenuActions.Sort((x, y) => y.priority.CompareTo(x.priority));
        }
            public void ConnectInterface(object target, object userData = null)
            {
                var actionsModule = evr.GetModule <ActionsModule>();

                if (actionsModule)
                {
                    var menuActions = actionsModule.menuActions;

                    var toolActions = target as IActions;
                    if (toolActions != null)
                    {
                        // Delay connecting actions to allow tool / module to initialize first
                        EditorApplication.delayCall += () =>
                        {
                            var actions = toolActions.actions;
                            if (actions != null)
                            {
                                foreach (var action in actions)
                                {
                                    var actionMenuData = new ActionMenuData()
                                    {
                                        name        = action.GetType().Name,
                                        sectionName = ActionMenuItemAttribute.DefaultActionSectionName,
                                        priority    = int.MaxValue,
                                        action      = action,
                                    };
                                    menuActions.Add(actionMenuData);
                                }

                                actionsModule.UpdateAlternateMenuActions();
                            }
                        };
                    }

                    var actionsMenu = target as IActionsMenu;
                    if (actionsMenu != null)
                    {
                        actionsMenu.menuActions = menuActions;
                        actionsModule.AddActionsMenu(actionsMenu);
                    }
                }
            }