60 lines
1.9 KiB
C#
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]);
|
|
}
|
|
|
|
}
|
|
}
|
|
} |