using UnityEngine;
using UnityEngine.EventSystems;
namespace CnControls
{
///
/// Simple button class
/// Handles press, hold and release, just like a normal button
///
public class SimpleButton : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
///
/// The name of the button
///
public string ButtonName = "Jump";
///
/// Utility object that is registered in the system
///
private VirtualButton _virtualButton;
///
/// It's pretty simple here
/// When we enable, we register our button in the input system
///
private void OnEnable()
{
_virtualButton = _virtualButton ?? new VirtualButton(ButtonName);
CnInputManager.RegisterVirtualButton(_virtualButton);
}
///
/// When we disable, we unregister our button
///
private void OnDisable()
{
CnInputManager.UnregisterVirtualButton(_virtualButton);
}
///
/// uGUI Event system stuff
/// It's also utilised by the editor input helper
///
/// Data of the passed event
public void OnPointerUp(PointerEventData eventData)
{
_virtualButton.Release();
}
///
/// uGUI Event system stuff
/// It's also utilised by the editor input helper
///
/// Data of the passed event
public void OnPointerDown(PointerEventData eventData)
{
_virtualButton.Press();
}
}
}