12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- using Sirenix.OdinInspector;
- using KairoEngine.Core;
- namespace KairoEngine.UI.Tooltips
- {
- [HideMonoScript]
- public class TooltipTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
- {
- private static LTDescr delay;
- public string header;
- public string content;
- public string tooltipType = "";
- private bool visible = false;
- public void OnPointerEnter(PointerEventData eventData)
- {
- if(MouseInputUIBlocker.BlockedByUI) return;
- if(string.IsNullOrEmpty(header) && string.IsNullOrEmpty(content)) return;
- delay = LeanTween.delayedCall(TooltipSystem.GetDelay(), () =>
- {
- TooltipSystem.Show(content, header, tooltipType);
- visible = true;
- CheckTooltip();
- });
-
- }
- public void OnMouseEnter()
- {
- if(MouseInputUIBlocker.BlockedByUI) return;
- if(string.IsNullOrEmpty(header) && string.IsNullOrEmpty(content)) return;
- delay = LeanTween.delayedCall(TooltipSystem.GetDelay(), () =>
- {
- TooltipSystem.Show(content, header, tooltipType);
- visible = true;
- CheckTooltip();
- });
-
- }
- public void OnPointerExit(PointerEventData eventData) => DisableTooltip();
- public void OnMouseExit() => DisableTooltip();
- private void OnDisable() => DisableTooltip();
- private void OnDestroy() => DisableTooltip();
- public void DisableTooltip()
- {
- if(delay != null) LeanTween.cancel(delay.uniqueId);
- TooltipSystem.Hide();
- visible = false;
- }
- private void CheckTooltip()
- {
- TooltipTrigger t = this;
- if(t.visible == false) return;
- Timer.ExecuteRealTime(500, () => {
- if(t == null)
- {
- TooltipSystem.Hide();
- return;
- }
- if(t.gameObject == null)
- {
- t.visible = false;
- TooltipSystem.Hide();
- return;
- }
- if(!t.gameObject.activeSelf)
- {
- t.visible = false;
- TooltipSystem.Hide();
- return;
- }
- if(t.gameObject.activeSelf && t.visible == true)
- {
- CheckTooltip();
- return;
- }
- });
- }
- }
- }
|