forked from Shardstone/trail-into-darkness
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
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<PopupContentBuilder> contentCallback;
|
|
bool initialized;
|
|
|
|
public PopupCategory Category => category;
|
|
|
|
public void Initialize(IPopupSystem popupSystem, Action<PopupContentBuilder> contentCallback) {
|
|
this.popupSystem = popupSystem;
|
|
this.contentCallback = contentCallback;
|
|
initialized = true;
|
|
}
|
|
|
|
public void Initialize(IPopupSystem popupSystem, PopupCategory category, Action<PopupContentBuilder> contentCallback) {
|
|
this.popupSystem = popupSystem;
|
|
this.category = category;
|
|
this.contentCallback = contentCallback;
|
|
initialized = true;
|
|
}
|
|
|
|
public void UpdateContent(Action<PopupContentBuilder> 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);
|
|
}
|
|
}
|
|
}
|