From 0c15f750010589224850ab757d29323125711aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C4=B9=E2=80=9A=20Kapalla?= Date: Sat, 17 Oct 2015 18:30:30 +0200 Subject: [PATCH] tooltip positionig relative to triggering object --HG-- branch : xesenix_upgrades --- Scripts/BoundTooltip/BoundTooltipTrigger.cs | 93 ++++++++++++--------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/Scripts/BoundTooltip/BoundTooltipTrigger.cs b/Scripts/BoundTooltip/BoundTooltipTrigger.cs index 9776722..415d70e 100644 --- a/Scripts/BoundTooltip/BoundTooltipTrigger.cs +++ b/Scripts/BoundTooltip/BoundTooltipTrigger.cs @@ -1,39 +1,54 @@ -///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/ - -using UnityEngine.EventSystems; - -namespace UnityEngine.UI.Extensions -{ - [AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")] - public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler - { - public string text; - - public void OnPointerEnter(PointerEventData eventData) - { - 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) - { - BoundTooltipItem.Instance.ShowTooltip(text, position); - } - void StopHover() - { - BoundTooltipItem.Instance.HideTooltip(); - } - } -} +///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/ +using UnityEngine.EventSystems; + +namespace UnityEngine.UI.Extensions +{ + [AddComponentMenu("UI/Extensions/Bound Tooltip/Tooltip Trigger")] + public class BoundTooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler + { + [TextAreaAttribute] + public string text; + + public bool useMousePosition = false; + + public Vector3 offset; + + public void OnPointerEnter(PointerEventData eventData) + { + if (useMousePosition) + { + 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(); + } + } +}