Class UnityMenuView
Lets a menu be embedded ("hosted") inside a composite (UnityCompositeUiView) layout instead of
anchoring itself on the canvas. A standalone menu positions and sizes its own root relative to the
canvas; when hosted, the parent layout container drives that rect and the menu anchors its content
within the given slot according to the host's chosen UiAnchorType.
Namespace: Serenity.Menu.Infrastructure.Views
Assembly: Serenity.UnityMenu.Infrastructure.dll
Syntax
public class UnityMenuView : UnityUiView, IHostableView, IFocusableMenuView
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
ArmVisibilitySounds()
Enables show/hide sound playback for subsequent visibility changes.
Construction-time visibility churn (initial hide, sizing passes) happens before this is called,
so boot stays silent; only visibility changes after arming play a sound.
Declaration
public void ArmVisibilitySounds()
BlurFocus()
Declaration
public void BlurFocus()
CancelOption()
Declaration
public void CancelOption()
EnsureSelectedOptionVisible(int)
Declaration
public void EnsureSelectedOptionVisible(int selectedOptionIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | selectedOptionIndex |
ExecuteCancel()
Declaration
public void ExecuteCancel()
ExecuteChangeOptionValue(UiOptionValue, string)
Declaration
public void ExecuteChangeOptionValue(UiOptionValue value, string optionId)
Parameters
| Type | Name | Description |
|---|---|---|
| UiOptionValue | value | |
| string | optionId |
ExecuteGoBack()
Declaration
public void ExecuteGoBack()
ExecuteHideMenu()
Declaration
public void ExecuteHideMenu()
ExecuteMenuAction(string)
Declaration
public void ExecuteMenuAction(string actionId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actionId |
ExecuteSelectOption(int)
Declaration
public void ExecuteSelectOption(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index |
ExecuteShowMenu()
Declaration
public void ExecuteShowMenu()
ExecuteTransitionateToView(string)
Declaration
public void ExecuteTransitionateToView(string menuId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | menuId |
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()
Declaration
public ScrollRect GetOptionsScrollRect()
Returns
| Type | Description |
|---|---|
| ScrollRect |
GetOptionsViewport()
Declaration
public GameObject GetOptionsViewport()
Returns
| Type | Description |
|---|---|
| GameObject |
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()
Declaration
public void HandleUnconsumedCancel()
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()
Declaration
public bool IsOptionsScrollActive()
Returns
| Type | Description |
|---|---|
| bool |
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. |
Remarks
Stays on the component itself rather than moving to Serenity.Menu.Infrastructure.Views.MenuVisibilityPresenter: it overrides UnityUiView's virtual and starts the sizing coroutine, both of which only the MonoBehaviour can do.
PrepareForHosting(UiAnchorType)
Declaration
public void PrepareForHosting(UiAnchorType viewAlignment)
Parameters
| Type | Name | Description |
|---|---|---|
| UiAnchorType | viewAlignment |
ReleaseFromHosting()
Declaration
public void ReleaseFromHosting()
ResetOptionsScroll()
Declaration
public void ResetOptionsScroll()
SelectNextOption()
Declaration
public void SelectNextOption()
SelectOptionById(string)
Declaration
public void SelectOptionById(string optionId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | optionId |
SelectPreviousOption()
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)
Declaration
public void SetOptionsScrollActive(bool isActive)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isActive |
SetOptionsScrollbar(Scrollbar)
Declaration
public void SetOptionsScrollbar(Scrollbar optionsScrollbar)
Parameters
| Type | Name | Description |
|---|---|---|
| Scrollbar | optionsScrollbar |
SetOptionsViewport(GameObject, ScrollRect)
Declaration
public void SetOptionsViewport(GameObject optionsViewport, ScrollRect optionsScrollRect)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | optionsViewport | |
| ScrollRect | optionsScrollRect |
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. |
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()
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 |