perf
This commit is contained in:
40
Assets/Scripts/Manager/NoteManager.cs
Normal file
40
Assets/Scripts/Manager/NoteManager.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user