This commit is contained in:
SoulliesOfficial
2026-06-12 03:17:18 -04:00
parent 997d187147
commit 4770905b33
9 changed files with 19086 additions and 18556 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Ichni.Editor;
using Lean.Pool;
using UnityEngine;
@@ -32,6 +33,17 @@ namespace Ichni.RhythmGame
substantialObject.FirstSetUpObject(isFirstGenerated);
substantialObject.SetEditorSubmodules();
if (isFirstGenerated) substantialObject.AfterInitialize();
// 在 NoteVisual 的 AfterInitialize + Recover 全部完成后,
// 立即强制父 Note 执行 ManualUpdate让效果状态机根据当前 songTime
// 将 noteMain 驱动至正确的可见状态,而非等待下一帧 NoteManager.ManualTick。
if (isFirstGenerated && substantialObject is NoteVisualBase noteVisual && noteVisual.note != null)
{
NoteBase note = noteVisual.note;
note.gameObject.SetActive(true);
note.ManualUpdate(EditorManager.instance.songInformation.songTime);
}
return substantialObject;
}

View File

@@ -206,6 +206,23 @@ namespace Ichni.RhythmGame
#endregion
#region [] Specific Manager Callbacks
/// <summary>
/// 当 NoteVisual 被动态挂载或替换后,重新缓存效果列表并刷新 NoteScheduler 注册。
/// 解决手动添加 NoteVisual 后,父 Note 的 generateEffects 等缓存仍为 null 导致特效无法驱动的问题。
/// </summary>
public void RefreshNoteVisualCaches()
{
generateEffects = GetEffectListSafe("Generate");
generalJudgeEffects = GetEffectListSafe("GeneralJudge");
perfectEffects = GetEffectListSafe("Perfect");
goodEffects = GetEffectListSafe("Good");
badEffects = GetEffectListSafe("Bad");
missEffects = GetEffectListSafe("Miss");
afterJudgeEffects = GetEffectListSafe("AfterJudge");
AddinNoteManager(false);
}
public void AddinNoteManager(bool isNewOne = true)
{
if (generateEffects != null)
@@ -243,15 +260,24 @@ namespace Ichni.RhythmGame
finishTime = Mathf.Max(finishTime, finishEffects[i].effectTime);
}
float activationTime = exactJudgeTime - beyondTime - 0.1f;
float endTime = (this is Hold hold ? hold.holdEndTime : exactJudgeTime) + finishTime + 0.1f;
if (exactJudgeTime - beyondTime - 0.5f > -EditorManager.instance.songInformation.delay)
{
gameObject.SetActive(false);
var noteScheduler = CoreServices.UpdateScheduler.NoteScheduler;
if (isNewOne)
noteScheduler.RegisterNote(this, exactJudgeTime - beyondTime - 0.1f, (this is Hold hold ? hold.holdEndTime : exactJudgeTime) + finishTime + 0.1f);
noteScheduler.RegisterNote(this, activationTime, endTime);
else
noteScheduler.ChangeNoteInfo(this, exactJudgeTime - beyondTime - 0.1f, (this is Hold hold ? hold.holdEndTime : exactJudgeTime) + finishTime + 0.1f);
noteScheduler.ChangeNoteInfo(this, activationTime, endTime);
}
else if (!isNewOne)
{
// 条件不满足(早期 Note时仍须更新 NoteManager 的时间窗口,
// 否则 beyondTime 变化后窗口不一致ManualTick 会错误地隐藏 Note。
var noteScheduler = CoreServices.UpdateScheduler.NoteScheduler;
noteScheduler.ChangeNoteInfo(this, activationTime, endTime);
}
}

View File

@@ -44,6 +44,20 @@ namespace Ichni.RhythmGame
base.SetDefaultSubmodules();
effectSubmodule = new EffectSubmodule(this, EffectSubmodule.EffectSubmodulePreset.Note);
}
/// <summary>
/// NoteVisual 初始化完毕后,通知父 Note 重新缓存效果列表。
/// 解决手动生成 NoteVisual 时,父 Note 的 generateEffects 等缓存为 null 导致特效不被驱动的问题。
/// </summary>
public override void AfterInitialize()
{
base.AfterInitialize();
if (note != null)
{
note.RefreshNoteVisualCaches();
}
}
#endregion
#region [] Visual Behaviors
@@ -56,6 +70,18 @@ namespace Ichni.RhythmGame
{
}
public override void OnDelete()
{
base.OnDelete();
// 清除父 Note 对已删除 NoteVisual 的引用,防止悬空引用和 NullReferenceException
if (note != null)
{
note.noteVisual = null;
note.RefreshNoteVisualCaches();
}
}
#endregion
}
}