void SetupButtonOrderThenSelectTool(IToolsMenuButton toolsMenuButton, bool selectAfterSettingButtonOrder = true) { var mainMenu = IsMainMenuButton(toolsMenuButton); if (mainMenu) { mainMenuActivatorSelected(rayOrigin); return; } var showMenuButton = !aboveMinimumButtonCount; Reinsert(toolsMenuButton, k_ActiveToolOrderPosition); this.RestartCoroutine(ref m_ShowHideAllButtonsCoroutine, ShowThenHideAllButtons(1f, showMenuButton)); if (selectAfterSettingButtonOrder && buttonSelected != null) { bool existingButton = m_OrderedButtons.Any((x) => x.toolType == toolsMenuButton.toolType); if (existingButton) { buttonSelected(rayOrigin, toolsMenuButton.toolType); // Select the tool in the Tools Menu } } }
/// <summary> /// Delete a highlighted button, then select the next active tool button /// </summary> /// <returns>Bool denoting that a highlighted button other than the selection tool button was deleted</returns> public bool DeleteHighlightedButton() { IToolsMenuButton button = null; for (int i = 0; i < m_OrderedButtons.Count; ++i) { button = m_OrderedButtons[i]; if ((button.highlighted || button.secondaryButtonHighlighted) && !IsSelectionToolButton(button)) { break; } button = null; } if (button != null) { m_OrderedButtons.Remove(button); button.destroy(); button = m_OrderedButtons[k_ActiveToolOrderPosition]; // Assign next ordered button if (buttonSelected != null) { buttonSelected(rayOrigin, button.toolType); // Select the new active tool button } } if (!aboveMinimumButtonCount && closeMenu != null) { closeMenu(); // Close the menu if below the minimum button count (only MainMenu & SelectionTool are active) } return(button != null); }
void ShowAllButtons(IToolsMenuButton button) { m_RayHovered = true; if (!allButtonsVisible && aboveMinimumButtonCount && !IsMainMenuButton(button) && m_ButtonHoverExitDelayCoroutine == null) { allButtonsVisible = true; } }
void Reinsert(IToolsMenuButton button, int newOrderPosition, bool updateButtonOrder = false) { var removed = m_OrderedButtons.Remove(button); if (!removed) { return; } m_OrderedButtons.Insert(newOrderPosition, button); if (updateButtonOrder) { button.order = newOrderPosition; } }
public void AddButton(IToolsMenuButton button, Transform buttonTransform) { button.interactable = true; button.showAllButtons = ShowAllButtons; button.hoverExit = ButtonHoverExitPerformed; button.maxButtonCount = maxButtonCount; button.selectTool = SelectExistingToolTypeFromButton; button.closeButton = DeleteHighlightedButton; button.visibleButtonCount = VisibleButtonCount; // allow buttons to fetch local buttonCount button.iconHighlightedLocalZOffset = k_RaySelectIconHighlightedZOffset; button.tooltipTarget = m_ButtonTooltipTarget; button.hovered += OnButtonHover; button.stencilRef = stencilRef; bool allowSecondaryButton = false; // Secondary button is the close button var insertPosition = k_MenuButtonOrderPosition; if (!IsMainMenuButton(button)) { insertPosition = k_ActiveToolOrderPosition; allowSecondaryButton = !IsSelectionToolButton(button); } var initializingButtons = m_OrderedButtons.Count == 1; m_OrderedButtons.Insert(insertPosition, button); // If only the MainMenu & SelectionTool buttons exist, set visible button count to 1 m_VisibleButtonCount = aboveMinimumButtonCount || initializingButtons ? m_OrderedButtons.Count : 1; button.implementsSecondaryButton = allowSecondaryButton; button.isActiveTool = true; button.order = insertPosition; buttonTransform.rotation = Quaternion.identity; buttonTransform.localPosition = Vector3.zero; buttonTransform.localScale = Vector3.zero; if (aboveMinimumButtonCount) // aboveMinimumCount will change throughout function, don't cache for re-use { this.RestartCoroutine(ref m_ShowHideAllButtonsCoroutine, ShowThenHideAllButtons(1.25f, false)); } else { SetupButtonOrder(); // Setup the MainMenu and active tool buttons only } }
/// <summary> /// Delete a highlighted button, then select the next active tool button /// </summary> /// <returns>Bool denoting that a highlighted button other than the selection tool button was deleted</returns> public bool DeleteHighlightedButton() { IToolsMenuButton button = null; for (int i = 0; i < m_OrderedButtons.Count; ++i) { button = m_OrderedButtons[i]; if ((button.highlighted || button.secondaryButtonHighlighted) && !IsSelectionToolButton(button)) { break; } button = null; } if (button != null) { m_OrderedButtons.Remove(button); button.destroy(); // Return to the selection tool, as the active tool, when closing a tool via the secondary close button on a ToolsMenuButton for (int i = 0; i < m_OrderedButtons.Count; ++i) { if (IsSelectionToolButton(m_OrderedButtons[i])) { button = m_OrderedButtons[i]; break; } } if (buttonSelected != null) { buttonSelected(rayOrigin, button.toolType); // Select the new active tool button } } if (!aboveMinimumButtonCount && closeMenu != null) { closeMenu(); // Close the menu if below the minimum button count (only MainMenu & SelectionTool are active) } return(button != null); }
static bool IsSelectionToolButton(IToolsMenuButton button) { return(button.toolType == typeof(SelectionTool)); }
static bool IsMainMenuButton(IToolsMenuButton button) { return(button.toolType == typeof(IMainMenu)); }