52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
|
|
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
|
|||
|
|
}
|
|||
|
|
}
|