修改部分的长音符判定bug,优化多键位同时触发的判定逻辑
Signed-off-by: Jiangqvweihuan <>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class InputManager : MonoBehaviour
|
||||
{
|
||||
public static event Action<KeyCode> OnKeyPressed;
|
||||
public static event Action<KeyCode> OnKeyReleased;
|
||||
|
||||
// 存储当前帧所有按下的按键
|
||||
private KeyCode[] pressedKeysThisFrame = new KeyCode[5];
|
||||
private int pressedKeyCount = 0;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
pressedKeyCount = 0;
|
||||
|
||||
// 检查所有可能的按键
|
||||
foreach (string color in new string[] { "red", "green", "yellow", "purple", "blue" })
|
||||
{
|
||||
KeyCode key = KeyBindingManager.GetKeyForColor(color);
|
||||
if (key == KeyCode.None) continue;
|
||||
|
||||
if (Input.GetKeyDown(key))
|
||||
{
|
||||
// 记录当前帧按下的所有按键
|
||||
pressedKeysThisFrame[pressedKeyCount++] = key;
|
||||
OnKeyPressed?.Invoke(key);
|
||||
}
|
||||
if (Input.GetKeyUp(key))
|
||||
{
|
||||
OnKeyReleased?.Invoke(key);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理多键同时按下
|
||||
if (pressedKeyCount > 1)
|
||||
{
|
||||
HandleMultiKeyPress();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleMultiKeyPress()
|
||||
{
|
||||
// 对当前帧所有按下的按键进行处理
|
||||
for (int i = 0; i < pressedKeyCount; i++)
|
||||
{
|
||||
KeyCode key = pressedKeysThisFrame[i];
|
||||
// 调用 JudgeManager 统一判断对应按键的音符
|
||||
JudgeManager.Instance.JudgeEarliestNote(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user