UIInventoryButton - jimdroberts/FishMMO GitHub Wiki
UI button representing a single inventory slot. Handles drag-and-drop assignment, swapping items between slots, unequipping equipment to inventory, right-click activation, and clearing slot visuals.
-
(inherits fields from UIReferenceButton)
This class extends
UIReferenceButton
and reuses its Icon, AmountText, CooldownText and reference handling behavior.
-
public override void OnLeftClick()
Handles left-click and drag-and-drop interactions: swaps items between inventory slots, unequips equipment to inventory if applicable, or begins dragging the current slot if empty.
-
public override void OnRightClick()
Activates the inventory item via
IInventoryController.Activate
when right-clicked. -
public override void Clear()
Clears the button visuals: icon, cooldown text, and amount text.
- Use
UIInventoryButton
as the button prefab for inventory slots and ensure it is configured as aReferenceButtonType.Inventory
on instantiation. - Provide
Icon
,AmountText
, andCooldownText
viaUIReferenceButton
base class references in the prefab. - Ensure
IInventoryController
andUIDragObject
UI systems are available and wired up at runtime for swap and drag behavior to work.
var btn = Instantiate(inventoryButtonPrefab, parent).GetComponent<UIInventoryButton>();
btn.Character = playerCharacter;
btn.ReferenceID = slotIndex;
btn.Type = ReferenceButtonType.Inventory;
// Dragging and clicking the button will be handled by the component.
- Validate references in the chore that creates inventory buttons to avoid null icons or texts.
- Keep
OnLeftClick
logic concise; it runs as part of UI interactions and triggers network broadcasts. - Ensure controller methods like
CanSwapItemSlots
are robust to prevent invalid swap broadcasts. - Use server-side validation for inventory actions; the UI should only suggest intent (it broadcasts requests, server enforces rules).