Files
ichni_Creator_Studio/Assets/Scripts/Manager/AnimationManager.cs
SoulliesOfficial aee62cd637 大修
2026-03-14 02:30:26 -04:00

52 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using Ichni.RhythmGame;
using SLSUtilities.General;
using UnityEngine;
namespace Ichni
{
/// <summary>
/// 编辑器 AnimationManager集中管理场上所有 AnimationBase 实例的逐帧更新。
/// 替代 AnimationBase.Update() 中大量零散的 MonoBehaviour 帧回调,
/// 由 EditorManager.Update 统一驱动,减少 Update() 调用开销。
/// 倒序遍历防止在更新途中某个动画自行销毁导致越界。
/// </summary>
public class AnimationManager : Singleton<AnimationManager>
{
#region [] Singleton Alias
public new static AnimationManager instance => Instance;
#endregion
#region [] Active Animation List
private readonly List<AnimationBase> _activeAnimations = new List<AnimationBase>(200);
#endregion
#region [] Registration
public void RegisterAnimation(AnimationBase anim)
{
if (!_activeAnimations.Contains(anim)) _activeAnimations.Add(anim);
}
public void UnregisterAnimation(AnimationBase anim) => _activeAnimations.Remove(anim);
#endregion
#region [] Manager-Driven Tick
/// <summary>
/// 由 EditorManager.Update 统一调度。
/// 倒序遍历以防在更新途中某个动画自行销毁导致列表越界。
/// </summary>
public void ManualTick(float songTime)
{
for (int i = _activeAnimations.Count - 1; i >= 0; i--)
{
var anim = _activeAnimations[i];
if (!anim.isActiveAndEnabled) continue;
if (anim.timeDurationSubmodule.CheckTimeInDuration(songTime))
{
anim.InvokeUpdate();
}
}
}
#endregion
}
}