gimm270_07_photogallery/Assets/StarterAssets/Mobile/Scripts/VirtualInputs/UIVirtualButton.cs

42 lines
1,013 B
C#
Raw Normal View History

2022-09-18 19:41:47 -06:00
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();
}
}