You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
972 B
C#
42 lines
972 B
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Events;
|
|
|
|
public class UIVirtualButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
|
|
{
|
|
[System.Serializable]
|
|
public class BoolEvent : UnityEvent<bool> { }
|
|
[System.Serializable]
|
|
public class Event : UnityEvent { }
|
|
|
|
[Header("Output")]
|
|
public BoolEvent buttonStateOutputEvent;
|
|
public Event buttonClickOutputEvent;
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
OutputButtonStateValue(true);
|
|
}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
OutputButtonStateValue(false);
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
OutputButtonClickEvent();
|
|
}
|
|
|
|
void OutputButtonStateValue(bool buttonState)
|
|
{
|
|
buttonStateOutputEvent.Invoke(buttonState);
|
|
}
|
|
|
|
void OutputButtonClickEvent()
|
|
{
|
|
buttonClickOutputEvent.Invoke();
|
|
}
|
|
|
|
}
|