tooltip positionig relative to triggering object
--HG-- branch : xesenix_upgradesrelease
parent
c4bd48ef4f
commit
0c15f75001
|
@ -1,39 +1,54 @@
|
||||||
///Credit Martin Nerurkar // www.martin.nerurkar.de // www.sharkbombs.com
|
///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/
|
///Sourced from - http://www.sharkbombs.com/2015/02/10/tooltips-with-the-new-unity-ui-ugui/
|
||||||
|
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")]
|
[AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")]
|
||||||
public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler
|
public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler
|
||||||
{
|
{
|
||||||
public string text;
|
[TextAreaAttribute]
|
||||||
|
public string text;
|
||||||
|
|
||||||
public void OnPointerEnter(PointerEventData eventData)
|
public bool useMousePosition = false;
|
||||||
{
|
|
||||||
StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f));
|
|
||||||
}
|
|
||||||
public void OnSelect(BaseEventData eventData)
|
|
||||||
{
|
|
||||||
StartHover(transform.position);
|
|
||||||
}
|
|
||||||
public void OnPointerExit(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
StopHover();
|
|
||||||
}
|
|
||||||
public void OnDeselect(BaseEventData eventData)
|
|
||||||
{
|
|
||||||
StopHover();
|
|
||||||
}
|
|
||||||
|
|
||||||
void StartHover(Vector3 position)
|
public Vector3 offset;
|
||||||
{
|
|
||||||
BoundTooltipItem.Instance.ShowTooltip(text, position);
|
public void OnPointerEnter(PointerEventData eventData)
|
||||||
}
|
{
|
||||||
void StopHover()
|
if (useMousePosition)
|
||||||
{
|
{
|
||||||
BoundTooltipItem.Instance.HideTooltip();
|
StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f));
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
StartHover(transform.position + offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnSelect(BaseEventData eventData)
|
||||||
|
{
|
||||||
|
StartHover(transform.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPointerExit(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
StopHover();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDeselect(BaseEventData eventData)
|
||||||
|
{
|
||||||
|
StopHover();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartHover(Vector3 position)
|
||||||
|
{
|
||||||
|
BoundTooltipItem.Instance.ShowTooltip(text, position);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopHover()
|
||||||
|
{
|
||||||
|
BoundTooltipItem.Instance.HideTooltip();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue