HotBarHUD

HUDElement that displays the player's inventory hotbar slots. Subscribes to the possessed character's CharacterInventory to reflect item changes and selection state in real time.

Definition

Namespace: Paragon.Townskeep.HUD Assembly: Townskeep.dll

public class HotBarHUD : HUDElement

Inheritance: SerializedMonoBehaviourParagonBehaviourParagonUIBehaviourHUDElement → HotBarHUD

Remarks

HotBarHUD bridges the inventory data model and the UI slot display. It discovers HotBarSlotUI children in Awake() and auto-selects slot 0 in Start().

Activation Flow

When the HUD is activated (OnActivated()), the component:

  1. Gets the current player's possessed Character via Player.Current.TryGetPossession<Character>()

  2. Subscribes to character.Inventory.Inventory.OnInventoryChanged for item add/remove/change events

  3. Subscribes to character.Inventory.CurrentSelectionChanged for selection highlight changes

Item Display

When the inventory fires OnInventoryChanged(index, item, amount):

  • If item is not null → slots[index].SetItem(item, amount) (shows the item icon)

  • If item is null → slots[index].Clear() (hides the icon)

Selection

SetSelection(int) deactivates the previous slot's highlight and activates the new one. Each HotBarSlotUI swaps between its Normal and Active background sprites.

Quick Lookup

Goal
How

Get current selection index

hotbar.CurrentSelection

Set selection programmatically

hotbar.SetSelection(index)

Access from HUD

hud.TryGetHUDElement<HotBarHUD>(out var hotbar)

Properties

Property
Type
Description

CurrentSelection

int

Index of the currently selected hotbar slot

Methods

OnActivated (override)

Subscribes to the possessed character's inventory change and selection change events.

Behavior:

  1. Calls Player.Current.TryGetPossession<Character>() to get the current character

  2. Subscribes to character.Inventory.Inventory.OnInventoryChanged

  3. Subscribes to character.Inventory.CurrentSelectionChanged

SetSelection

Switches the visual selection highlight from the current slot to the new one.

Parameter
Type
Description

selection

int

Index of the slot to select

Behavior:

  1. Calls OnDeactivated() on the previously selected HotBarSlotUI

  2. Updates currentSelection to the new index

  3. Calls OnActivated() on the newly selected HotBarSlotUI

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

Examples

Accessing the Hotbar from Game Code

Hierarchy Setup

See Also

Last updated