logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityUiInteractableComponent

    Abstract base class for all Unity UI interactable components in the Serenity foundation.

    Inheritance
    object
    UnityUiComponent
    UnityUiInteractableComponent
    UnityUiInputComponent
    UnityUiSliderComponent
    UnityUiSubmitComponent
    UnityUiToggleComponent
    Implements
    IUiInteractable
    IUiComponent
    IComponent
    IFoundationSettings
    Inherited Members
    UnityUiComponent._animators
    UnityUiComponent.UpdateUiElement<T>(Action<T>, IFoundationViewElement)
    Namespace: Serenity.Ui.Infrastructure.Components
    Assembly: Serenity.UnityUi.Infrastructure.dll
    Syntax
    public abstract class UnityUiInteractableComponent : UnityUiComponent, IUiInteractable, IUiComponent, IComponent, IFoundationSettings

    Constructors

    UnityUiInteractableComponent()

    Declaration
    protected UnityUiInteractableComponent()

    Fields

    _buttons

    Declaration
    protected List<GameObject> _buttons
    Field Value
    Type Description
    List<GameObject>

    _contentWrapperGameObject

    Declaration
    protected GameObject _contentWrapperGameObject
    Field Value
    Type Description
    GameObject

    _decorationsCoroutine

    Declaration
    protected Coroutine _decorationsCoroutine
    Field Value
    Type Description
    Coroutine

    _highlightGameObject

    Declaration
    protected GameObject _highlightGameObject
    Field Value
    Type Description
    GameObject

    _isDragging

    Declaration
    protected bool _isDragging
    Field Value
    Type Description
    bool

    _labelGameObject

    Declaration
    protected GameObject _labelGameObject
    Field Value
    Type Description
    GameObject

    _mainButtonGameObject

    Declaration
    protected GameObject _mainButtonGameObject
    Field Value
    Type Description
    GameObject

    _optionValueUiComponentType

    Declaration
    protected UiComponentInteractionType _optionValueUiComponentType
    Field Value
    Type Description
    UiComponentInteractionType

    _valueGameObject

    Declaration
    protected GameObject _valueGameObject
    Field Value
    Type Description
    GameObject

    _wantsHighlightVisible

    Declaration
    protected bool _wantsHighlightVisible
    Field Value
    Type Description
    bool

    _widthLocked

    Declaration
    protected bool _widthLocked
    Field Value
    Type Description
    bool

    Properties

    InteractableActions

    Gets the interactable component actions interface.
    Provides access to all interaction callbacks and event handlers for this component.

    Declaration
    public IUiInteractableActions InteractableActions { get; }
    Property Value
    Type Description
    IUiInteractableActions

    The interactable component actions interface

    InteractableParameters

    Gets or sets the interactable component parameters interface.

    Declaration
    public IUiInteractableParameters InteractableParameters { get; set; }
    Property Value
    Type Description
    IUiInteractableParameters

    _decorationsInitialized

    Whether the decoration layout pass has completed at least once.

    Declaration
    protected bool _decorationsInitialized { get; set; }
    Property Value
    Type Description
    bool

    Methods

    AdaptHighlightWidthToText(Image, TMP_Text, RectTransform, float, bool, bool, GameObject)

    Adapts the highlight image width to match the text content with configurable padding and constraints.
    Delegates to Serenity.Ui.Infrastructure.Components.UnityUiInteractableHighlightService.

    Declaration
    protected void AdaptHighlightWidthToText(Image image, TMP_Text text, RectTransform referenceRect, float padding, bool clampToReference = true, bool preferLayoutElement = true, GameObject boundsRoot = null)
    Parameters
    Type Name Description
    Image image
    TMP_Text text
    RectTransform referenceRect
    float padding
    bool clampToReference
    bool preferLayoutElement
    GameObject boundsRoot

    AlignElements(UiComponentInteractionType, UiComponentAlignmentType)

    Aligns the visual elements of this component based on interaction and alignment types.

    Declaration
    public void AlignElements(UiComponentInteractionType interactionType, UiComponentAlignmentType alignment)
    Parameters
    Type Name Description
    UiComponentInteractionType interactionType

    The UI component interaction type

    UiComponentAlignmentType alignment

    The UI component alignment type

    Awake()

    Unity lifecycle method called when the GameObject is created.
    Validates component setup, initializes button references, wrapper configuration, and calls base initialization.
    Logs errors if essential components are missing for proper component operation.

    Declaration
    public override void Awake()
    Overrides
    UnityUiComponent.Awake()

    Blur()

    Handles focus loss for this component with animation updates.
    Prevents blur operations during drag states and triggers deselection animations.
    Invokes blur actions for proper focus state management.

    Declaration
    public virtual void Blur()

    CalculateLogicalWidth()

    Calculates the logical width of this option based on label text, UI element, and padding.
    This represents the actual content width needed, not the full RectTransform width.

    Declaration
    public float CalculateLogicalWidth()
    Returns
    Type Description
    float

    The logical option width (labelWidth + uiElementWidth + padding), or 0 if calculation fails.

    Cancel()

    Handles cancellation actions for this component with audio feedback.
    Invokes cancel actions and plays cancellation audio when configured.
    Provides standardized cancellation behavior across all interactable components.

    Declaration
    public virtual void Cancel()

    DecrementValue()

    Decrements the component value and plays associated audio feedback.
    Prevents operation during drag states and invokes decrement value actions if available.
    Triggers audio feedback for value change operations when configured.

    Declaration
    public virtual void DecrementValue()

    FlipHorizontally(GameObject)

    Flips the label GameObject horizontally.

    Declaration
    protected void FlipHorizontally(GameObject label)
    Parameters
    Type Name Description
    GameObject label

    The label GameObject to flip

    Focus()

    Handles focus gain for this component with animation and audio feedback.
    Prevents focus changes during drag operations and triggers focus animations.
    Invokes focus actions and plays selection audio when configured.

    Declaration
    public virtual void Focus()

    GetButtonElements(bool)

    Retrieves the button elements as a list of foundation view elements.

    Declaration
    public List<IFoundationViewElement> GetButtonElements(bool includeMainButton = true)
    Parameters
    Type Name Description
    bool includeMainButton

    True to include the main button, false to exclude it

    Returns
    Type Description
    List<IFoundationViewElement>

    List of button elements as foundation view elements

    GetButtonGameObjects(bool)

    Retrieves the button GameObject references as a list.

    Declaration
    public List<GameObject> GetButtonGameObjects(bool includeMainButton = true)
    Parameters
    Type Name Description
    bool includeMainButton

    True to include the main button, false to exclude it

    Returns
    Type Description
    List<GameObject>

    List of button GameObject references

    GetContentWrapperGameObject()

    Retrieves the content wrapper GameObject reference.
    Provides direct access to the underlying Unity GameObject for the content wrapper element.

    Declaration
    public GameObject GetContentWrapperGameObject()
    Returns
    Type Description
    GameObject

    The content wrapper GameObject reference

    GetDecorationsPassVersion()

    Returns the current decorations pass version for orchestration tracking.

    Declaration
    public int GetDecorationsPassVersion()
    Returns
    Type Description
    int

    GetHighlightElement()

    Retrieves the highlight element as a foundation view element.

    Declaration
    public IFoundationViewElement GetHighlightElement()
    Returns
    Type Description
    IFoundationViewElement

    The highlight element as a foundation view element

    GetHighlightGameObject()

    Retrieves the highlight GameObject reference.

    Declaration
    public GameObject GetHighlightGameObject()
    Returns
    Type Description
    GameObject

    The highlight GameObject reference

    GetHighlightImage(Image, TMP_Text, RectTransform)

    Retrieves or creates the UnityUiHighlightImage data for the specified image and text components.
    Delegates to Serenity.Ui.Infrastructure.Components.UnityUiInteractableHighlightService.

    Declaration
    protected UnityUiHighlightImage GetHighlightImage(Image image, TMP_Text text, RectTransform referenceRect)
    Parameters
    Type Name Description
    Image image
    TMP_Text text
    RectTransform referenceRect
    Returns
    Type Description
    UnityUiHighlightImage

    GetHighlightTargetWidth(Image, TMP_Text, RectTransform, float, bool, bool, GameObject)

    Calculates the target width for the highlight image.
    Delegates to Serenity.Ui.Infrastructure.Components.UnityUiInteractableHighlightService.

    Declaration
    protected float GetHighlightTargetWidth(Image image, TMP_Text text, RectTransform referenceRect, float padding, bool clampToReference, bool preferLayoutElement, GameObject boundsRoot)
    Parameters
    Type Name Description
    Image image
    TMP_Text text
    RectTransform referenceRect
    float padding
    bool clampToReference
    bool preferLayoutElement
    GameObject boundsRoot
    Returns
    Type Description
    float

    GetIndex()

    Gets the current display index of this component.
    Returns the component's position in the UI hierarchy ordering.

    Declaration
    public int GetIndex()
    Returns
    Type Description
    int

    The zero-based index position of this component

    GetIsDragging()

    Gets the current dragging state of this component.
    Returns whether the component is currently in a dragging operation.

    Declaration
    public bool GetIsDragging()
    Returns
    Type Description
    bool

    True if component is being dragged, false otherwise

    GetLabelElement()

    Retrieves the label element as a foundation view element.

    Declaration
    public IFoundationViewElement GetLabelElement()
    Returns
    Type Description
    IFoundationViewElement

    The label element as a foundation view element

    GetLabelGameObject()

    Retrieves the label GameObject reference.

    Declaration
    public GameObject GetLabelGameObject()
    Returns
    Type Description
    GameObject

    The label GameObject reference

    GetMainButtonElement()

    Retrieves the main button element as a foundation view element.

    Declaration
    public IFoundationViewElement GetMainButtonElement()
    Returns
    Type Description
    IFoundationViewElement

    The main button element as a foundation view element

    GetMainButtonGameObject()

    Retrieves the main button GameObject reference.

    Declaration
    public GameObject GetMainButtonGameObject()
    Returns
    Type Description
    GameObject

    The main button GameObject reference

    GetUiComponentInteractionType()

    Retrieves the UI component interaction type for this component.

    Declaration
    public UiComponentInteractionType GetUiComponentInteractionType()
    Returns
    Type Description
    UiComponentInteractionType

    The UI component interaction type

    GetValueElement()

    Retrieves the value element as a foundation view element.

    Declaration
    public IFoundationViewElement GetValueElement()
    Returns
    Type Description
    IFoundationViewElement

    The value element as a foundation view element

    GetValueGameObject()

    Retrieves the value GameObject reference.

    Declaration
    public GameObject GetValueGameObject()
    Returns
    Type Description
    GameObject

    The value GameObject reference

    HandleCenterAlignment(TMP_Text)

    Handles the center alignment for the label text.

    Declaration
    protected void HandleCenterAlignment(TMP_Text labelText)
    Parameters
    Type Name Description
    TMP_Text labelText

    The label text to align

    IncrementValue()

    Increments the component value and plays associated audio feedback.
    Prevents operation during drag states and invokes increment value actions if available.
    Triggers audio feedback for value change operations when configured.

    Declaration
    public virtual void IncrementValue()

    Initialize(IUiComponentParameters, IUiComponentActions, ILogService)

    Initializes the Unity UI component with required parameters, actions, and services.
    Extends base initialization to include Unity-specific Animator component setup for animation support.
    This method establishes the connection between foundation-agnostic component logic and Unity's rendering system.

    Declaration
    public override void Initialize(IUiComponentParameters parameters, IUiComponentActions uiComponentActions, ILogService logService)
    Parameters
    Type Name Description
    IUiComponentParameters parameters

    Component configuration parameters defining behavior and appearance

    IUiComponentActions uiComponentActions

    Action handlers for component interactions and events

    ILogService logService

    Logging service for debugging and error reporting

    Overrides
    UnityUiComponent.Initialize(IUiComponentParameters, IUiComponentActions, ILogService)

    InitializeButtons()

    Initializes the button elements for this component.

    Declaration
    protected void InitializeButtons()

    InitializeHighlight()

    Initializes the highlight state for this component based on its index.

    Declaration
    public void InitializeHighlight()

    InitializeLabel(string)

    Initializes the label for this component.

    Declaration
    public void InitializeLabel(string label)
    Parameters
    Type Name Description
    string label

    InitializeMirroring(UiComponentAlignmentType)

    Initializes mirroring for the component based on the specified alignment type.

    Declaration
    protected void InitializeMirroring(UiComponentAlignmentType optionAlignment)
    Parameters
    Type Name Description
    UiComponentAlignmentType optionAlignment

    The UI component alignment type

    InitializeVisualElement()

    Initializes the visual elements of this component with default parameters.

    Declaration
    public virtual void InitializeVisualElement()

    InitializeVisualElement(UiComponentInteractionType, UiComponentAlignmentType, float, string)

    Initializes the visual elements of this component with specified parameters.

    Declaration
    public void InitializeVisualElement(UiComponentInteractionType interactionType, UiComponentAlignmentType alignment, float gap, string label)
    Parameters
    Type Name Description
    UiComponentInteractionType interactionType
    UiComponentAlignmentType alignment
    float gap
    string label

    IsWidthLocked()

    Gets whether the width is currently locked.

    Declaration
    public bool IsWidthLocked()
    Returns
    Type Description
    bool

    MapTMPAlignment(UiComponentAlignmentType)

    Maps foundation alignment types to TextMeshPro alignment options.
    Delegates to Serenity.Ui.Infrastructure.Components.UnityUiInteractableTextAlignmentHelper.

    Declaration
    protected TextAlignmentOptions MapTMPAlignment(UiComponentAlignmentType alignment)
    Parameters
    Type Name Description
    UiComponentAlignmentType alignment

    The foundation alignment type to convert

    Returns
    Type Description
    TextAlignmentOptions

    The corresponding TextMeshPro alignment option

    OnDisable()

    Declaration
    public override void OnDisable()

    OnDraggingEnd()

    Handles the end of dragging operations for this component.
    Prevents multiple drag end events and invokes dragging end actions.
    Resets internal drag state and notifies action handlers of the drag completion.

    Declaration
    public void OnDraggingEnd()

    OnDraggingStart()

    Handles the start of dragging operations for this component.
    Prevents multiple drag start events and invokes dragging start actions.
    Updates internal drag state and notifies action handlers of the drag operation.

    Declaration
    public void OnDraggingStart()

    OnEnable()

    Declaration
    public override void OnEnable()

    RefreshLayoutAfterTextChange()

    Forces recalculation of decorations (highlight, widths, etc.) after text has changed (translation, manual change, etc.).

    Declaration
    public void RefreshLayoutAfterTextChange()

    RelocateHighlightImage(Image, TMP_Text, RectTransform, RectTransform)

    Relocates the highlight image centered over the union of relevant horizontal bounds.
    Delegates to Serenity.Ui.Infrastructure.Components.UnityUiInteractableHighlightService.

    Declaration
    protected void RelocateHighlightImage(Image image, TMP_Text text, RectTransform refRect, RectTransform parent)
    Parameters
    Type Name Description
    Image image
    TMP_Text text
    RectTransform refRect
    RectTransform parent

    RunDecorations(bool)

    Explicitly runs a decorations pass, bypassing auto-decorations gating.

    Declaration
    public Coroutine RunDecorations(bool reselectButton = false)
    Parameters
    Type Name Description
    bool reselectButton
    Returns
    Type Description
    Coroutine

    SelectComponentById(string)

    Requests navigation to a specific component by its identifier.
    Invokes component selection by ID actions for direct UI navigation.

    Declaration
    public virtual void SelectComponentById(string id)
    Parameters
    Type Name Description
    string id

    The unique identifier of the component to select

    SelectNextComponent()

    Requests navigation to the next component in the UI flow.
    Invokes next component selection actions for UI navigation management.

    Declaration
    public virtual void SelectNextComponent()

    SelectPreviousComponent()

    Requests navigation to the previous component in the UI flow.
    Invokes previous component selection actions for UI navigation management.

    Declaration
    public virtual void SelectPreviousComponent()

    SetAutoDecorationsEnabled(bool)

    Enable or disable automatic decoration passes triggered by Focus/TMP changes.

    Declaration
    public void SetAutoDecorationsEnabled(bool enabled)
    Parameters
    Type Name Description
    bool enabled

    SetButtonAlignment(UiComponentAlignmentType)

    Sets the button alignment based on the specified alignment type.

    Declaration
    protected void SetButtonAlignment(UiComponentAlignmentType optionAlignment)
    Parameters
    Type Name Description
    UiComponentAlignmentType optionAlignment

    The UI component alignment type

    SetButtonElements(List<IFoundationViewElement>)

    Sets the button elements using a list of foundation view elements.

    Declaration
    public void SetButtonElements(List<IFoundationViewElement> buttons)
    Parameters
    Type Name Description
    List<IFoundationViewElement> buttons

    List of foundation view elements to set as buttons

    SetContentWrapperGameObject(GameObject)

    Sets the content wrapper GameObject reference.
    Assigns the provided GameObject as the content wrapper element for this component.

    Declaration
    public void SetContentWrapperGameObject(GameObject contentWrapperGameObject)
    Parameters
    Type Name Description
    GameObject contentWrapperGameObject

    SetDeselectedAnimation()

    Sets the deselected animation for this component.

    Declaration
    protected void SetDeselectedAnimation()

    SetElementPosition(float, UiComponentAlignmentType)

    Sets the position of this component based on its index and specified gap.

    Declaration
    public void SetElementPosition(float gap, UiComponentAlignmentType optionAlignment)
    Parameters
    Type Name Description
    float gap

    The vertical gap between components

    UiComponentAlignmentType optionAlignment

    The UI component alignment type

    SetFocus(bool)

    Sets the focus state of this component with visual and behavioral updates.
    Controls highlight visibility and triggers appropriate focus/blur methods.
    Manages the visual indication of component selection state.

    Declaration
    public virtual void SetFocus(bool active)
    Parameters
    Type Name Description
    bool active

    True to focus the component, false to blur it

    SetFocusAnimation()

    Sets the focus animation for this component.

    Declaration
    protected void SetFocusAnimation()

    SetHighlightAlignment(UiComponentAlignmentType)

    Sets the highlight alignment based on the specified alignment type.

    Declaration
    protected void SetHighlightAlignment(UiComponentAlignmentType optionAlignment)
    Parameters
    Type Name Description
    UiComponentAlignmentType optionAlignment

    The UI component alignment type

    SetHighlightElement(IFoundationViewElement)

    Sets the highlight element using a foundation view element.

    Declaration
    public void SetHighlightElement(IFoundationViewElement highlight)
    Parameters
    Type Name Description
    IFoundationViewElement highlight

    The foundation view element to set as the highlight

    SetHighlightGameObject(GameObject)

    Sets the highlight GameObject reference.

    Declaration
    public void SetHighlightGameObject(GameObject highlightGameObject)
    Parameters
    Type Name Description
    GameObject highlightGameObject

    The GameObject to set as the highlight element

    SetIndex(int)

    Sets the display index for this component within its container.
    Updates the component's position in the UI hierarchy for proper ordering.

    Declaration
    public void SetIndex(int index)
    Parameters
    Type Name Description
    int index

    The zero-based index position for this component

    SetIsDragging(bool)

    Sets the dragging state for this component.
    Controls whether the component is currently being dragged, affecting interaction behavior.

    Declaration
    public void SetIsDragging(bool isDragging)
    Parameters
    Type Name Description
    bool isDragging

    True if component is being dragged, false otherwise

    SetLabelAlignment(UiComponentAlignmentType)

    Sets the label alignment based on the specified alignment type.

    Declaration
    protected void SetLabelAlignment(UiComponentAlignmentType optionAlignment)
    Parameters
    Type Name Description
    UiComponentAlignmentType optionAlignment

    The UI component alignment type

    SetLabelElement(IFoundationViewElement)

    Sets the label element using a foundation view element.

    Declaration
    public void SetLabelElement(IFoundationViewElement label)
    Parameters
    Type Name Description
    IFoundationViewElement label

    The foundation view element to set as the label

    SetLabelGameObject(GameObject)

    Sets the label GameObject reference.

    Declaration
    public void SetLabelGameObject(GameObject labelGameObject)
    Parameters
    Type Name Description
    GameObject labelGameObject

    SetLabelText(string)

    Sets the displayed text on the label element's TMPro.TMP_Text component. No-op when the label GameObject or its TMP_Text is missing.

    Declaration
    public void SetLabelText(string text)
    Parameters
    Type Name Description
    string text

    The text to display on the label.

    SetMainButtonElement(IFoundationViewElement)

    Sets the main button element using a foundation view element.

    Declaration
    public void SetMainButtonElement(IFoundationViewElement mainButton)
    Parameters
    Type Name Description
    IFoundationViewElement mainButton

    The foundation view element to set as the main button

    SetMainButtonGameObject(GameObject)

    Sets the main button GameObject reference.

    Declaration
    public void SetMainButtonGameObject(GameObject mainButtonGameObject)
    Parameters
    Type Name Description
    GameObject mainButtonGameObject

    SetUiComponentInteractionType(UiComponentInteractionType)

    Sets the UI component interaction type for this component.

    Declaration
    public void SetUiComponentInteractionType(UiComponentInteractionType optionValueUiComponentType)
    Parameters
    Type Name Description
    UiComponentInteractionType optionValueUiComponentType

    The UI component interaction type to set

    SetValue(string)

    Abstract method for setting the display value of this component.
    Must be implemented by derived classes to handle component-specific value display.

    Declaration
    public abstract void SetValue(string value)
    Parameters
    Type Name Description
    string value

    The string value to display in the component

    SetValueAlignment(UiComponentInteractionType, UiComponentAlignmentType)

    Sets the value alignment based on the specified interaction and alignment types.

    Declaration
    protected void SetValueAlignment(UiComponentInteractionType interactionType, UiComponentAlignmentType optionAlignment)
    Parameters
    Type Name Description
    UiComponentInteractionType interactionType

    The UI component interaction type

    UiComponentAlignmentType optionAlignment

    The UI component alignment type

    SetValueElement(IFoundationViewElement)

    Sets the value element using a foundation view element.

    Declaration
    public void SetValueElement(IFoundationViewElement value)
    Parameters
    Type Name Description
    IFoundationViewElement value

    The foundation view element to set as the value

    SetValueGameObject(GameObject)

    Sets the value GameObject reference.

    Declaration
    public void SetValueGameObject(GameObject valueGameObject)
    Parameters
    Type Name Description
    GameObject valueGameObject

    SetValueText(string)

    Sets the displayed text on the value element's TMPro.TMP_Text component. No-op when the value GameObject or its TMP_Text is missing.

    Declaration
    public void SetValueText(string text)
    Parameters
    Type Name Description
    string text

    The text to display on the value.

    SetWidthLocked(bool)

    Sets the width lock state for this component.

    Declaration
    public void SetWidthLocked(bool locked)
    Parameters
    Type Name Description
    bool locked

    SetupDecorations(bool)

    Coroutine that configures decorations and (optionally) re-selects the button.
    Delegates the layout pass to Serenity.Ui.Infrastructure.Components.UnityUiInteractableDecorationCoordinator.

    Declaration
    protected IEnumerator SetupDecorations(bool reselectButton)
    Parameters
    Type Name Description
    bool reselectButton
    Returns
    Type Description
    IEnumerator

    Submit()

    Handles submission actions for this component with audio feedback.
    Invokes submit actions and plays submission audio when configured.
    Provides standardized submission behavior across all interactable components.

    Declaration
    public virtual void Submit()

    Events

    DecorationsReady

    Event fired when SetupDecorations completes successfully.

    Declaration
    public event Action<UnityUiInteractableComponent> DecorationsReady
    Event Type
    Type Description
    Action<UnityUiInteractableComponent>

    Implements

    IUiInteractable
    IUiComponent
    IComponent
    IFoundationSettings
    In this article
    © 2026 Serenity. All Rights Reserved