Skip to content

Game.UI.Tooltip.TooltipUISystem

Assembly:
Namespace: Game.UI.Tooltip

Type: public class

Base: UISystemBase

Summary:
Manages tooltip UI presentation for the game. The system collects tooltip groups produced by other systems each frame, binds them to the UI widget hierarchy under the "tooltip" group, and handles a special "mouse" tooltip group that follows the cursor. It coordinates tooltip updates via the game's UpdateSystem (SystemUpdatePhase.UITooltip) and respects UI hit-testing (does not show tooltips while the cursor is over UI).


Fields

  • private const string kGroup = "tooltip"
    Identifier used for the WidgetBindings group name; the system creates bindings scoped to this group.

  • private static readonly float2 kTooltipPointerDistance
    Offset (0, 16) applied to the mouse-based tooltip position so the tooltip appears slightly below the cursor.

  • private UpdateSystem m_UpdateSystem
    Cached reference to the game's UpdateSystem used to drive the UITooltip update phase so other systems can populate tooltip data.

  • private WidgetBindings m_WidgetBindings
    WidgetBindings instance created for "tooltip" -> "groups". Used to supply child tooltip groups to the UI widget layer.

Properties

  • public override GameMode gameMode => GameMode.GameOrEditor
    Specifies that this UISystem is active in both Game and Editor modes.

  • public List<TooltipGroup> groups { get; private set; }
    A list populated each frame (by other systems during the UITooltip phase) with tooltip groups that should be rendered. The system clears and reuses this list every update.

  • public TooltipGroup mouseGroup { get; private set; }
    A special TooltipGroup reserved for mouse-following tooltips. If populated during the UITooltip phase and the mouse is on-screen, the system positions this group near the cursor (plus kTooltipPointerDistance) and adds it to the widget bindings.

Constructors

  • public TooltipUISystem()
    Default constructor. Marked with [Preserve] in the source to avoid stripping by Unity. Initialization happens in OnCreate.

Methods

  • protected override void OnCreate()
    [Preserve] Initializes the system:
  • Obtains/creates the UpdateSystem reference from the world.
  • Creates a WidgetBindings instance for the "tooltip" widget group and registers it with AddUpdateBinding.
  • Initializes the groups list.
  • Initializes mouseGroup with default values (path = "mouse", position = (0,0), horizontalAlignment = Start, verticalAlignment = Start).

  • protected override void OnUpdate()
    [Preserve] Runs every frame and performs the following when widget bindings are active:

  • Clears existing binding children, groups list, and mouseGroup.children.
  • If the cursor is not over UI:
    • Calls m_UpdateSystem.Update(SystemUpdatePhase.UITooltip) so other systems can populate tooltip data into this system's groups and mouseGroup.
    • If the mouse is on-screen and mouseGroup has children, computes mouseGroup.position from InputManager.instance.mousePosition (converting screen Y to UI coordinates) plus kTooltipPointerDistance, and adds mouseGroup to the widget binding children.
    • Adds all other tooltip groups (groups list) to the widget binding children.
  • Calls base.OnUpdate().

Usage Example

// Example: add a custom tooltip group from another system during the UITooltip update phase.
// This code might run inside a system that runs during SystemUpdatePhase.UITooltip.

using Unity.Mathematics;

// Get the tooltip system (World here refers to the system's World)
var tooltipSystem = World.GetOrCreateSystemManaged<Game.UI.Tooltip.TooltipUISystem>();

// Create and populate a TooltipGroup (fields shown are the typical ones used by TooltipUISystem)
var myGroup = new TooltipGroup
{
    path = "my_custom_group",
    position = new float2(200f, 400f),
    horizontalAlignment = TooltipGroup.Alignment.Center,
    verticalAlignment = TooltipGroup.Alignment.Top
};

// Add tooltip entries to the group's children (Tooltip entry type and fields depend on the game's tooltip model)
myGroup.children.Add(new TooltipEntry { /* fill text, icons, styles, etc. */ });

// Register the group so TooltipUISystem will display it this frame
tooltipSystem.groups.Add(myGroup);

// For mouse-following tooltips, populate tooltipSystem.mouseGroup.children during the UITooltip phase;
// TooltipUISystem will position it relative to the cursor and add the group automatically.