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 OnPointerExit(PointerEventData eventData) { if(delay != null) LeanTween.cancel(delay.uniqueId); TooltipSystem.Hide(); visible = false; } 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 OnMouseExit() { 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; } }); } } }