original ver 25/06/01

This commit is contained in:
GardeniaRabbit
2025-06-02 00:48:08 +08:00
committed by FloatGaming
commit 89e03899f0
1065 changed files with 183622 additions and 0 deletions
@@ -0,0 +1,122 @@
using System.Collections.Generic;
using UnityEngine;
public class JudgeManager : MonoBehaviour
{
public static JudgeManager Instance { get; private set; }
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 void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
return;
}
}
/// <summary>
/// 记录某个颜色的长音符 End 段的 scheduledEndTime
/// </summary>
public void RegisterScheduledEndTime(string noteColor, float endTime)
{
noteEndTimes[noteColor] = endTime;
}
/// <summary>
/// 获取某个颜色的 End 段的 scheduledEndTime
/// </summary>
public float GetScheduledEndTime(string noteColor)
{
return noteEndTimes.ContainsKey(noteColor) ? noteEndTimes[noteColor] : 0f;
}
public void RegisterStartJudged(string noteID, bool state)
{
startJudgedNotes[noteID] = state;
}
public bool IsStartJudged(string noteID)
{
return startJudgedNotes.ContainsKey(noteID) && startJudgedNotes[noteID];
}
public void RegisterNoteReleased(string noteID, bool state)
{
releasedNotes[noteID] = state;
Debug.Log($"[JudgeManager] RegisterNoteReleased: {noteID} = {state}");
}
public bool HasNoteReleased(string noteID)
{
return releasedNotes.ContainsKey(noteID) && releasedNotes[noteID];
}
/// <summary>
/// 当音符进入判定区域时调用
/// </summary>
public void RegisterNote(KeyCode key, Note note)
{
if (!judgeQueues.ContainsKey(key))
judgeQueues[key] = new Queue<Note>();
if (!judgeQueues[key].Contains(note))
{
judgeQueues[key].Enqueue(note);
}
}
/// <summary>
/// 当音符离开判定区域时调用
/// </summary>
public void UnregisterNote(KeyCode key, Note note)
{
if (!judgeQueues.ContainsKey(key)) return;
Queue<Note> newQueue = new Queue<Note>();
while (judgeQueues[key].Count > 0)
{
Note n = judgeQueues[key].Dequeue();
if (n != note)
{
newQueue.Enqueue(n);
}
else
{
// **如果音符未被判定,则触发 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(); // 只取最早的音符
if (note != null && !note.IsJudged())
{
note.Judge();
}
}
}
}