UIReferenceButton - jimdroberts/FishMMO GitHub Wiki

Description

UIReferenceButton is an advanced button class for the FishMMO client UI, used by inventory, equipment, bank, and hotkey buttons. It manages reference IDs, button types, icon and text display, and tooltip interactions for items and abilities.


API Access

Fields

  • public const long NULL_REFERENCE_ID

    Constant representing a null reference ID for buttons.

  • protected UITooltip currentUITooltip

    Reference to the currently displayed tooltip instance.

  • public long ReferenceID

    ReferenceID is equal to the inventory slot, equipment slot, or ability id based on Reference Type.

  • public ReferenceButtonType Type

    The type of reference button (inventory, equipment, bank, ability, etc.).

  • public Image Icon

    The icon image displayed on the button.

  • public Sprite DefaultIconSprite

    The default icon sprite to use when no item is present.

  • public TMP_Text CooldownText

    The text displaying cooldown information.

  • public TMP_Text AmountText

    The text displaying item amount or stack size.

  • public IPlayerCharacter Character

    The player character associated with this button.

Methods

  • protected override void OnDisable()

    Called when the button is disabled. Hides any active tooltip.

  • public virtual void OnLeftClick()

    Called when the left mouse button is clicked. Override for custom logic.

  • public virtual void OnRightClick()

    Called when the right mouse button is clicked. Override for custom logic.

  • public override void OnPointerEnter(PointerEventData eventData)

    Handles pointer enter event to show tooltip for the referenced item or ability. Parameters: PointerEventData eventData – Pointer event data.

  • public virtual void ShowTooltip(long referenceID)

    Shows the tooltip for the referenced item, equipment, bank item, or ability based on button type. Parameters: long referenceID – Reference ID to look up tooltip data.

  • public override void OnPointerExit(PointerEventData eventData)

    Handles pointer exit event to hide tooltip. Parameters: PointerEventData eventData – Pointer event data.

  • public override void OnPointerClick(PointerEventData eventData)

    Handles pointer click event, invoking left or right click logic. Parameters: PointerEventData eventData – Pointer event data.

  • private void ClearTooltip()

    Hides the currently displayed tooltip, if any.

  • public virtual void Clear()

    Clears the button state, resets icon and text, and hides tooltip.


Basic Usage

Setup

  1. Attach UIReferenceButton to a UI Button GameObject.
  2. Assign the Icon, DefaultIconSprite, CooldownText, and AmountText fields in the Inspector.
  3. Set the Character property to the player character instance.
  4. Set the ReferenceID and Type as needed for the button's function.

Example

// Example: Setting up a UIReferenceButton for an inventory slot
UIReferenceButton button = GetComponent<UIReferenceButton>();
button.Icon = ...; // Assign Image
button.DefaultIconSprite = ...; // Assign Sprite
button.CooldownText = ...; // Assign TMP_Text
button.AmountText = ...; // Assign TMP_Text
button.Character = playerCharacter;
button.ReferenceID = 5; // Inventory slot 5
button.Type = ReferenceButtonType.Inventory;

Best Practices

  • Always assign all serialized fields in the Inspector to avoid null references.
  • Override OnLeftClick and OnRightClick for custom button logic.
  • Use the correct ReferenceButtonType for each button to ensure proper tooltip and logic handling.
  • Call Clear() when resetting or reusing buttons to avoid stale data or tooltips.
⚠️ **GitHub.com Fallback** ⚠️