Files
ichni_Creator_Studio/Assets/Scripts/Manager/NoteManager.cs
TRAfoer 725009e354 大幅优化
Signed-off-by: TRAfoer <lhf190@outlook.com>
2025-10-05 11:45:32 +08:00

60 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
namespace Ichni.RhythmGame
{
public class NoteManager : MonoBehaviour
{
public List<(NoteBase note, float activationTime, float finishTime)> pendingNotes = new List<(NoteBase, float, float)>();
private int nextNoteIndex = 0;
public void RegisterNote(NoteBase note, float activationTime, float finishTime)
{
pendingNotes.Add((note, activationTime, finishTime));
AllNotesRegistered();
}
// 在所有物体注册完毕后,对列表进行一次排序
public void AllNotesRegistered()
{
pendingNotes.Sort((a, b) => a.activationTime.CompareTo(b.activationTime));
}
void LateUpdate()
{
List<(NoteBase note, float activationTime, float finishTime)> toRemove = new List<(NoteBase, float, float)>();
foreach ((NoteBase note, float activationTime, float finishTime) in pendingNotes)
{
if (note == null)
{
toRemove.Add((note, activationTime, finishTime));
continue;
}
if (EditorManager.instance.songInformation.songTime >= activationTime &&
EditorManager.instance.songInformation.songTime <= finishTime)
{
if (!note.gameObject.activeSelf)
{
note.gameObject.SetActive(true);
}
}
else
{
if (note.gameObject.activeSelf)
{
note.gameObject.SetActive(false);
}
}
}
for (int i = toRemove.Count - 1; i >= 0; i--)
{
pendingNotes.Remove(toRemove[i]);
}
}
}
}