2015-02-27 04:42:26 +08:00
|
|
|
|
///Credit Martin Nerurkar // www.martin.nerurkar.de // www.sharkbombs.com
|
|
|
|
|
///Sourced from - http://www.sharkbombs.com/2015/02/10/tooltips-with-the-new-unity-ui-ugui/
|
2015-02-11 04:56:12 +08:00
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
2018-11-26 08:56:54 +08:00
|
|
|
|
[AddComponentMenu("UI/Extensions/Bound Tooltip/Bound Tooltip Item")]
|
2015-02-11 04:56:12 +08:00
|
|
|
|
public class BoundTooltipItem : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public bool IsActive
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return gameObject.activeSelf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UnityEngine.UI.Text TooltipText;
|
|
|
|
|
public Vector3 ToolTipOffset;
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
instance = this;
|
|
|
|
|
if(!TooltipText) TooltipText = GetComponentInChildren<Text>();
|
|
|
|
|
HideTooltip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowTooltip(string text, Vector3 pos)
|
|
|
|
|
{
|
|
|
|
|
if (TooltipText.text != text)
|
|
|
|
|
TooltipText.text = text;
|
|
|
|
|
|
|
|
|
|
transform.position = pos + ToolTipOffset;
|
|
|
|
|
|
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideTooltip()
|
|
|
|
|
{
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Standard Singleton Access
|
|
|
|
|
private static BoundTooltipItem instance;
|
|
|
|
|
public static BoundTooltipItem Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (instance == null)
|
2023-11-24 04:32:53 +08:00
|
|
|
|
{
|
|
|
|
|
#if UNITY_2023_1_OR_NEWER
|
|
|
|
|
instance = GameObject.FindFirstObjectByType<BoundTooltipItem>();
|
|
|
|
|
#else
|
2015-02-11 04:56:12 +08:00
|
|
|
|
instance = GameObject.FindObjectOfType<BoundTooltipItem>();
|
2023-11-24 04:32:53 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2015-02-11 04:56:12 +08:00
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|