2024-04-10 09:44:23 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
public class OnButtonPress : MonoBehaviour
|
|
|
|
{
|
|
|
|
[Tooltip("Actions to check")]
|
2024-09-23 17:11:21 +02:00
|
|
|
public InputAction actionA = null;
|
|
|
|
public UnityEvent OnPressA = new UnityEvent();
|
2024-04-10 09:44:23 +02:00
|
|
|
|
2024-09-23 17:11:21 +02:00
|
|
|
public InputAction actionB = null;
|
|
|
|
public UnityEvent OnPressB = new UnityEvent();
|
|
|
|
|
|
|
|
public InputAction actionX = null;
|
|
|
|
public UnityEvent OnPressX = new UnityEvent();
|
|
|
|
|
|
|
|
public InputAction actionY = null;
|
|
|
|
public UnityEvent OnPressY = new UnityEvent();
|
2024-04-10 09:44:23 +02:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
2024-09-23 17:11:21 +02:00
|
|
|
actionA.started += ButtonAPressed;
|
|
|
|
actionB.started += ButtonBPressed;
|
|
|
|
actionX.started += ButtonXPressed;
|
|
|
|
actionY.started += ButtonYPressed;
|
2024-04-10 09:44:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
2024-09-23 17:11:21 +02:00
|
|
|
actionA.started -= ButtonAPressed;
|
|
|
|
actionB.started -= ButtonBPressed;
|
|
|
|
actionX.started -= ButtonXPressed;
|
|
|
|
actionY.started -= ButtonYPressed;
|
2024-04-10 09:44:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
2024-09-23 17:11:21 +02:00
|
|
|
actionA.Enable();
|
|
|
|
actionB.Enable();
|
|
|
|
actionX.Enable();
|
|
|
|
actionY.Enable();
|
2024-04-10 09:44:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
2024-09-23 17:11:21 +02:00
|
|
|
actionA.Disable();
|
|
|
|
actionB.Disable();
|
|
|
|
actionX.Disable();
|
|
|
|
actionY.Disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonAPressed(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
OnPressA.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonBPressed(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
OnPressB.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ButtonXPressed(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
OnPressX.Invoke();
|
2024-04-10 09:44:23 +02:00
|
|
|
}
|
|
|
|
|
2024-09-23 17:11:21 +02:00
|
|
|
private void ButtonYPressed(InputAction.CallbackContext context)
|
2024-04-10 09:44:23 +02:00
|
|
|
{
|
2024-09-23 17:11:21 +02:00
|
|
|
OnPressY.Invoke();
|
2024-04-10 09:44:23 +02:00
|
|
|
}
|
|
|
|
}
|