53 lines
1.2 KiB
C#
53 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class RhythmInputHandler : MonoBehaviour
|
|
{
|
|
[Header("Reference")]
|
|
[SerializeField] private RhythmGameManager rhythmGameManager;
|
|
|
|
[Header("Keyboard Test")]
|
|
[SerializeField] private bool allowKeyboardTest = true;
|
|
[SerializeField] private Key testKey = Key.Space;
|
|
|
|
[Header("Auto Find")]
|
|
[SerializeField] private bool autoFindManager = true;
|
|
|
|
private void Awake()
|
|
{
|
|
if (rhythmGameManager == null && autoFindManager)
|
|
rhythmGameManager = FindFirstObjectByType<RhythmGameManager>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!allowKeyboardTest)
|
|
return;
|
|
|
|
if (Keyboard.current == null)
|
|
return;
|
|
|
|
if (Keyboard.current[testKey].wasPressedThisFrame)
|
|
SubmitHit();
|
|
}
|
|
|
|
public void OnHit(InputValue value)
|
|
{
|
|
if (value.isPressed)
|
|
SubmitHit();
|
|
}
|
|
|
|
public void SubmitHit()
|
|
{
|
|
if (rhythmGameManager == null)
|
|
return;
|
|
|
|
rhythmGameManager.SubmitHit();
|
|
}
|
|
|
|
public void SetManager(RhythmGameManager manager)
|
|
{
|
|
rhythmGameManager = manager;
|
|
}
|
|
}
|