logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityMenuService

    Unity MonoBehaviour implementation of IMenuService that manages menu view display and navigation.
    Handles the lifecycle and state management of Unity-based menu views throughout the application.

    Inheritance
    object
    UnityMenuService
    Implements
    IMenuService
    IService
    IFoundationSettings
    IMenuInstanceGate
    Namespace: Serenity.Menu.Infrastructure.Services
    Assembly: Serenity.UnityMenu.Infrastructure.dll
    Syntax
    public class UnityMenuService : MonoBehaviour, IMenuService, IService, IFoundationSettings, IMenuInstanceGate

    Constructors

    UnityMenuService()

    Declaration
    public UnityMenuService()

    Fields

    _logService

    Declaration
    protected ILogService _logService
    Field Value
    Type Description
    ILogService

    ILogService for logging within the menu service.

    _menuViews

    Declaration
    protected Dictionary<string, UnityMenuView> _menuViews
    Field Value
    Type Description
    Dictionary<string, UnityMenuView>

    Dictionary of built Unity menu views keyed by their identifiers for efficient lookup.

    Properties

    Guid

    Declaration
    public string Guid { get; set; }
    Property Value
    Type Description
    string

    Gets or sets the globally unique identifier for this service.

    Id

    Declaration
    public string Id { get; set; }
    Property Value
    Type Description
    string

    LogService

    Declaration
    public ILogService LogService { get; set; }
    Property Value
    Type Description
    ILogService

    Methods

    DeactivateMenuContext()

    Declaration
    public void DeactivateMenuContext()

    EnsureMenu(string)

    Ensures the requested menu has a built, cached view, building a LazyOnFirstOpen menu on first request.
    Idempotent: an already-built menu returns true without rebuilding; a registered lazy menu is built once and cached; an unknown menu id fails loudly (throws). A lazy build failure is logged in detail, then rethrown in editor/development builds (fail-loud) or reported as false in production builds.

    Declaration
    public bool EnsureMenu(string menuId)
    Parameters
    Type Name Description
    string menuId

    The id of the menu whose visual instance must exist.

    Returns
    Type Description
    bool

    True if the menu's view is available after the call; false on a non-fatal (production) build failure.

    Exceptions
    Type Condition
    Exception

    Thrown when the menu id is unknown, or when a lazy build fails in editor/development builds.

    GetCurrentView()

    Gets the currently active menu view by checking which view's options wrapper is active.
    Returns null if no menu view is currently active.

    Declaration
    public IViewBase GetCurrentView()
    Returns
    Type Description
    IViewBase

    The currently active IViewBase implementation, or null if none are active.

    InitializeService(Dictionary<string, IViewBase>, IViewBrowserService, string)

    Initializes the menu service with the provided menu views.
    Validates that all provided views are UnityMenuView instances and stores them for management.

    Declaration
    public void InitializeService(Dictionary<string, IViewBase> menuViews, IViewBrowserService viewBrowserService, string initMenuId)
    Parameters
    Type Name Description
    Dictionary<string, IViewBase> menuViews

    Dictionary of menu views keyed by their identifiers.

    IViewBrowserService viewBrowserService

    Service for managing view navigation and lifecycle operations between menu screens.

    string initMenuId

    The ID of the initial menu to show when ShowInitialMenu is called.

    Exceptions
    Type Condition
    Exception

    Thrown when a view is not a UnityMenuView instance.

    RegisterLazyMenus(Dictionary<string, UnityMenuLazyRegistration>, UnityMenuLazyBuildContext)

    Registers LazyOnFirstOpen menus and the shared build context used to construct their views on first show.
    Intended to be called by the installer immediately after InitializeService(Dictionary<string, IViewBase>, IViewBrowserService, string). Safe to call with an empty registration set (the all-PreloadOnStartup default), in which case no menu is ever lazy.

    Declaration
    public void RegisterLazyMenus(Dictionary<string, UnityMenuLazyRegistration> lazyRegistrations, UnityMenuLazyBuildContext context)
    Parameters
    Type Name Description
    Dictionary<string, UnityMenuLazyRegistration> lazyRegistrations

    Per-menu lazy registrations keyed by menu id.

    UnityMenuLazyBuildContext context

    Shared build inputs reused to construct any lazy menu view.

    SetGameModeService(IGameModeService)

    Sets the GameMode service used to coordinate the application mode when the initial menu is shown.
    Intended to be invoked by the composition root once the GameMode service has been constructed.

    Declaration
    public void SetGameModeService(IGameModeService gameModeService)
    Parameters
    Type Name Description
    IGameModeService gameModeService

    The GameMode service implementation to coordinate with.

    ShowInitialMenu()

    Shows the initial menu configured during initialization.
    This is the menu that should be displayed at startup or when returning from gameplay.

    Declaration
    public void ShowInitialMenu()
    Exceptions
    Type Condition
    Exception

    Thrown when InitMenuId is not configured or the menu is not found.

    ShowMenu(string)

    Shows the menu with the specified identifier by executing its show menu operation.
    Activates the requested menu view and makes it visible to the user.

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

    The identifier of the menu to show.

    Exceptions
    Type Condition
    Exception

    Thrown when the specified menu ID is not found in the service.

    Implements

    IMenuService
    IService
    IFoundationSettings
    IMenuInstanceGate
    In this article
    © 2026 Serenity. All Rights Reserved