using System; using UnityEngine; using UnityEngine.EventSystems; namespace Jovian.PopupSystem.UI { public class PopupTrigger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { [SerializeField] PopupCategory category; [SerializeField] AnchorSide anchorSide = AnchorSide.Below; [SerializeField] PopupPositionMode positionMode = PopupPositionMode.AnchorToElement; IPopupSystem popupSystem; Action contentCallback; bool initialized; public PopupCategory Category => category; public void Initialize(IPopupSystem popupSystem, Action contentCallback) { this.popupSystem = popupSystem; this.contentCallback = contentCallback; initialized = true; } public void Initialize(IPopupSystem popupSystem, PopupCategory category, Action contentCallback) { this.popupSystem = popupSystem; this.category = category; this.contentCallback = contentCallback; initialized = true; } public void UpdateContent(Action contentCallback) { this.contentCallback = contentCallback; } public void OnPointerEnter(PointerEventData eventData) { if(!initialized || popupSystem == null || contentCallback == null) { return; } if(positionMode == PopupPositionMode.AnchorToElement) { popupSystem.Show(category, contentCallback, (RectTransform)transform, anchorSide); } else { popupSystem.Show(category, contentCallback); } } public void OnPointerExit(PointerEventData eventData) { if(!initialized || popupSystem == null) { return; } popupSystem.Hide(category); } } }