TooltipTrigger.cs 1.6 KB

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