repaired the motherfucking hold note problem which troubled us longer than 2 months

added some UI
This commit is contained in:
FloatGaming
2025-08-02 00:28:35 +08:00
parent 373f0511e3
commit 774d3aeb7f
160 changed files with 5472 additions and 841 deletions
+30 -104
View File
@@ -8,42 +8,9 @@ public class JudgeManager : MonoBehaviour
private Dictionary<KeyCode, Queue<Note>> judgeQueues = new Dictionary<KeyCode, Queue<Note>>();
private Dictionary<string, bool> startJudgedNotes = new Dictionary<string, bool>();
private Dictionary<string, bool> releasedNotes = new Dictionary<string, bool>();
// 记录 End 段的 scheduledEndTime(防止 End 被回收后仍然能判定)
private Dictionary<string, float> noteEndTimes = new Dictionary<string, float>();
private Dictionary<string, float> _holdNoteStartTimes = new Dictionary<string, float>();
// 长音符状态管理
private Dictionary<int, bool> _holdNoteValidity = new Dictionary<int, bool>();
private Dictionary<int, bool> _holdNoteKeyHeld = new Dictionary<int, bool>(); // 新增:记录按键按住状态
private Dictionary<KeyCode, List<Note>> multiKeyJudgeQueues = new Dictionary<KeyCode, List<Note>>();
public void RegisterNoteForMultiKey(KeyCode key, Note note)
{
if (!multiKeyJudgeQueues.ContainsKey(key))
multiKeyJudgeQueues[key] = new List<Note>();
if (!multiKeyJudgeQueues[key].Contains(note))
{
multiKeyJudgeQueues[key].Add(note);
}
}
public void JudgeAllNotesForMultiKey(KeyCode key)
{
if (multiKeyJudgeQueues.ContainsKey(key))
{
// 对同一按键的所有音符进行判定
foreach (var note in multiKeyJudgeQueues[key])
{
if (note != null && !note.IsJudged())
{
note.Judge();
}
}
multiKeyJudgeQueues[key].Clear();
}
}
private void Awake()
{
@@ -58,68 +25,25 @@ public class JudgeManager : MonoBehaviour
}
}
#region
public bool IsHoldNoteValid(int holdNoteId)
/// <summary>
/// 记录某个颜色的长音符 End 段的 scheduledEndTime
/// </summary>
public void RegisterScheduledEndTime(string noteColor, float endTime)
{
return _holdNoteValidity.ContainsKey(holdNoteId) && _holdNoteValidity[holdNoteId];
noteEndTimes[noteColor] = endTime;
}
public void SetHoldNoteValidity(int holdNoteId, bool isValid)
/// <summary>
/// 获取某个颜色的 End 段的 scheduledEndTime
/// </summary>
public float GetScheduledEndTime(string noteColor)
{
_holdNoteValidity[holdNoteId] = isValid;
//Debug.Log($"设置长音符有效性: ID={holdNoteId}, Valid={isValid}");
return noteEndTimes.ContainsKey(noteColor) ? noteEndTimes[noteColor] : 0f;
}
public void RemoveHoldNoteValidity(int holdNoteId)
{
if (_holdNoteValidity.ContainsKey(holdNoteId))
{
_holdNoteValidity.Remove(holdNoteId);
}
}
// 新增:注册/更新按键按住状态
public void RegisterHoldNoteKeyHeld(int holdNoteId, bool isHeld)
{
_holdNoteKeyHeld[holdNoteId] = isHeld;
}
// 新增:检查按键是否按住
public bool IsHoldNoteKeyHeld(int holdNoteId)
{
return _holdNoteKeyHeld.ContainsKey(holdNoteId) && _holdNoteKeyHeld[holdNoteId];
}
#endregion
#region
public void RegisterScheduledEndTime(string noteId, float endTime)
{
noteEndTimes[noteId] = endTime;
}
public float GetScheduledEndTime(string noteId)
{
return noteEndTimes.ContainsKey(noteId) ? noteEndTimes[noteId] : 0f;
}
public void RegisterHoldNoteStart(string noteId, float startTime)
{
_holdNoteStartTimes[noteId] = startTime;
//Debug.Log($"注册长音符开始: ID={noteId}, Time={startTime}");
}
public bool IsHoldNoteActive(string noteId)
{
return _holdNoteStartTimes.ContainsKey(noteId) &&
(Time.time - _holdNoteStartTimes[noteId]) < 5f;
}
#endregion
#region
public void RegisterStartJudged(string noteID, bool state)
{
startJudgedNotes[noteID] = state;
//Debug.Log($"[JudgeManager] RegisterStartJudged: {noteID} = {state}");
}
public bool IsStartJudged(string noteID)
@@ -130,16 +54,17 @@ public class JudgeManager : MonoBehaviour
public void RegisterNoteReleased(string noteID, bool state)
{
releasedNotes[noteID] = state;
//Debug.Log($"[JudgeManager] RegisterNoteReleased: {noteID} = {state}");
Debug.Log($"[JudgeManager] RegisterNoteReleased: {noteID} = {state}");
}
public bool HasNoteReleased(string noteID)
{
return releasedNotes.ContainsKey(noteID) && releasedNotes[noteID];
}
#endregion
#region
/// <summary>
/// 当音符进入判定区域时调用
/// </summary>
public void RegisterNote(KeyCode key, Note note)
{
if (!judgeQueues.ContainsKey(key))
@@ -151,6 +76,9 @@ public class JudgeManager : MonoBehaviour
}
}
/// <summary>
/// 当音符离开判定区域时调用
/// </summary>
public void UnregisterNote(KeyCode key, Note note)
{
if (!judgeQueues.ContainsKey(key)) return;
@@ -163,34 +91,32 @@ public class JudgeManager : MonoBehaviour
{
newQueue.Enqueue(n);
}
else if (!n.IsJudged())
else
{
n.JudgeMiss();
// **如果音符未被判定,则触发 Miss**
if (!n.IsJudged())
{
n.JudgeMiss();
}
}
}
judgeQueues[key] = newQueue;
}
/// <summary>
/// 按键按下时,判定队列中最早进入的音符
/// </summary>
public void JudgeEarliestNote(KeyCode key)
{
if (judgeQueues.ContainsKey(key) && judgeQueues[key].Count > 0)
{
Note note = judgeQueues[key].Dequeue();
Note note = judgeQueues[key].Dequeue(); // 只取最早的音符
if (note != null && !note.IsJudged())
{
note.Judge();
}
}
}
#endregion
#region
public void ResetAllHoldNotes()
{
_holdNoteValidity.Clear();
_holdNoteStartTimes.Clear();
_holdNoteKeyHeld.Clear();
//Debug.Log("重置所有长音符状态");
}
#endregion
}
}