47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using TH1_Core.Managers;
|
||
using UnityEngine;
|
||
|
||
namespace TH1_Anim.Fragments
|
||
{
|
||
/// <summary>
|
||
/// 攻击动画的 pending step 作用域。
|
||
/// 逻辑运算期间,技能产生的视觉步骤会收集到此对象中,
|
||
/// 等 Fragment 创建后通过 FlushTo 注入到 Fragment 的 step-list 中。
|
||
/// 使用 using 语句保证无论什么分支退出都会自动清理。
|
||
/// </summary>
|
||
public class PendingAnimScope : IDisposable
|
||
{
|
||
private readonly List<FragmentStep> _steps = new List<FragmentStep>();
|
||
private bool _consumed;
|
||
|
||
/// <summary>
|
||
/// 添加一个待注入的步骤(技能在生命周期回调中调用)。
|
||
/// </summary>
|
||
public void Add(FragmentStep step)
|
||
{
|
||
_steps.Add(step);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将收集到的步骤全部注入到目标 Fragment,并标记已消费。
|
||
/// </summary>
|
||
public void FlushTo(FragmentBase fragment)
|
||
{
|
||
foreach (var step in _steps)
|
||
fragment.InjectStep(step);
|
||
_consumed = true;
|
||
_steps.Clear();
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
if (!_consumed && _steps.Count > 0)
|
||
Debug.LogWarning($"PendingAnimScope: {_steps.Count} pending steps discarded (no Fragment consumed them).");
|
||
_steps.Clear();
|
||
PresentationManager.ClearCurrentScope();
|
||
}
|
||
}
|
||
}
|