UITooltip - jimdroberts/FishMMO GitHub Wiki

Description

UITooltip is a UI control in the FishMMO client that displays a tooltip with text near the mouse cursor. It updates its position each frame to follow the mouse and adjusts its offset to stay on screen.


API Access

Fields

  • public TMP_Text Text

    The text component used to display the tooltip content.

  • public RectTransform Background

    The background RectTransform for positioning and sizing the tooltip.

Methods

  • void Update()

    Updates the tooltip position each frame to follow the mouse, adjusting vertical offset if near the top or bottom of the screen.

  • public void Open(string text)

    Opens the tooltip with the specified text, positions it near the mouse, and shows it. Parameters: string text – Text to display in the tooltip.


Basic Usage

Setup

  1. Attach UITooltip to a UI GameObject in the Unity Editor.
  2. Assign the Text and Background fields in the Inspector.
  3. Call Open() to display a tooltip with the desired text.

Example

// Example: Showing a tooltip on mouse hover
UITooltip tooltip = GetComponent<UITooltip>();
tooltip.Text = ...; // Assign TMP_Text
tooltip.Background = ...; // Assign RectTransform
// To show a tooltip:
tooltip.Open("This is a tooltip!");

Best Practices

  • Always assign the Text and Background fields in the Inspector to avoid null references.
  • Use the Open() method to display tooltips with dynamic content.
  • Ensure the tooltip stays within screen bounds by using the provided offset logic.
⚠️ **GitHub.com Fallback** ⚠️