using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace MoreMountains.Tools
{
///
/// A simple helper class you can use to trigger methods on Unity's pointer events
/// Typically used on a UI Image
///
public class MMOnPointer : MonoBehaviour, IPointerDownHandler, IPointerEnterHandler, IPointerUpHandler, IPointerExitHandler, IPointerClickHandler
{
[Header("Pointer movement")]
/// an event to trigger when the pointer enters the associated game object
[Tooltip("an event to trigger when the pointer enters the associated game object")]
public UnityEvent PointerEnter;
/// an event to trigger when the pointer exits the associated game object
[Tooltip("an event to trigger when the pointer exits the associated game object")]
public UnityEvent PointerExit;
[Header("Clicks")]
/// an event to trigger when the pointer is pressed down on the associated game object
[Tooltip("an event to trigger when the pointer is pressed down on the associated game object")]
public UnityEvent PointerDown;
/// an event to trigger when the pointer is pressed up on the associated game object
[Tooltip("an event to trigger when the pointer is pressed up on the associated game object")]
public UnityEvent PointerUp;
/// an event to trigger when the pointer is clicked on the associated game object
[Tooltip("an event to trigger when the pointer is clicked on the associated game object")]
public UnityEvent PointerClick;
///
/// IPointerEnterHandler implementation
///
///
public void OnPointerEnter(PointerEventData eventData)
{
PointerEnter?.Invoke();
}
///
/// IPointerExitHandler implementation
///
///
public void OnPointerExit(PointerEventData eventData)
{
PointerExit?.Invoke();
}
///
/// IPointerDownHandler implementation
///
///
public void OnPointerDown(PointerEventData eventData)
{
PointerDown?.Invoke();
}
///
/// IPointerUpHandler implementation
///
///
public void OnPointerUp(PointerEventData eventData)
{
PointerUp?.Invoke();
}
///
/// IPointerClickHandler implementation
///
///
public void OnPointerClick(PointerEventData eventData)
{
PointerClick?.Invoke();
}
}
}