logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityMenuView

    Partial class for UnityMenuView containing navigation/submit haptic feedback. The feedback service is the single source of truth — this view only asks it to play a definition; the service owns enable/intensity scaling. The service is resolved lazily via ServiceLocatorBridge because it is registered during the initialization pipeline, possibly after this view exists. Menus target the acting pad (the player driving the menu just pressed Navigate/Submit, so it is the current device).

    Inheritance
    object
    UnityMenuView
    Implements
    IFocusableMenuView
    IHostableView
    Namespace: Serenity.Menu.Infrastructure.Views
    Assembly: Serenity.UnityMenu.Infrastructure.dll
    Syntax
    public class UnityMenuView : UnityUiView, IFocusableMenuView, IHostableView
    Remarks

    The composite mounts a menu by calling PrepareForHosting(UiAnchorType) (right after reparenting it under the slot) and releases it by calling ReleaseFromHosting() (before reparenting it back). Because a menu view is a shared singleton, hosting must be fully reversible: the first PrepareForHosting(UiAnchorType) snapshots the standalone rect state so ReleaseFromHosting() can restore it, leaving the menu usable on its own again rather than trapped under the composite.

    Constructors

    UnityMenuView()

    Declaration
    public UnityMenuView()

    Properties

    FocusableOptionCount

    Declaration
    public int FocusableOptionCount { get; }
    Property Value
    Type Description
    int

    HasCrossMenuHost

    Whether this menu is wired into a cross-menu host (so boundaries hand off to siblings).

    Declaration
    public bool HasCrossMenuHost { get; }
    Property Value
    Type Description
    bool

    HostView

    The top-level composite view that hosts this menu, or null when standalone.

    Declaration
    public IViewBase HostView { get; }
    Property Value
    Type Description
    IViewBase

    IsHosted

    True when this menu is embedded inside a composite layout rather than the canvas.

    Declaration
    public bool IsHosted { get; }
    Property Value
    Type Description
    bool

    IsInputActive

    Declaration
    public bool IsInputActive { get; }
    Property Value
    Type Description
    bool

    Methods

    BlurFocus()

    Declaration
    public void BlurFocus()

    CancelOption()

    Cancels the currently selected menu option if it supports cancellation.
    Checks if the selected option implements IUiCancellable interface and executes its cancel action.

    Declaration
    public void CancelOption()

    EnsureSelectedOptionVisible(int)

    Scrolls the options viewport just enough to keep the option at selectedOptionIndex fully visible. Called whenever the selection changes (including wrap-around between first and last option), so gamepad/keyboard navigation never focuses an option hidden by the clip mask. No-op when option scrolling is not active.

    Declaration
    public void EnsureSelectedOptionVisible(int selectedOptionIndex)
    Parameters
    Type Name Description
    int selectedOptionIndex

    Zero-based index of the newly selected option.

    ExecuteCancel()

    Executes a cancel action for the current menu context.
    Triggers the menu cancel use case with this view's identifier.

    Declaration
    public void ExecuteCancel()

    ExecuteChangeOptionValue(UiOptionValue, string)

    Executes a change option value action for the option that actually changed.
    Updates that option's value by triggering the change option value use case.

    Declaration
    public void ExecuteChangeOptionValue(UiOptionValue value, string optionId)
    Parameters
    Type Name Description
    UiOptionValue value

    New value to set for the changed option.

    string optionId

    Identifier of the option whose value changed. Must be the changed option, not the currently selected one: a value change can originate from a component that is not the selected option (e.g. clicking a slider before it gains selection), and targeting the selected option would alias the two options onto the same value instance.

    ExecuteGoBack()

    Executes a navigation back action to the previous view in the browser history.
    Uses the view browser service to go back and triggers a menu transition to the returned view.

    Declaration
    public void ExecuteGoBack()

    ExecuteHideMenu()

    Executes a hide action to make this menu invisible.
    Triggers the menu hide use case with this view's identifier.

    Declaration
    public void ExecuteHideMenu()

    ExecuteMenuAction(string)

    Executes a specific menu action by its identifier.
    Finds the action definition, creates the corresponding signal instance, and dispatches it through the event system.

    Declaration
    public void ExecuteMenuAction(string actionId)
    Parameters
    Type Name Description
    string actionId

    String identifier of the menu action to execute.

    ExecuteSelectOption(int)

    Executes a select option action for a specific option index.
    Triggers the menu select option use case with this view's identifier and the target option index.

    Declaration
    public void ExecuteSelectOption(int index)
    Parameters
    Type Name Description
    int index

    Zero-based index of the option to select.

    ExecuteShowMenu()

    Executes a show action to make this menu visible.
    Triggers the menu show use case with this view's identifier.

    Declaration
    public void ExecuteShowMenu()

    ExecuteTransitionateToView(string)

    Executes a transition to a specific menu view by its identifier.
    Triggers the menu transition use case and pushes the current view to the browser history stack.

    Declaration
    public void ExecuteTransitionateToView(string menuId)
    Parameters
    Type Name Description
    string menuId

    String identifier of the target menu to transition to.

    FocusOption(int)

    Declaration
    public void FocusOption(int index)
    Parameters
    Type Name Description
    int index

    GetDirection()

    Gets the axis along which this menu lays out its options.

    Declaration
    public MenuDirection GetDirection()
    Returns
    Type Description
    MenuDirection

    The menu layout direction.

    GetMenuArea()

    Retrieves the current menu area dimensions used for layout calculations and positioning operations.
    Returns the stored dimensions that define the total area occupied by the menu content.

    Declaration
    public Vector2 GetMenuArea()
    Returns
    Type Description
    Vector2

    Vector2 containing the width (x) and height (y) dimensions of the menu area in screen units.

    GetMenuUseCases()

    Retrieves the menu use cases handler that contains business logic for menu operations.
    Returns the use cases instance that manages menu interactions and workflows.

    Declaration
    public MenuUseCases GetMenuUseCases()
    Returns
    Type Description
    MenuUseCases

    MenuUseCases instance containing menu business logic operations.

    GetOptionComponents()

    Retrieves the cached array of UnityUiInteractableComponent references for menu options.
    Returns the cached component references that were populated when SetOptionsGameObjects was called.

    Declaration
    public UnityUiInteractableComponent[] GetOptionComponents()
    Returns
    Type Description
    UnityUiInteractableComponent[]

    Array of UnityUiInteractableComponent references, or empty array if not initialized.

    GetOptionsGameObjects()

    Retrieves the array of GameObjects representing menu options.
    Returns all option GameObjects or an empty array if none are set.

    Declaration
    public GameObject[] GetOptionsGameObjects()
    Returns
    Type Description
    GameObject[]

    Array of GameObjects containing menu options, or empty array if not initialized.

    GetOptionsScrollRect()

    Retrieves the ScrollRect scrolling the options wrapper, or null when this menu was built without scrolling.

    Declaration
    public ScrollRect GetOptionsScrollRect()
    Returns
    Type Description
    ScrollRect

    The options ScrollRect, or null.

    GetOptionsViewport()

    Retrieves the options viewport GameObject, or null when this menu was built without scrolling.

    Declaration
    public GameObject GetOptionsViewport()
    Returns
    Type Description
    GameObject

    The viewport GameObject that clips the options wrapper, or null.

    GetOptionsWrapper()

    Retrieves the GameObject wrapper that contains all menu option components.
    Returns the parent container GameObject that holds the menu's interactive UI elements.

    Declaration
    public GameObject GetOptionsWrapper()
    Returns
    Type Description
    GameObject

    GameObject that serves as the wrapper container for menu options.

    GetPreferredHostedHeight()

    Declaration
    public float GetPreferredHostedHeight()
    Returns
    Type Description
    float

    GetPreferredHostedWidth()

    Declaration
    public float GetPreferredHostedWidth()
    Returns
    Type Description
    float

    GetSelectedOption()

    Retrieves the currently selected menu option component.
    Returns the Unity UI interactable component that is currently focused, or null if index is out of range.

    Declaration
    public UnityUiInteractableComponent GetSelectedOption()
    Returns
    Type Description
    UnityUiInteractableComponent

    UnityUiInteractableComponent of the selected option, or null if not found.

    GetSelectedOptionIndex()

    Retrieves the index of the currently selected menu option.
    Returns the zero-based index representing which option is currently focused in the menu.

    Declaration
    public int GetSelectedOptionIndex()
    Returns
    Type Description
    int

    Zero-based index of the currently selected menu option.

    GetTitleAreaHeight()

    Retrieves the vertical space the title occupies above the options, including the title-to-options gap; zero when the menu has no title.

    Declaration
    public float GetTitleAreaHeight()
    Returns
    Type Description
    float

    The title block height in screen units.

    GetTitleGameObject()

    Retrieves the GameObject containing the menu title text component.

    Declaration
    public GameObject GetTitleGameObject()
    Returns
    Type Description
    GameObject

    HandleUnconsumedCancel()

    Handles a cancel input that no component consumed (no editing input, no open dropdown):
    dispatches this view's OnCancel signals and navigates back to the previous view.

    Declaration
    public void HandleUnconsumedCancel()
    Remarks

    Signals dispatch BEFORE navigating so they fire while this view is still the current one — ExecuteGoBack() triggers a transition that dispatches the destination's OnShow signals, and OnCancel must not interleave after those. With empty history the go-back is a no-op, so the signals still fire.

    HideHosted()

    Declaration
    public void HideHosted()

    Initialize(AudioPlayerPlayClip, string, IEventDispatcherService, MenuUseCases, UnityMenuViewModel, IGameSettingsService, IViewBrowserService, List<IFoundationActionDefinition>, IUiService)

    Declaration
    public void Initialize(AudioPlayerPlayClip audioPlayerPlayClip, string audioServiceId, IEventDispatcherService eventDispatcherService, MenuUseCases menuUseCases, UnityMenuViewModel viewModel, IGameSettingsService gameSettingsService, IViewBrowserService viewBrowserService, List<IFoundationActionDefinition> menuActionDefinitions, IUiService uiService)
    Parameters
    Type Name Description
    AudioPlayerPlayClip audioPlayerPlayClip
    string audioServiceId
    IEventDispatcherService eventDispatcherService
    MenuUseCases menuUseCases
    UnityMenuViewModel viewModel
    IGameSettingsService gameSettingsService
    IViewBrowserService viewBrowserService
    List<IFoundationActionDefinition> menuActionDefinitions
    IUiService uiService

    InvokeHorizontalRelayout()

    Re-runs the stored horizontal relayout, if any. No-op when none was registered.

    Declaration
    public void InvokeHorizontalRelayout()

    IsHorizontal()

    Whether this menu lays out its options horizontally (side by side).

    Declaration
    public bool IsHorizontal()
    Returns
    Type Description
    bool

    True when the direction is HORIZONTAL.

    IsOptionsScrollActive()

    Whether option scrolling is active (the options area is clamped and scrolls).

    Declaration
    public bool IsOptionsScrollActive()
    Returns
    Type Description
    bool

    True when the options area scrolls.

    OnDisable()

    Unity lifecycle method called when the component is disabled.
    Unsubscribes from locale change events and stops any running width adaptation coroutine.

    Declaration
    protected virtual void OnDisable()

    OnEnable()

    Unity lifecycle method called when the component is enabled.
    Subscribes to locale change events for real-time menu width adaptation.

    Declaration
    protected virtual void OnEnable()

    OnShow(bool)

    Handles the menu show/hide state changes and manages focus on the selected option.
    Implements "hide until ready" pattern: menu visuals are hidden during sizing, then revealed when complete.

    Declaration
    protected override void OnShow(bool isShowing)
    Parameters
    Type Name Description
    bool isShowing

    Boolean indicating whether the menu should be shown or hidden.

    PrepareForHosting(UiAnchorType)

    Declaration
    public void PrepareForHosting(UiAnchorType viewAlignment)
    Parameters
    Type Name Description
    UiAnchorType viewAlignment

    ReleaseFromHosting()

    Declaration
    public void ReleaseFromHosting()

    ResetOptionsScroll()

    Snaps the options scroll back to the start (the first option). No-op when not scrolling.

    Declaration
    public void ResetOptionsScroll()

    SelectNextOption()

    Selects the next available option in the menu navigation sequence.
    Delegates to the currently selected option's next component selection logic.

    Declaration
    public void SelectNextOption()

    SelectOptionById(string)

    Selects a specific menu option by its identifier.
    Delegates to the currently selected option's component selection logic using the provided ID.

    Declaration
    public void SelectOptionById(string optionId)
    Parameters
    Type Name Description
    string optionId

    String identifier of the option to select.

    SelectPreviousOption()

    Selects the previous available option in the menu navigation sequence.
    Delegates to the currently selected option's previous component selection logic.

    Declaration
    public void SelectPreviousOption()

    SetBackgroundGameObject(GameObject)

    Sets the GameObject containing the menu background image component.
    Configures the background image that provides visual context for the menu content.

    Declaration
    public void SetBackgroundGameObject(GameObject backgroundGameObject)
    Parameters
    Type Name Description
    GameObject backgroundGameObject

    SetCrossMenuHost(ICrossMenuHost, bool)

    Declaration
    public void SetCrossMenuHost(ICrossMenuHost host, bool wrapAround)
    Parameters
    Type Name Description
    ICrossMenuHost host
    bool wrapAround

    SetDirection(MenuDirection)

    Sets the axis along which this menu lays out its options. Stored so the input controller and the option scrolling can branch between the vertical and horizontal layout at runtime.

    Declaration
    public void SetDirection(MenuDirection direction)
    Parameters
    Type Name Description
    MenuDirection direction

    The menu layout direction.

    SetGameSettingsService(IGameSettingsService)

    Sets the game settings service used for accessing and managing game configuration values.
    Configures the service that provides default values and setting management for menu options.

    Declaration
    public void SetGameSettingsService(IGameSettingsService gameSettingsService)
    Parameters
    Type Name Description
    IGameSettingsService gameSettingsService

    Service instance for accessing game settings and default values.

    SetHorizontalRelayout(Action)

    Stores the callback that re-runs the horizontal row layout (option widths/positions, wrapper size, scroll clamp, menu footprint). A horizontal menu under AdaptMenuWidth sizes options to their content, which is only accurate after the show-time sizing pipeline has applied the font and decorations — so the layout is recomputed then via this callback rather than relying on the build-time measurement.

    Declaration
    public void SetHorizontalRelayout(Action relayout)
    Parameters
    Type Name Description
    Action relayout

    The relayout action supplied by the factory (captures menu settings/theme).

    SetHostView(IViewBase)

    Declaration
    public void SetHostView(IViewBase host)
    Parameters
    Type Name Description
    IViewBase host

    SetInputActive(bool)

    Declaration
    public void SetInputActive(bool active)
    Parameters
    Type Name Description
    bool active

    SetLifecycleSignals(IReadOnlyList<EventDispatcherSignal>, IReadOnlyList<EventDispatcherSignal>, IReadOnlyList<EventDispatcherSignal>)

    Sets the lifecycle signal collections dispatched when the menu transitions between shown and hidden states, and when a cancel input is not consumed by the selected option.

    Declaration
    public void SetLifecycleSignals(IReadOnlyList<EventDispatcherSignal> onShow, IReadOnlyList<EventDispatcherSignal> onHide, IReadOnlyList<EventDispatcherSignal> onCancel)
    Parameters
    Type Name Description
    IReadOnlyList<EventDispatcherSignal> onShow

    Signals to dispatch when the menu becomes visible.

    IReadOnlyList<EventDispatcherSignal> onHide

    Signals to dispatch when the menu becomes hidden.

    IReadOnlyList<EventDispatcherSignal> onCancel

    Signals to dispatch when the cancel input falls through unconsumed.

    SetMenuActionDefinitions(List<IFoundationActionDefinition>)

    Sets the menu action definitions that define available interactions and behaviors for this menu view.
    Configures the foundation action definitions that determine how user inputs are processed and handled.

    Declaration
    public void SetMenuActionDefinitions(List<IFoundationActionDefinition> menuActionDefinitions)
    Parameters
    Type Name Description
    List<IFoundationActionDefinition> menuActionDefinitions

    List of foundation action definitions containing input mapping and behavior configuration for menu interactions.

    SetMenuArea(Vector2)

    Sets the calculated menu area dimensions used for layout and positioning calculations.
    Defines the total area occupied by the menu content for alignment and spacing operations.

    Declaration
    public void SetMenuArea(Vector2 menuArea)
    Parameters
    Type Name Description
    Vector2 menuArea

    Vector2 containing width (x) and height (y) dimensions of the menu content area in screen units.

    SetOptionsGameObjects(GameObject[])

    Sets the array of GameObjects representing menu options.
    Configures the GameObjects that contain the interactive UI components for the menu.
    Also caches the UnityUiInteractableComponent references for efficient access.

    Declaration
    public void SetOptionsGameObjects(GameObject[] optionsGameObjects)
    Parameters
    Type Name Description
    GameObject[] optionsGameObjects

    Array of GameObjects containing menu options and their UI components.

    SetOptionsScrollActive(bool)

    Sets whether option scrolling is active: the options area is clamped to the configured visible rows and the remaining options scroll. Decided during menu area sizing via the scroll policy.

    Declaration
    public void SetOptionsScrollActive(bool isActive)
    Parameters
    Type Name Description
    bool isActive

    True when the menu has more options than fit the visible rows.

    SetOptionsScrollbar(Scrollbar)

    Stores the generated scrollbar overlaying the options viewport.

    Declaration
    public void SetOptionsScrollbar(Scrollbar optionsScrollbar)
    Parameters
    Type Name Description
    Scrollbar optionsScrollbar

    The scrollbar wired to the options ScrollRect.

    SetOptionsViewport(GameObject, ScrollRect)

    Stores the options viewport created for a scrollable menu and the ScrollRect driving it.

    Declaration
    public void SetOptionsViewport(GameObject optionsViewport, ScrollRect optionsScrollRect)
    Parameters
    Type Name Description
    GameObject optionsViewport

    The masked viewport GameObject between the menu root and the options wrapper.

    ScrollRect optionsScrollRect

    The ScrollRect on the viewport scrolling the options wrapper.

    SetOptionsWrapper(GameObject)

    Sets the GameObject wrapper that will contain all menu option components.
    Configures the parent container GameObject that will hold the menu's interactive UI elements.

    Declaration
    public void SetOptionsWrapper(GameObject optionsWrapper)
    Parameters
    Type Name Description
    GameObject optionsWrapper

    GameObject to serve as the wrapper container for menu options.

    SetTitle(string, UiAnchorType, float)

    Sets the title text of the menu.

    Declaration
    public void SetTitle(string title, UiAnchorType menuAlignment, float fontSize)
    Parameters
    Type Name Description
    string title

    The title text to set.

    UiAnchorType menuAlignment

    The alignment of the menu.

    float fontSize

    The font size of the title.

    SetTitleAreaHeight(float)

    Sets the vertical space the title occupies above the options (title height plus the title-to-options gap), or zero when the menu has no title. Stored so the menu can report its full footprint (title + options) when hosted inside a composite layout.

    Declaration
    public void SetTitleAreaHeight(float titleAreaHeight)
    Parameters
    Type Name Description
    float titleAreaHeight

    The title block height including the title gap, in screen units.

    SetTitleGameObject(GameObject)

    Sets the GameObject containing the menu title text component.
    Configures the title text element that displays the menu's main heading.

    Declaration
    public void SetTitleGameObject(GameObject titleGameObject)
    Parameters
    Type Name Description
    GameObject titleGameObject

    SetUseCases(MenuUseCases)

    Sets the menu use cases handler that contains business logic for menu operations.
    Configures the use cases instance that will manage menu interactions and workflows.

    Declaration
    public void SetUseCases(MenuUseCases menuUseCases)
    Parameters
    Type Name Description
    MenuUseCases menuUseCases

    MenuUseCases instance containing menu business logic operations.

    SetViewBrowserService(IViewBrowserService)

    Sets the view browser service used for navigation between different menu views and UI screens.
    Configures the service that manages view lifecycle and transition operations.

    Declaration
    public void SetViewBrowserService(IViewBrowserService viewBrowserService)
    Parameters
    Type Name Description
    IViewBrowserService viewBrowserService

    Service instance responsible for view navigation and management functionality.

    SetViewModel(UnityMenuViewModel)

    Sets the view model that provides data binding and state management for the menu view.
    Configures the Unity menu view model that handles reactive property updates and menu state synchronization.

    Declaration
    public void SetViewModel(UnityMenuViewModel viewModel)
    Parameters
    Type Name Description
    UnityMenuViewModel viewModel

    Unity menu view model instance containing reactive properties and state management logic.

    ShouldAutoFocusOnShow()

    Whether this menu should show its selection highlight when its show sequence completes. A menu in a cross-menu stack highlights only while it currently holds input; otherwise a non-focused sibling would re-highlight itself asynchronously and two menus would appear focused at once.

    Declaration
    public bool ShouldAutoFocusOnShow()
    Returns
    Type Description
    bool

    True to focus the selected option on show; false to leave it blurred.

    ShowHosted()

    Declaration
    public void ShowHosted()

    SubmitOption()

    Submits the currently selected menu option if it supports submission.
    Checks if the selected option implements IUiSubmittable interface and executes its submit action.

    Declaration
    public void SubmitOption()

    SubscribeToEventDispatcherEvents()

    Subscribes to event dispatcher events that affect menu behavior and state management.
    Registers event handlers for game settings reset operations, font size changes, and other system-wide notifications.

    Declaration
    public override void SubscribeToEventDispatcherEvents()

    TryCrossMenu(bool)

    Attempts to hand focus to the adjacent sibling menu when this menu is at a navigation boundary. Returns true when the cross-menu host took over the move (focus moved to a sibling, or stayed put in stop-at-ends mode) — in which case the caller must NOT also wrap within this menu.

    Declaration
    public bool TryCrossMenu(bool forward)
    Parameters
    Type Name Description
    bool forward

    True for downward/next, false for upward/previous.

    Returns
    Type Description
    bool

    True when cross-menu navigation owned this boundary; false to fall back to within-menu wrap.

    UpdateWidthFromContent()

    Recalculates the menu view width based on the widest child element (title, options, background, etc.).
    Sets this RectTransform horizontal size to match the widest element it contains.

    Declaration
    public void UpdateWidthFromContent()

    Events

    HostedSizeChanged

    Declaration
    public event Action HostedSizeChanged
    Event Type
    Type Description
    Action

    Implements

    IFocusableMenuView
    IHostableView
    In this article
    © 2026 Serenity. All Rights Reserved