Files
ichni_Official/Assets/Scripts/Manager/NoteManager.cs
SoulliesOfficial bae0bfbc20 perf
2025-07-21 05:42:20 -04:00

40 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class NoteManager : MonoBehaviour
{
private List<(float activationTime, NoteBase note)> pendingNotes = new List<(float, NoteBase)>();
private int nextNoteIndex = 0;
public void RegisterNote(NoteBase note, float activationTime)
{
pendingNotes.Add((activationTime, note));
}
// 在所有物体注册完毕后,对列表进行一次排序
public void AllNotesRegistered()
{
pendingNotes.Sort((a, b) => a.activationTime.CompareTo(b.activationTime));
}
void Update()
{
// 如果所有音符都已激活,则不执行任何操作
if (nextNoteIndex >= pendingNotes.Count)
{
return;
}
// 检查下一个待激活的音符
while (nextNoteIndex < pendingNotes.Count &&
GameManager.instance.songTime >= pendingNotes[nextNoteIndex].activationTime)
{
pendingNotes[nextNoteIndex].note.gameObject.SetActive(true);
nextNoteIndex++;
}
}
}
}