Tooltip

Easily create a nicely looking tooltip.

Simple Usage

Attach the component to any GameObject and assign the required fields.

After configuring your tooltip, create a prefab of it and assign it to the Tooltip Manager.

Make sure the line styles are configured in the Tooltip Manager.

The visibility of the tooltip is controlled by a CanvasGroup alpha value.

To display a tooltip you could use the Tooltip Show component or via code.

Code Usage

Always call the InstantiateIfNecessary(GameObject go) method before using the static methods. This will make sure you have the tooltip instantiated in the current canvas.

Use the Show() and Hide() methods to toggle the visibility of the tooltip.

Every time the tooltip hides the text lines are cleared.

If you instantiate a tooltip into the scene manually that instance is going to be used for that scene.

The tooltip is designed to work with a single instance and most methods are static.

public void OnTooltip(bool show)
{
    // Check if we have the instance of the manager
    if (UITooltipManager.Instance == null)
        return;
        
    // If we are showing the tooltip
    if (show)
    {
        UITooltip.InstantiateIfNecessary(this.gameObject);
        
        // Add a simple title line
        UITooltip.AddTitle("Tooltip Title");
        
        // Add a spacer
        UITooltip.AddSpacer();
        
        // Add a simple line of text
        UITooltip.AddLine("A line of text");
        
        // Add columns of text
        UITooltip.AddLineColumn("Left column text");
        UITooltip.AddLineColumn("Right column text");
        
        // Add description line
        UITooltip.AddDescription("Some very simple description");
        
        // You can set the tooltip width
        UITooltip.SetWidth(512f);

        // You can set the tooltip horizontal fit mode
        UITooltip.SetHorizontalFitMode(ContentSizeFitter.FitMode.PreferredSize);

        // You can anchor the tooltip to a transform
        UITooltip.AnchorToRect(this.transform as RectTransform);

        // You can override the tooltip offset
        UITooltip.OverrideOffset(Vector2.zero);
        UITooltip.OverrideAnchoredOffset(Vector2.zero);

        // Show the tooltip
        UITooltip.Show();
    }
    else
    {
        // Hide the tooltip
        UITooltip.Hide();
    }
}

Static Methods

Name Value Summary
AddTitle(string) void
Adds title line.
static
AddDescription(string) void
Adds description line.
static
AddLine(string) void
Adds a new single column line.
static
AddLine(string, RectOffset) void
Adds a new single column line.
static
AddLine(string, RectOffset, string) void
Adds a new single column line.
static
AddLine(string, RectOffset, UITooltipLines.LineStyle) void
Adds a new single column line.
static
AddLine(string, string) void
Adds a new single column line.
static
AddLine(string, UITooltipLines.LineStyle) void
Adds a new single column line.
static
AddLineColumn(string) void
Adds a column (Either to the last line if it's not complete or to a new one).
static
AddLineColumn(string, string) void
Adds a column (Either to the last line if it's not complete or to a new one).
static
AddLineColumn(string, UITooltipLines.LineStyle) void
Adds a column (Either to the last line if it's not complete or to a new one).
static
AddSpacer() void
Adds a spacer line.
static
AnchorToRect(RectTransform) void
Anchors the tooltip to a rect.
static
Show() void
Show the tooltip.
static
Hide() void
Hide the tooltip.
static
InstantiateIfNecessary(GameObject) void
Instantiate the tooltip game object if necessary.
static
OverrideAnchoredOffset(Vector2) void
Overrides the anchored offset for single display of the tooltip.
static
OverrideOffset(Vector2) void
Overrides the offset for single display of the tooltip.
static
SetHorizontalFitMode(ContentSizeFitter.FitMode) void
Sets the horizontal fit mode of the tooltip.
static
SetLines(UITooltipLines) void
Sets the lines template.
static
SetWidth(float) void
Sets the width of the toolip.
static