Class UnityMenuView
Partial class for UnityMenuView containing game settings synchronization, reset-to-default logic, and value type compatibility validation.
Namespace: Serenity.Menu.Infrastructure.Views
Assembly: Serenity.UnityMenu.Infrastructure.dll
Syntax
public class UnityMenuView : UnityUiView
Constructors
UnityMenuView()
Declaration
public UnityMenuView()
Methods
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()
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. |
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. |
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. |
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. |
GetTitleGameObject()
Retrieves the GameObject containing the menu title text component.
Declaration
public GameObject GetTitleGameObject()
Returns
| Type | Description |
|---|---|
| GameObject |
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 |
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. |
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 |
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. |
SetLifecycleSignals(IReadOnlyList<EventDispatcherSignal>, IReadOnlyList<EventDispatcherSignal>)
Sets the lifecycle signal collections dispatched when the menu transitions between shown and hidden states.
Declaration
public void SetLifecycleSignals(IReadOnlyList<EventDispatcherSignal> onShow, IReadOnlyList<EventDispatcherSignal> onHide)
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. |
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. |
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. |
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. |
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()
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()