Class UnityUiView
Abstract base class for Unity UI views providing common functionality for UI display and interaction.
Manages view models, audio integration, event dispatching, and UI element lifecycle within the Unity UI system.
Handles wrapper GameObject visibility, button state management, and audio playback coordination for consistent UI behavior.
Namespace: Serenity.Ui.Infrastructure.Views
Assembly: Serenity.UnityUi.Infrastructure.dll
Syntax
public abstract class UnityUiView : UnityViewBase
Constructors
UnityUiView()
Declaration
protected UnityUiView()
Fields
_audioClips
Declaration
protected Dictionary<string, AudioPlayerClip> _audioClips
Field Value
| Type | Description |
|---|---|
| Dictionary<string, AudioPlayerClip> | Dictionary of audio clips available for this view |
_audioPlayerPlayClip
Declaration
protected AudioPlayerPlayClip _audioPlayerPlayClip
Field Value
| Type | Description |
|---|---|
| AudioPlayerPlayClip | The audio player delegate for playing UI sounds |
_audioServiceId
Declaration
protected string _audioServiceId
Field Value
| Type | Description |
|---|---|
| string | The audio service identifier for this view |
_eventDispatcherService
Declaration
protected IEventDispatcherService _eventDispatcherService
Field Value
| Type | Description |
|---|---|
| IEventDispatcherService | The event dispatcher service for this view |
_uiHideSfxKey
Declaration
protected string _uiHideSfxKey
Field Value
| Type | Description |
|---|---|
| string | The key for the UI hide sound effect |
_uiShowSfxKey
Declaration
protected string _uiShowSfxKey
Field Value
| Type | Description |
|---|---|
| string | The key for the UI show sound effect |
_useCases
Declaration
protected UiUseCases _useCases
Field Value
| Type | Description |
|---|---|
| UiUseCases | The UI use cases associated with this view |
_viewModel
Declaration
protected UnityUiViewModel _viewModel
Field Value
| Type | Description |
|---|---|
| UnityUiViewModel | The view model associated with this UI view |
_wrapper
Declaration
protected GameObject _wrapper
Field Value
| Type | Description |
|---|---|
| GameObject | The wrapper GameObject for this UI view |
Methods
CanPlayAudio(string)
Validates whether audio can be played for the specified sound effect key.
Checks for the presence of required audio components and validates the audio clip exists in the dictionary.
Throws KeyNotFoundException if the specified audio clip key is not found.
Declaration
protected bool CanPlayAudio(string sfxKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sfxKey | The audio clip key to validate for playback |
Returns
| Type | Description |
|---|---|
| bool | True if audio can be played, false otherwise |
Exceptions
| Type | Condition |
|---|---|
| KeyNotFoundException | Thrown when the audio clip key is not found |
DisableNonSelectedButtons()
Disables button and event trigger components for all UI interactable elements.
Prevents user interaction with UI elements during dragging or other operations requiring focus lock.
Declaration
protected void DisableNonSelectedButtons()
EnableAllButtons()
Re-enables button and event trigger components for all UI interactable elements.
Restores normal user interaction capabilities after dragging or other focus-locked operations complete.
Declaration
protected void EnableAllButtons()
GetAudioClips()
Returns the audio clips dictionary configured for this view.
Provides access to all audio clips available for UI sound effects.
Declaration
public Dictionary<string, AudioPlayerClip> GetAudioClips()
Returns
| Type | Description |
|---|---|
| Dictionary<string, AudioPlayerClip> | Dictionary mapping audio clip keys to AudioPlayerClip instances |
GetUseCases()
Returns the UI use cases configured for this view.
Provides access to the application layer use cases for view operations.
Declaration
public UiUseCases GetUseCases()
Returns
| Type | Description |
|---|---|
| UiUseCases | The UI use cases instance for this view |
GetViewModel()
Returns the currently configured view model instance.
Provides access to the bound view model for external view state inspection.
Declaration
public UnityUiViewModel GetViewModel()
Returns
| Type | Description |
|---|---|
| UnityUiViewModel | The Unity UI view model bound to this view |
GetWrapper()
Declaration
public GameObject GetWrapper()
Returns
| Type | Description |
|---|---|
| GameObject |
Initialize(AudioPlayerPlayClip, string, IEventDispatcherService)
Initializes the Unity UI view with required dependencies and services.
Configures audio playback, event dispatching, and other essential services for view operation.
Declaration
public virtual void Initialize(AudioPlayerPlayClip audioPlayerPlayClip, string audioServiceId, IEventDispatcherService eventDispatcherService)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioPlayerPlayClip | audioPlayerPlayClip | |
| string | audioServiceId | |
| IEventDispatcherService | eventDispatcherService |
InitializeEventDispatcher(IEventDispatcherService)
Initializes the event dispatcher for this view and subscribes to relevant events.
Sets up the event communication system and establishes event subscriptions.
Declaration
public void InitializeEventDispatcher(IEventDispatcherService eventDispatcherService)
Parameters
| Type | Name | Description |
|---|---|---|
| IEventDispatcherService | eventDispatcherService | The event dispatcher service for view communication |
OnDraggingEnd()
Handles the end of UI element dragging operations.
Re-enables all buttons to restore normal UI interaction capabilities.
Declaration
public void OnDraggingEnd()
OnDraggingStart()
Handles the start of UI element dragging operations.
Disables non-selected buttons to prevent unintended interactions during drag operations.
Declaration
public void OnDraggingStart()
OnShow(bool)
Handles view visibility state changes from the view model.
Controls the wrapper GameObject activation state based on the view model's showing state.
Logs warnings if the wrapper GameObject is not properly configured.
Declaration
protected virtual void OnShow(bool isShowing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isShowing | True if the view should be visible, false otherwise |
SetAudioClips(AudioPlayerClip, AudioPlayerClip)
Sets the audio clips for UI sound effects.
Configures the show and hide sound effects for the UI elements managed by this view.
Declaration
public void SetAudioClips(AudioPlayerClip showSfx, AudioPlayerClip hideSfx)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioPlayerClip | showSfx | The audio clip to play when showing the UI |
| AudioPlayerClip | hideSfx | The audio clip to play when hiding the UI |
SetAudioPlayerPlayClip(AudioPlayerPlayClip)
Sets the audio player component for playing audio clips.
Configures the component responsible for controlling audio playback in this view.
Declaration
public void SetAudioPlayerPlayClip(AudioPlayerPlayClip audioPlayerPlayClip)
Parameters
| Type | Name | Description |
|---|---|---|
| AudioPlayerPlayClip | audioPlayerPlayClip | The audio player component instance |
SetAudioServiceId(string)
Configures the audio service identifier for this view.
Sets the service ID used for audio playback through the audio system.
Declaration
public void SetAudioServiceId(string audioServiceId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | audioServiceId | The audio service identifier string |
SetEventDispatcherService(IEventDispatcherService)
Sets the event dispatcher service for this view.
Establishes the communication channel for view-to-system event messaging.
Declaration
public void SetEventDispatcherService(IEventDispatcherService eventDispatcherService)
Parameters
| Type | Name | Description |
|---|---|---|
| IEventDispatcherService | eventDispatcherService | The event dispatcher service instance |
SetUseCases(UiUseCases)
Sets the use cases for this view.
Configures the application layer use cases that this view can execute.
Declaration
public void SetUseCases(UiUseCases useCases)
Parameters
| Type | Name | Description |
|---|---|---|
| UiUseCases | useCases | The UI use cases instance |
SetViewModel(UnityUiViewModel)
Configures the view model and establishes data binding for view state management.
Subscribes to the view model's visibility state changes to control wrapper GameObject activation.
Adds the subscription to the disposables collection for proper cleanup on view destruction.
Declaration
public void SetViewModel(UnityUiViewModel viewModel)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityUiViewModel | viewModel | The Unity UI view model to bind to this view |
SetWrapper(GameObject)
Sets the wrapper GameObject for this view.
Configures the container GameObject that holds the view's UI elements.
Declaration
public void SetWrapper(GameObject wrapper)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | wrapper | The wrapper GameObject to assign |
SubscribeToEventDispatcherEvents()
Abstract method for subscribing to event dispatcher events.
Must be implemented by derived classes to define specific event subscriptions.
Declaration
public abstract void SubscribeToEventDispatcherEvents()