58 lines
2.5 KiB
C#
58 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class InputManagerLR : MonoBehaviour
|
|
{
|
|
private static InputManagerLR instance;
|
|
|
|
[SerializeField] private InputActionAsset actionAsset;
|
|
|
|
private InputActionMap actionMap;
|
|
private InputAction primaryButtonR;
|
|
private InputAction secondaryButtonR;
|
|
private InputAction primaryButtonL;
|
|
private InputAction secondaryButtonL;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
|
|
if (actionAsset != null)
|
|
{
|
|
actionMap = actionAsset.FindActionMap("Test");
|
|
if (actionMap != null)
|
|
{
|
|
primaryButtonR = actionMap.FindAction("XR_PrimaryButtonR", throwIfNotFound: false);
|
|
primaryButtonL = actionMap.FindAction("XR_PrimaryButtonL", throwIfNotFound: false);
|
|
secondaryButtonR = actionMap.FindAction("XR_SecondaryButtonR", throwIfNotFound: false);
|
|
secondaryButtonL = actionMap.FindAction("XR_SecondaryButtonL", throwIfNotFound: false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnEnable() => actionMap?.Enable();
|
|
private void OnDisable() => actionMap?.Disable();
|
|
|
|
public static bool PrimaryButtonR() => instance?.primaryButtonR?.IsPressed() ?? false;
|
|
public static bool PrimaryButtonR_OnPress() => instance?.primaryButtonR?.WasPressedThisFrame() ?? false;
|
|
public static bool PrimaryButtonR_OnRelease() => instance?.primaryButtonR?.WasReleasedThisFrame() ?? false;
|
|
|
|
public static bool PrimaryButtonL() => instance?.primaryButtonL?.IsPressed() ?? false;
|
|
public static bool PrimaryButtonL_OnPress() => instance?.primaryButtonL?.WasPressedThisFrame() ?? false;
|
|
public static bool PrimaryButtonL_OnRelease() => instance?.primaryButtonL?.WasReleasedThisFrame() ?? false;
|
|
|
|
public static bool SecondaryButtonR() => instance?.secondaryButtonR?.IsPressed() ?? false;
|
|
public static bool SecondaryButtonR_OnPress() => instance?.secondaryButtonR?.WasPressedThisFrame() ?? false;
|
|
public static bool SecondaryButtonR_OnRelease() => instance?.secondaryButtonR?.WasReleasedThisFrame() ?? false;
|
|
|
|
public static bool SecondaryButtonL() => instance?.secondaryButtonL?.IsPressed() ?? false;
|
|
public static bool SecondaryButtonL_OnPress() => instance?.secondaryButtonL?.WasPressedThisFrame() ?? false;
|
|
public static bool SecondaryButtonL_OnRelease() => instance?.secondaryButtonL?.WasReleasedThisFrame() ?? false;
|
|
} |