Tooltip System
Guide on how to integrate tooltips with Unit System.
Overview
This page is for guiding you through the process of basic integration for Tooltip System package. Refer to the Tooltip System Guide if you need more information.
1. Setup Scene
If you do not have Tooltip System package present, then follow it's guide for import and scene setup:
Create empty object and add
TooltipManager
component or drag Tooltip Manager prefab into your scene. Check all the tabs and configure it for your project.
2. Hovering over Entities and Units
To achieve hover over units you can follow the steps on guide or:
Add
Tooltip Object
andHover Object
components to root game object of your prefabs.Then add the demo script
SetEntityTooltipInformation
which uses regularTextTooltipInformation
type of information.To see the information when hovering object, you also need a UI element to show the information on. Add Tooltip UI in your scene and reference it in the manager (with
TextTooltipInformation
type), otherwise it will not be found when manager will be search for tooltip text options.
3. Hover over UI
To achieve hovering over UI elements, the first step and last steps are the same as before:
Add
Tooltip Object
andHover Object
components to root game object of your UI prefabs (or scene defined UI, does not need to be a prefab).Then add if you are using demo prefab for UI
UnitProductionView
, then you need only to addthe demo script
UnitProductionViewTooltipInfo
. If you have a custom one, check the code example below.To see the information when hovering object, you also need a UI element to show the information on. Add Tooltip UI in your scene and reference it in the manager (with
TextTooltipInformation
type), otherwise it will not be found when manager will be search for tooltip text options.
Custom UI
You can use custom UI Action element for production or any other action defined by your entities and units. If you are unfamiliar with this see the IEntityUIHandler
or AUnitUIHandler
which is responsible for feeding it to the UI.
public class MyCustomUIElement : AEntityActionUIElement
{
[SerializeField] private UnityEngine.UI.Button button;
private ProductionAction _productionAction;
private IEntity _entity;
private void Awake()
{
button.onClick.AddListener(HandleClick);
}
public override void Configure(IEntity entity)
{
// Save reference
_entity = entity;
}
public override void SetAction(IEntityUIAction action)
{
// Here you should cast to the action which you are using on your UI.
// Demo scene uses the ProductionAction which is the default one for production that
// may also be defined on Faction itself.
if (action is not ProductionAction productionAction) return;
// Save reference
_productionAction = productionAction;
var producible = productionAction.ProducibleQuantity.Producible;
var text = producible.Name + "\n" + producible.Description;
GetComponent<TooltipObject>().information = new TextTooltipInformation()
{
text = text
};
// Configure the rest of UI for the action, like icon or text.
}
public override bool CheckActionHotKey()
{
// Check for hotkey clicks (if used), return true when it is clicked.
return false;
}
private void HandleClick()
{
if (_entity != null)
{
_productionAction.Execute(_entity);
}
}
}
Last updated