HotBarSlotUI
Individual hotbar slot UI element. Displays an item icon and toggles between normal/active background sprites to indicate the currently selected slot.
Definition
Namespace: Paragon.Townskeep.HUD
Assembly: Townskeep.dll
public class HotBarSlotUI : ParagonUIBehaviourInheritance: SerializedMonoBehaviour → ParagonBehaviour → ParagonUIBehaviour → HotBarSlotUI
Remarks
HotBarSlotUI represents a single slot in the hotbar. It manages two visual concerns:
Selection state — Swaps the background
Imagesprite betweenNormalandActiveto indicate whether this slot is currently selected.Item display — Shows or hides an item icon
Imageand sets it to the item'sIconsprite.
The component expects a specific child hierarchy (found via transform.Find in Awake()):
A child named
"Background"with anImagecomponentA child named
"Item"with anImagecomponent
HotBarSlotUI is driven by HotBarHUD, which discovers all slot children via GetComponentsInChildren<HotBarSlotUI>() and calls the appropriate methods when inventory or selection state changes.
Quick Lookup
Show an item in the slot
slot.SetItem(item)
Clear the slot
slot.Clear()
Highlight as selected
slot.OnActivated()
Remove selection highlight
slot.OnDeactivated()
Fields
Normal
Background sprite for the unselected state.
Active
Background sprite for the selected state.
Methods
Awake
Resolves the Background and Item child Image components via transform.Find().
OnActivated
Sets the background sprite to Active, indicating this slot is the current selection.
OnDeactivated
Sets the background sprite to Normal, indicating this slot is no longer selected.
SetItem
Displays an item in the slot by activating the icon GameObject and setting the sprite to the item's Icon.
item
Item
The item to display
amount
int
Item amount (currently unused visually, default: 1)
The amount parameter is accepted but not currently rendered. The slot displays the item icon only, without a quantity label.
Clear
Hides the item icon by deactivating the icon GameObject and resetting its sprite to the background sprite.
Common Pitfalls
Child hierarchy must match expected names
Awake() uses transform.Find("Background") and transform.Find("Item") to resolve Image components. If these children are missing or named differently, NullReferenceException will occur.
Normal and Active sprites must be assigned
The Normal and Active sprite fields are public but not validated. If unassigned, OnActivated() / OnDeactivated() will set the background sprite to null, causing a blank image.
See Also
HotBarHUD — parent element that manages all slots
HUDElement — base class for HUD panels
Item — the item type displayed in slots
Last updated