TooltipTrigger.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.EventSystems;
  6. namespace KairoEngine.UI.Tooltips
  7. {
  8. public class TooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  9. {
  10. private static LTDescr delay;
  11. public string header;
  12. public string content;
  13. public string tooltipType = "";
  14. public void OnPointerEnter(PointerEventData eventData)
  15. {
  16. if(MouseInputUIBlocker.BlockedByUI) return;
  17. if(string.IsNullOrEmpty(header) && string.IsNullOrEmpty(content)) return;
  18. delay = LeanTween.delayedCall(TooltipSystem.GetDelay(), () =>
  19. {
  20. TooltipSystem.Show(content, header, tooltipType);
  21. });
  22. }
  23. public void OnPointerExit(PointerEventData eventData)
  24. {
  25. if(delay != null) LeanTween.cancel(delay.uniqueId);
  26. TooltipSystem.Hide();
  27. }
  28. public void OnMouseEnter()
  29. {
  30. if(MouseInputUIBlocker.BlockedByUI) return;
  31. if(string.IsNullOrEmpty(header) && string.IsNullOrEmpty(content)) return;
  32. delay = LeanTween.delayedCall(TooltipSystem.GetDelay(), () =>
  33. {
  34. TooltipSystem.Show(content, header, tooltipType);
  35. });
  36. }
  37. public void OnMouseExit()
  38. {
  39. if(delay != null) LeanTween.cancel(delay.uniqueId);
  40. TooltipSystem.Hide();
  41. }
  42. }
  43. }