@@ -1,17 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame
|
||||
{
|
||||
public class NoteManager : MonoBehaviour
|
||||
{
|
||||
private List<(NoteBase note, float activationTime, float finishTime)> pendingNotes = new List<(NoteBase, float, float)>();
|
||||
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();
|
||||
}
|
||||
|
||||
// 在所有物体注册完毕后,对列表进行一次排序
|
||||
@@ -20,20 +22,39 @@ namespace Ichni.RhythmGame
|
||||
pendingNotes.Sort((a, b) => a.activationTime.CompareTo(b.activationTime));
|
||||
}
|
||||
|
||||
void Update()
|
||||
void LateUpdate()
|
||||
{
|
||||
foreach ((NoteBase note, float activationTime, float finishTime) note in pendingNotes)
|
||||
List<(NoteBase note, float activationTime, float finishTime)> toRemove = new List<(NoteBase, float, float)>();
|
||||
foreach ((NoteBase note, float activationTime, float finishTime) in pendingNotes)
|
||||
{
|
||||
if (EditorManager.instance.songInformation.songTime >= note.activationTime &&
|
||||
EditorManager.instance.songInformation.songTime <= note.finishTime)
|
||||
if (note == null)
|
||||
{
|
||||
note.note.gameObject.SetActive(true);
|
||||
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
|
||||
{
|
||||
note.note.gameObject.SetActive(false);
|
||||
if (note.gameObject.activeSelf)
|
||||
{
|
||||
note.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = toRemove.Count - 1; i >= 0; i--)
|
||||
{
|
||||
pendingNotes.Remove(toRemove[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user