add the connections and sendToTest.cs for connecting with the game test
This commit is contained in:
@@ -11,10 +11,21 @@ public class InputManager : MonoBehaviour
|
||||
[Header("轨道判定显示TMP对象(请在Inspector中连接)")]
|
||||
public TextMeshProUGUI[] trackJudgeTexts = new TextMeshProUGUI[5];
|
||||
|
||||
[Header("按键指示文本(独立于判定文本,五个分别对应按键:D,F,Space,J,K)")]
|
||||
public TextMeshProUGUI[] trackKeyTexts = new TextMeshProUGUI[5];
|
||||
|
||||
[Header("是否显示判定文字")]
|
||||
public bool showJudgeText = true;
|
||||
|
||||
// 按键激活/非激活颜色
|
||||
[Header("按键高亮颜色设置")]
|
||||
[Tooltip("按键被按下时的颜色")]
|
||||
public Color keyActiveColor = Color.yellow;
|
||||
[Tooltip("按键未按下时的颜色(默认黑色)")]
|
||||
public Color keyInactiveColor = Color.black;
|
||||
|
||||
// 判定结果对应颜色
|
||||
[Header("判定结果对应颜色")]
|
||||
public Color perfectColor = Color.yellow;
|
||||
public Color greatColor = Color.green;
|
||||
public Color goodColor = Color.cyan;
|
||||
@@ -26,6 +37,15 @@ public class InputManager : MonoBehaviour
|
||||
Instance = this;
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
// 初始化按键文本为非激活颜色
|
||||
if (trackKeyTexts != null)
|
||||
{
|
||||
foreach (var t in trackKeyTexts)
|
||||
{
|
||||
if (t != null) t.color = keyInactiveColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -35,14 +55,48 @@ public class InputManager : MonoBehaviour
|
||||
KeyCode key = KeyBindingManager.GetKeyForColor(color);
|
||||
if (key == KeyCode.None) continue;
|
||||
|
||||
int index = GetIndexForColor(color);
|
||||
|
||||
if (Input.GetKeyDown(key))
|
||||
{
|
||||
OnKeyPressed?.Invoke(key);
|
||||
// 调用 JudgeManager 统一判断最早的音符
|
||||
JudgeManager.Instance.JudgeEarliestNote(key);
|
||||
|
||||
// 按下时设置对应的按键文本颜色为激活色(如果已设置)
|
||||
if (trackKeyTexts != null && index >= 0 && index < trackKeyTexts.Length)
|
||||
{
|
||||
var txt = trackKeyTexts[index];
|
||||
if (txt != null)
|
||||
txt.color = keyActiveColor;
|
||||
}
|
||||
}
|
||||
if (Input.GetKeyUp(key))
|
||||
{
|
||||
OnKeyReleased?.Invoke(key);
|
||||
|
||||
// 松开时恢复为非激活颜色
|
||||
if (trackKeyTexts != null && index >= 0 && index < trackKeyTexts.Length)
|
||||
{
|
||||
var txt = trackKeyTexts[index];
|
||||
if (txt != null)
|
||||
txt.color = keyInactiveColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int GetIndexForColor(string color)
|
||||
{
|
||||
// 保持与 trackJudgeTexts 相同的索引映射
|
||||
switch (color)
|
||||
{
|
||||
case "red": return 0;
|
||||
case "green": return 1;
|
||||
case "yellow": return 2;
|
||||
case "purple": return 3;
|
||||
case "blue": return 4;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user