logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityHudElementView

    One HUD element on screen: an anchored container holding an optional caption and whatever its representation renders.

    Inheritance
    object
    UnityHudElementView
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    Namespace: Serenity.GameUi.Infrastructure.Views
    Assembly: Serenity.UnityGameUi.Infrastructure.dll
    Syntax
    public sealed class UnityHudElementView
    Remarks

    The caption is a separate text object from the value on purpose. The theme's localization updater translates whatever text it finds, so routing a number through it would make it look up "1234" as a translation key.

    Constructors

    UnityHudElementView()

    Declaration
    public UnityHudElementView()

    Properties

    BindingError

    Why this element cannot read its value, or empty when it is fine.

    Declaration
    public string BindingError { get; }
    Property Value
    Type Description
    string

    ContentRoot

    The container Serenity.GameUi.Infrastructure.Views.UnityHudElementView.CreateContainer(Serenity.GameUi.Infrastructure.Settings.UnityHudElementDefinition,UnityEngine.RectTransform,Serenity.GameUi.Infrastructure.Representations.HudRenderResources) builds — the same UnityEngine.RectTransform a FLEXBOX representation's layout group arranges, and the one HudElementHierarchy reparents a child element's root underneath when the child authors this element as its ParentId.

    Declaration
    public RectTransform ContentRoot { get; }
    Property Value
    Type Description
    RectTransform

    ElementId

    The authored element's id, so the host can address it individually (e.g. per-element show/hide signals).

    Declaration
    public string ElementId { get; }
    Property Value
    Type Description
    string

    GameObject

    The element's root object, so the host can show, hide and destroy it.

    Declaration
    public GameObject GameObject { get; }
    Property Value
    Type Description
    GameObject

    Methods

    Build(UnityHudElementDefinition, RectTransform, HudRenderResources, Func<Type, object>)

    Builds the element under host.

    Declaration
    public static UnityHudElementView Build(UnityHudElementDefinition definition, RectTransform host, HudRenderResources resources, Func<Type, object> serviceResolver)
    Parameters
    Type Name Description
    UnityHudElementDefinition definition

    The authored element.

    RectTransform host

    The HUD host to parent under.

    HudRenderResources resources

    Theme-derived building blocks.

    Func<Type, object> serviceResolver

    Resolves a service contract to its instance.

    Returns
    Type Description
    UnityHudElementView

    The built view.

    BuildPreview(UnityHudElementDefinition, RectTransform, HudRenderResources)

    Builds the element with its authored preview values instead of live bindings.

    Declaration
    public static UnityHudElementView BuildPreview(UnityHudElementDefinition definition, RectTransform host, HudRenderResources resources)
    Parameters
    Type Name Description
    UnityHudElementDefinition definition

    The authored element.

    RectTransform host

    The preview canvas root to parent under.

    HudRenderResources resources

    Theme-derived building blocks.

    Returns
    Type Description
    UnityHudElementView

    The built view.

    Remarks

    Shares every line of placement, layout and drawing with Build(UnityHudElementDefinition, RectTransform, HudRenderResources, Func<Type, object>) — only the source of the numbers differs. That is the point: what the builder tool shows is the renderer the game runs, not a second implementation that can drift away from it.

    Dispose()

    Destroys the element's objects.

    Declaration
    public void Dispose()

    EnableValueChangeObservation()

    Arms this view to raise ValueChanged on an actual value change, and (like change feedback and thresholds already do at build time) marks that it needs to observe its value at all.

    Declaration
    public void EnableValueChangeObservation()
    Remarks

    Expected to be called before this view's first Tick(float) — UnityHudHostComponent.BuildAnimator calls this once per watched element, right after every element in the HUD is built and before the host's own Update loop ever ticks anything, because which elements are watched is only known once every element's authored animations have been read (see Build(UnityHudElementDefinition, RectTransform, HudRenderResources, Func<Type, object>)/Serenity.GameUi.Infrastructure.Views.UnityHudElementView.Construct(Serenity.GameUi.Infrastructure.Settings.UnityHudElementDefinition,UnityEngine.RectTransform,Serenity.GameUi.Infrastructure.Representations.HudRenderResources) for why it cannot run earlier, as part of the build itself).

    A caller that arms observation only after this view has already ticked is defended against rather than merely documented against: Serenity.GameUi.Infrastructure.Views.UnityHudElementView._needsValueRebaseline makes the very next Serenity.GameUi.Infrastructure.Views.UnityHudElementView.ObserveValue call re-baseline silently — the same mechanism Serenity.GameUi.Infrastructure.Views.UnityHudElementView.ObserveHiddenValueSilently already provides for a hidden element — instead of comparing the shared HudValueChangeDetector against whatever baseline happened to already be there.

    MarkDirty()

    Forces a read on the next tick, regardless of the element's trigger.

    Declaration
    public void MarkDirty()
    Remarks

    How the on-signal trigger drives an element: the host marks it dirty when the signal lands.

    RequestSignalAnimation(UnityHudElementAnimation)

    The host's entry point for an ON_SIGNAL animation. Goes through the same per-entry cooldown gate as a value- or show-raised one rather than activating the animator layer directly.

    Declaration
    public void RequestSignalAnimation(UnityHudElementAnimation animation)
    Parameters
    Type Name Description
    UnityHudElementAnimation animation

    The authored entry the landed signal maps to.

    RequestValueAnimation(UnityHudElementAnimation, HudValueChangeDirection)

    The host's entry point for a value-triggered animation, called once per (owner, entry) pair the host registered against a watched view's ValueChanged.

    Declaration
    public void RequestValueAnimation(UnityHudElementAnimation animation, HudValueChangeDirection direction)
    Parameters
    Type Name Description
    UnityHudElementAnimation animation

    The authored entry to evaluate and, if it matches, request.

    HudValueChangeDirection direction

    The direction the watched value changed in.

    SetVisible(bool)

    Shows or hides the element.

    Declaration
    public void SetVisible(bool visible)
    Parameters
    Type Name Description
    bool visible

    Whether it should be visible.

    Remarks

    Used both for whole-HUD show/hide and for per-element hiding (HideHudElementSignal). Toggling the root's active state, rather than a UnityEngine.CanvasGroup alpha, is enough to satisfy the per-element contract too: elements are independently anchored under the host rather than arranged by a shared layout group, so deactivating one never reflows its siblings — and Tick(float) is driven by the host's own Update loop rather than a per-GameObject MonoBehaviour.Update, so bindings keep reading and applying while the element sits inactive.

    ON_SHOW only arms on a genuine hidden→visible transition, tracked by Serenity.GameUi.Infrastructure.Views.UnityHudElementView._isVisible rather than the root's own activeSelf (which starts true the instant a fresh GameObject is created, before anything has ever called this method). Calling this with true twice in a row — or a host that shows every built element and then immediately re-hides the ones remembered as individually hidden — must never re-fire an entrance animation for an element that was never really shown in between. See UnityHudHostComponent.ShowAllElements for the pass that depends on this: it computes each element's final visibility up front instead of showing everything and re-hiding, specifically so a StartsHidden element's SetVisible(true) is never called at all.

    Tick(float)

    Re-reads the bindings and updates the visuals if the element's trigger allows it now.

    Declaration
    public void Tick(float deltaSeconds)
    Parameters
    Type Name Description
    float deltaSeconds

    Unscaled time since the previous tick.

    Events

    AnimationRequested

    Raised when an authored animation passes its cooldown gate. The host subscribes one non-closure handler over the view rather than reaching into the scheduler, so the event stays part of the view's surface even though the gate that decides it does not.

    Declaration
    public event Action<UnityHudElementAnimation> AnimationRequested
    Event Type
    Type Description
    Action<UnityHudElementAnimation>

    ValueChanged

    Raised once this view's bound value is observed to have actually changed, and only once EnableValueChangeObservation() has been called. Passes this rather than closing over the view, mirroring AnimationRequested: the host subscribes one non-closure instance method per watched view instead of allocating a lambda per subscription.

    Declaration
    public event Action<UnityHudElementView, HudValueChangeDirection> ValueChanged
    Event Type
    Type Description
    Action<UnityHudElementView, HudValueChangeDirection>
    In this article
    © 2026 Serenity. All Rights Reserved