HUD

Component-based heads-up display framework. HUD acts as a root container that auto-discovers HUDElement children via GetComponentsInChildren, initializes them, and manages their activation lifecycle. Subclass HUDElement to create new HUD panels — the system handles discovery, initialization, and type-safe retrieval automatically.

Architecture

spinner

Data Flow

spinner

Key Concepts

Concept
Description

HUD

Root MonoBehaviour that discovers and manages all HUDElement children. One per HUD hierarchy.

HUDElement

Abstract base class for individual HUD panels. Subclass to create new panels.

Type-keyed dictionary

Elements are stored by their concrete Type, enabling TryGetHUDElement<T>() for type-safe retrieval.

Lifecycle callbacks

OnActivated() / OnDisabled() are called on all elements when the HUD is toggled.

Quick Start

1. Create a HUD element

using Paragon.Townskeep.HUD;

public class HealthBarHUD : HUDElement
{
    public override void OnActivated()
    {
        // Refresh health display when HUD becomes active
        UpdateHealthBar();
    }

    public override void OnDisabled()
    {
        // Cleanup when HUD is hidden
    }

    private void UpdateHealthBar() { /* ... */ }
}

2. Hierarchy setup

Place the HUD component on a root UI GameObject. Add HUDElement subclasses as children anywhere in the hierarchy — they are discovered via GetComponentsInChildren.

3. Access elements at runtime

Classes

Class
Description

Root container — discovers, initializes, and manages HUD elements

Abstract base class for HUD panels

Subsystems

Subsystem
Description

Chat window, input field, tabs, and message display

See Also

Last updated