目前添加了一个能够深度查找和设置反射的helper,但是Tag的系统仍然不完全,另外我觉得console可以重构了 Signed-off-by: TRAfoer <lhf190@outlook.com>
55 lines
1.8 KiB
C#
55 lines
1.8 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();
|
|
print($"Registered note {note.elementName} with activation time {activationTime} and finish time {finishTime}");
|
|
}
|
|
|
|
// 在所有物体注册完毕后,对列表进行一次排序
|
|
public void AllNotesRegistered()
|
|
{
|
|
pendingNotes.Sort((a, b) => a.activationTime.CompareTo(b.activationTime));
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
|
|
float currentTime = EditorManager.instance.songInformation.songTime;
|
|
|
|
// 一次性移除所有 null 项
|
|
pendingNotes.RemoveAll(item => item.note == null);
|
|
|
|
foreach (var item in pendingNotes)
|
|
{
|
|
var (note, activationTime, finishTime) = item;
|
|
bool shouldBeActive = currentTime >= activationTime && currentTime <= finishTime;
|
|
bool isActive = note.gameObject.activeSelf;
|
|
|
|
if (shouldBeActive && !isActive)
|
|
{
|
|
note.gameObject.SetActive(true);
|
|
if (currentTime < note.exactJudgeTime) note.noteVisual?.Recover();
|
|
}
|
|
else if (!shouldBeActive && isActive)
|
|
{
|
|
|
|
note.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
} |