Example #1
0
        public void AddSettingsMenu(ISettingsMenuProvider provider)
        {
            var type = provider.GetType();
            var customMenuAttribute = (MainMenuItemAttribute)type.GetCustomAttributes(typeof(MainMenuItemAttribute), false).FirstOrDefault();

            ITooltip tooltip = null;

            MainMenuUI.ButtonData buttonData;
            if (customMenuAttribute != null && customMenuAttribute.shown)
            {
                tooltip = customMenuAttribute.tooltip;

                buttonData = new MainMenuUI.ButtonData(customMenuAttribute.name)
                {
                    sectionName = customMenuAttribute.sectionName,
                    description = customMenuAttribute.description
                };
            }
            else
            {
                buttonData = new MainMenuUI.ButtonData(type.Name);
            }

            AddSettingsMenu(provider, buttonData, tooltip);
        }
Example #2
0
        void AddSettingsMenu(ISettingsMenuProvider provider, MainMenuUI.ButtonData buttonData, ITooltip tooltip)
        {
            buttonData.sectionName = k_SettingsMenuSectionName;

            var button = CreateFaceButton(buttonData, tooltip, () =>
            {
                var instance = m_MainMenuUI.AddSubmenu(k_SettingsMenuSectionName, provider.settingsMenuPrefab);
                m_SettingsMenus[provider]     = instance;
                provider.settingsMenuInstance = instance;
                AddToggleHaptics(instance);
            });

            button.hovered += OnButtonHovered;
            button.clicked += OnButtonClicked;
        }
Example #3
0
        void CreateFaceButtons()
        {
            var types = new HashSet <Type>();

            types.UnionWith(menuTools);
            types.UnionWith(menuWorkspaces);
            types.UnionWith(settingsMenuProviders.Keys.Select(provider => provider.Item1));
            types.UnionWith(settingsMenuItemProviders.Keys.Select(provider => provider.Item1));

            if (Application.isPlaying)
            {
                types.RemoveWhere(type => type.GetCustomAttributes(true).OfType <EditorOnlyWorkspaceAttribute>().Any());
            }

            foreach (var type in types)
            {
                var customMenuAttribute = (MainMenuItemAttribute)type.GetCustomAttributes(typeof(MainMenuItemAttribute), false).FirstOrDefault();
                if (customMenuAttribute != null && !customMenuAttribute.shown)
                {
                    continue;
                }

                var isTool                 = typeof(ITool).IsAssignableFrom(type) && menuTools.Contains(type);
                var isWorkspace            = typeof(Workspace).IsAssignableFrom(type);
                var isSettingsProvider     = typeof(ISettingsMenuProvider).IsAssignableFrom(type);
                var isSettingsItemProvider = typeof(ISettingsMenuItemProvider).IsAssignableFrom(type);

                ITooltip tooltip = null;
                MainMenuUI.ButtonData buttonData = null;

                var selectedType = type; // Local variable for closure
                if (customMenuAttribute != null && customMenuAttribute.shown)
                {
                    tooltip = customMenuAttribute.tooltip;

                    buttonData = new MainMenuUI.ButtonData(customMenuAttribute.name)
                    {
                        sectionName = customMenuAttribute.sectionName,
                        description = customMenuAttribute.description
                    };
                }

                if (isTool)
                {
                    if (buttonData == null)
                    {
                        buttonData = new MainMenuUI.ButtonData(type.Name);
                    }

                    var mainMenuButton = CreateFaceButton(buttonData, tooltip, () =>
                    {
                        if (targetRayOrigin)
                        {
                            this.SelectTool(targetRayOrigin, selectedType,
                                            hideMenu: typeof(IUsesInstantiateMenuUI).IsAssignableFrom(selectedType));
                            UpdateToolButtons();
                        }
                    });

                    m_ToolButtons[type] = mainMenuButton;

                    // Assign Tools Menu button preview properties
                    if (mainMenuButton != null)
                    {
                        mainMenuButton.toolType = selectedType;
                    }

                    m_ToolsSpatialMenuElements.Add(new SpatialMenu.SpatialMenuElementContainer(buttonData.name, buttonData.description, node =>
                    {
                        this.SelectTool(this.RequestRayOriginFromNode(node), selectedType,
                                        hideMenu: typeof(IUsesInstantiateMenuUI).IsAssignableFrom(selectedType));
                    }));

                    UpdateToolButtons();
                }

                if (isWorkspace)
                {
                    // For workspaces that haven't specified a custom attribute, do some menu categorization automatically
                    if (buttonData == null)
                    {
                        buttonData = new MainMenuUI.ButtonData(type.Name)
                        {
                            sectionName = "Workspaces"
                        }
                    }
                    ;

                    CreateFaceButton(buttonData, tooltip, () => { this.CreateWorkspace(selectedType); });

                    m_WorkspaceSpatialMenuElements.Add(new SpatialMenu.SpatialMenuElementContainer(buttonData.name, buttonData.description, node => this.CreateWorkspace(selectedType)));
                }

                if (isSettingsProvider)
                {
                    foreach (var providerPair in settingsMenuProviders)
                    {
                        var tuple = providerPair.Key;
                        if (tuple.Item1 == type && (tuple.Item2 == null || tuple.Item2 == rayOrigin))
                        {
                            AddSettingsMenu(providerPair.Value, buttonData, tooltip);
                        }
                    }
                }

                if (isSettingsItemProvider)
                {
                    foreach (var providerPair in settingsMenuItemProviders)
                    {
                        var kvp = providerPair.Key;
                        if (kvp.Item1 == type && (kvp.Item2 == null || kvp.Item2 == rayOrigin))
                        {
                            AddSettingsMenuItem(providerPair.Value);
                        }
                    }
                }
            }
        }

        MainMenuButton CreateFaceButton(MainMenuUI.ButtonData buttonData, ITooltip tooltip, Action buttonClickCallback)
        {
            var mainMenuButton = m_MainMenuUI.CreateFaceButton(buttonData);

            if (mainMenuButton == null)
            {
                return(null);
            }

            var button = mainMenuButton.button;

            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() =>
            {
                if (m_MenuHideFlags == 0)
                {
                    buttonClickCallback();
                }
            });

            mainMenuButton.hovered += OnButtonHovered;
            mainMenuButton.clicked += OnButtonClicked;
            mainMenuButton.tooltip  = tooltip;

            return(mainMenuButton);
        }

        void UpdateToolButtons()
        {
            foreach (var kvp in m_ToolButtons)
            {
                kvp.Value.selected = this.IsToolActive(targetRayOrigin, kvp.Key);
            }
        }

        void OnButtonClicked(Transform rayOrigin)
        {
            this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonClickPulse);
            this.ClearToolsMenuButtonPreview();
        }

        void OnButtonHovered(Transform rayOrigin, Type buttonType, string buttonDescription)
        {
            this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonHoverPulse);

            // Pass the pointer which is over us, so this information can supply context (e.g. selecting a tool for a different hand)
            // Enable preview-mode on a Tools Menu button; Display on the opposite proxy device by evaluating the entering RayOrigin
            // Disable any existing previews being displayed in ToolsMenus
            this.ClearToolsMenuButtonPreview();

            if (buttonType != null && rayOrigin != null)
            {
                this.PreviewInToolsMenuButton(rayOrigin, buttonType, buttonDescription);
            }
        }

        void OnToggleHovered(Transform rayOrigin)
        {
            this.Pulse(this.RequestNodeFromRayOrigin(rayOrigin), m_ButtonHoverPulse);
        }

        void SendVisibilityPulse()
        {
            this.Pulse(node, m_MenuHideFlags == 0 ? m_HidePulse : m_ShowPulse);
        }