Class UnityHudHostComponent
Owns the HUD on screen: builds an authored HUD's elements under its own canvas, ticks them, and tears them down when the HUD changes.
Namespace: Serenity.GameUi.Infrastructure.Views
Assembly: Serenity.UnityGameUi.Infrastructure.dll
Syntax
public class UnityHudHostComponent : MonoBehaviour
Remarks
Deliberately outside the view router. ViewRouter.ShowView hides the current view before showing
the next, so a HUD registered as a router view would be torn down by any menu. Every other persistent
overlay in Serenity — the toast host, the loading overlay, the input prompt — opts out the same way, with
its own sorting canvas.
Constructors
UnityHudHostComponent()
Declaration
public UnityHudHostComponent()
Fields
DefaultName
Name given to a host GameObject created by CreateDefault(string).
Declaration
public const string DefaultName = "HudHost"
Field Value
| Type | Description |
|---|---|
| string |
HudSortingOrder
Sorting order for the HUD canvas. Below the toast host's 1000 and far below the loading overlay's 11000, so a notification or a load screen always covers the HUD rather than the other way round.
Declaration
public const int HudSortingOrder = 500
Field Value
| Type | Description |
|---|---|
| int |
Properties
CurrentHud
The HUD currently built, or null when none is shown.
Declaration
public UnityHudDefinition CurrentHud { get; }
Property Value
| Type | Description |
|---|---|
| UnityHudDefinition |
Methods
Clear()
Destroys every built element and forgets which elements were individually hidden.
Declaration
public void Clear()
Remarks
Deliberately distinct from the teardown ShowHud(string) does internally when switching HUDs:
that one (TearDownElements) keeps Serenity.GameUi.Infrastructure.Views.UnityHudHostComponent._hiddenElementKeys so hiding an element, then
switching HUDs and back, reapplies the hidden state on rebuild. This public entry point is the
explicit "start over" — the per-element memory resets with it, for every HUD it was recorded against.
CreateDefault(string)
Builds a host GameObject stretched to fill its parent (or the whole screen, standing alone) with a
UnityHudHostComponent attached. The shipped UI prefab authors its host directly rather
than through this method; this is the single construction path UnityGameHudPresenter uses for
its self-healing fallback — a scene whose UI prefab ships no host, or a host destroyed at runtime —
so there is exactly one place that knows what a HUD host GameObject looks like.
Declaration
public static UnityHudHostComponent CreateDefault(string name = "HudHost")
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name for the created GameObject. |
Returns
| Type | Description |
|---|---|
| UnityHudHostComponent | The host, with its own RectTransform already stretched full-rect. |
GetBindingErrors()
Every element's binding error, for the validator and the diagnostics overlay.
Declaration
public IReadOnlyList<string> GetBindingErrors()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> | One message per element that cannot read its value. |
HideHud()
Hides the built elements without tearing them down.
Declaration
public void HideHud()
RegisterHud(UnityHudDefinition)
Makes a HUD switchable by id on this host.
Declaration
public void RegisterHud(UnityHudDefinition hud)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityHudDefinition | hud | The HUD to register; ignored when null or already known. |
SetDefaultHud(UnityHudDefinition)
Sets the HUD used when the state names none.
Declaration
public void SetDefaultHud(UnityHudDefinition hud)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityHudDefinition | hud | The default HUD. |
ShowHud(string)
Builds the HUD with the given id, or the default when the id is empty.
Declaration
public void ShowHud(string hudId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | hudId | The HUD to show; empty selects the default. |