2026-06-19 UI, UI로직
This commit is contained in:
52
Assets/My project/RhythmGame/Scripts/RhythmInputHandler.cs
Normal file
52
Assets/My project/RhythmGame/Scripts/RhythmInputHandler.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user