GBA.Unity/Assets/emulator/KeyMappingButton.cs

40 lines
879 B
C#
Raw Permalink Normal View History

2024-08-16 14:51:15 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public enum GBAKeyCode
{
Start,
Select,
Left,
Right,
Up,
Down,
A,
B,
L,
R,
}
public class KeyMappingButton : Button, IPointerDownHandler, IPointerUpHandler
{
public bool pressed { private set; get; }
public GBAKeyCode keyCode { private set; get; }
protected override void Awake()
{
pressed = false;
//keyCode = System.Enum.Parse<GBAKeyCode>(gameObject.name);
keyCode = (GBAKeyCode)System.Enum.Parse(keyCode.GetType(),gameObject.name);
}
public override void OnPointerDown(PointerEventData eventData)
{
base.OnPointerDown(eventData);
pressed = true;
}
public override void OnPointerUp(PointerEventData eventData)
{
base.OnPointerUp(eventData);
pressed = false;
}
}