# Minimal HUD

A worked example of what the UI Creator compiler emits, and of the hand written code that sits
beside it. Import it with Package Manager > UI Creator Runtime > Samples > Minimal HUD.

## Layout

```
Generated/            everything the compiler owns, rewritten on every export
  Hud.uxml
  Hud.uss
  HudScreen.g.cs      the screen class
  HudActions.g.cs     action name constants and typed subscribe helpers
  UgxScreenFactory.g.cs  key to class switch, installed on load
HudScreen.cs          the other half of the partial class: your code, never regenerated
HudDataSource.cs      a hand written data source plus a driver component
```

In a real project the compiler writes `Generated/` into `Assets/<UiFolder>/Generated/Screens/Hud/`
and the registry asset into `Assets/<UiFolder>/Generated/Resources/UgxScreenRegistry.asset`.

## Running it

1. Add a `UIDocument` to a GameObject and give it a `PanelSettings`.
2. Add `UgxDocument` next to it and set **Screen Key** to `Hud`.
3. Add `MinimalHudDriver` to the same GameObject and drag it into **Data Source Object**.
4. Enter play mode. Health falls, the bar shrinks, and under 25% the warning fades in and pulses.

## The contract, in one place

- `HudScreen` derives from `UgxScreen`, is `partial`, and exposes `public const string Key`.
- Typed element properties are resolved in `AttachElements` through `Q<T>(name)`, which throws a
  message naming the screen and the element when the UXML no longer has it.
- Tables are `static readonly` arrays so a screen instance carries no per instance setup cost.
- `ConnectBindings`, `ConnectActions` and `ConnectEffects` each forward one table to the runtime.
- The four `partial void` hooks are called from the matching `OnScreen*` overrides.
- `UgxScreenFactory` installs itself on load, in the player and in the editor.

Two things worth copying into the compiler:

- **Binding paths are the data source's own member names**, with no screen or source prefix.
  `UgxSchemaWalker` reports `hp`, not `player.hp`, and `Notify()` raises `hp`, so a prefixed path
  resolves against nothing and the binding fails on every update.
- **A data source must be able to announce a change.** Derive from `UgxDataSource`, use
  `UgxDictionaryDataSource`, or forward `INotifyBindablePropertyChanged` the way
  `MinimalHudDriver` does. A source that only implements `IUgxDataSource` renders once and then
  freezes; the connector logs a warning when it sees one.
