com.unity.uiextensions/Scripts/BoundTooltip/BoundTooltipItem.cs

57 lines
1.4 KiB
C#
Raw Normal View History

///Credit Martin Sharkbomb
///Sourced from - http://forum.unity3d.com/threads/tooltips.264395/#post-1957075
namespace UnityEngine.UI.Extensions
{
[AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Item")]
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)
instance = GameObject.FindObjectOfType<BoundTooltipItem>();
return instance;
}
}
}
}