Files
ichni_Creator_Studio/Assets/Scripts/Manager/NoteManager.cs

60 lines
1.9 KiB
C#
Raw Normal View History

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