首次提交
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
|
||||
namespace Roy
|
||||
{
|
||||
public class AnimationPipeline : BaseManager<AnimationPipeline>
|
||||
{
|
||||
private Queue<Tween> _tweenQueue = new Queue<Tween>(); // 动画队列
|
||||
private Sequence _currentSequence; // 当前的动画Sequence
|
||||
private bool _isPlaying = false; // 管线是否正在播放
|
||||
|
||||
// 向管线添加一个新的动画
|
||||
public void AddToPipeline(Tween newTween)
|
||||
{
|
||||
_tweenQueue.Enqueue(newTween); // 将新的动画放入队列
|
||||
|
||||
if (!_isPlaying)
|
||||
{
|
||||
StartNextSequence(); // 如果没有播放中的动画,启动队列中的下一个动画
|
||||
}
|
||||
}
|
||||
|
||||
// 启动下一个动画序列
|
||||
private void StartNextSequence()
|
||||
{
|
||||
if (_tweenQueue.Count == 0)
|
||||
{
|
||||
_isPlaying = false; // 队列为空,停止播放
|
||||
return;
|
||||
}
|
||||
|
||||
_isPlaying = true;
|
||||
_currentSequence = DOTween.Sequence(); // 创建一个新的Sequence
|
||||
|
||||
while (_tweenQueue.Count > 0)
|
||||
{
|
||||
Tween nextTween = _tweenQueue.Dequeue();
|
||||
_currentSequence.Append(nextTween); // 将每个Tween按顺序加入到Sequence
|
||||
}
|
||||
|
||||
// 当Sequence完成时,检查队列中是否还有新的动画
|
||||
_currentSequence.OnComplete(() =>
|
||||
{
|
||||
_isPlaying = false;
|
||||
StartNextSequence(); // 如果还有新动画,继续播放
|
||||
});
|
||||
|
||||
_currentSequence.Play(); // 播放当前Sequence
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user