Class UnityModalComponentFactory
Factory class for creating Unity modal UI components.
Handles instantiation of modal components from templates and manages option value updates.
Integrates with game settings service to persist option changes and validate value ranges.
Implements
Inherited Members
Namespace: Serenity.Modal.Infrastructure.Views.Factories
Assembly: Serenity.UnityModal.Infrastructure.dll
Syntax
public class UnityModalComponentFactory : IUiComponentFactory
Constructors
UnityModalComponentFactory(IGameSettingsService)
Initializes a new instance of the UnityModalComponentFactory.
Sets up dependency on the game settings service for option value management.
Declaration
public UnityModalComponentFactory(IGameSettingsService gameSettingsService)
Parameters
| Type | Name | Description |
|---|---|---|
| IGameSettingsService | gameSettingsService | Service for reading and writing game settings. |
Properties
GameSettingsService
The game settings service this factory persists option values through.
Declaration
public IGameSettingsService GameSettingsService { get; }
Property Value
| Type | Description |
|---|---|
| IGameSettingsService | The injected IGameSettingsService. |
Methods
CreateUiComponent<Element, Parameters, Actions>(Parameters, Actions, IFoundationViewElement, ILogService)
Creates a UI component instance from the provided template and parameters.
Instantiates a GameObject from the template and initializes the component with the given parameters and actions.
Validates template availability and ensures proper component setup before returning the created element.
Declaration
public Element CreateUiComponent<Element, Parameters, Actions>(Parameters parameters, Actions actions, IFoundationViewElement template, ILogService logService) where Element : IFoundationViewElement where Parameters : IUiComponentParameters where Actions : IUiComponentActions
Parameters
| Type | Name | Description |
|---|---|---|
| Parameters | parameters | Configuration parameters for the UI component. |
| Actions | actions | Actions that define component behavior. |
| IFoundationViewElement | template | The template foundation view element to instantiate from. |
| ILogService | logService | Service for logging operations. |
Returns
| Type | Description |
|---|---|
| Element | The created UI component element. |
Type Parameters
| Name | Description |
|---|---|
| Element | The type of foundation view element to create. |
| Parameters | The type of UI component parameters. |
| Actions | The type of UI component actions. |
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown when unsupported element type or null template is provided. |
| Exception | Thrown when GameObject instantiation fails. |
| InvalidOperationException | Thrown when component retrieval fails. |
SetOptionValue(UiOption, string)
Sets the value of a UI option and persists it through the game settings service.
Handles type conversion and validation based on the option's value type.
Enforces minimum and maximum value constraints when specified in game settings.
Supports FLOAT, INT, BOOL, and STRING value types with appropriate formatting.
Declaration
public void SetOptionValue(UiOption option, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| UiOption | option | The UI option whose value is being set. |
| string | value | The string representation of the new value. |
ShiftOptionValue(UiOption, UnityUiInteractableComponent, int, float)
Shifts the value of an option by a relative step and persists it through the game settings service, then syncs the option's interactable so its visual reflects the new value.
Declaration
public void ShiftOptionValue(UiOption option, UnityUiInteractableComponent component, int shiftIndex, float floatIncrement)
Parameters
| Type | Name | Description |
|---|---|---|
| UiOption | option | The option whose value is shifted. |
| UnityUiInteractableComponent | component | The interactable to update so its display matches the new value. |
| int | shiftIndex | The relative step (typically +1 / -1). |
| float | floatIncrement | The amount a single FLOAT step changes the value. |
Remarks
Modal equivalent of UnityMenuOptionValueService.ShiftOptionValue, operating directly on the
UiOption instead of a menu view-model so it carries no menu coupling. FLOAT steps by
floatIncrement, INT by 1, BOOL toggles, and SELECTABLE cycles through the
configured entries. Min/max bounds from game settings are respected.