tooltip positionig relative to triggering object

--HG--
branch : xesenix_upgrades
pull/413/head
Paweł Kapalla 2015-10-17 18:30:30 +02:00
parent c4bd48ef4f
commit 0c15f75001
1 changed files with 54 additions and 39 deletions

View File

@ -1,6 +1,5 @@
///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
@ -8,20 +7,35 @@ 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
{ {
[TextAreaAttribute]
public string text; public string text;
public bool useMousePosition = false;
public Vector3 offset;
public void OnPointerEnter(PointerEventData eventData) public void OnPointerEnter(PointerEventData eventData)
{
if (useMousePosition)
{ {
StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f)); StartHover(new Vector3(eventData.position.x, eventData.position.y, 0f));
} }
else
{
StartHover(transform.position + offset);
}
}
public void OnSelect(BaseEventData eventData) public void OnSelect(BaseEventData eventData)
{ {
StartHover(transform.position); StartHover(transform.position);
} }
public void OnPointerExit(PointerEventData eventData) public void OnPointerExit(PointerEventData eventData)
{ {
StopHover(); StopHover();
} }
public void OnDeselect(BaseEventData eventData) public void OnDeselect(BaseEventData eventData)
{ {
StopHover(); StopHover();
@ -31,6 +45,7 @@ namespace UnityEngine.UI.Extensions
{ {
BoundTooltipItem.Instance.ShowTooltip(text, position); BoundTooltipItem.Instance.ShowTooltip(text, position);
} }
void StopHover() void StopHover()
{ {
BoundTooltipItem.Instance.HideTooltip(); BoundTooltipItem.Instance.HideTooltip();