57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace DefaultNamespace.ProcessMode
|
|
{
|
|
public class AnimationManager
|
|
{
|
|
private static Dictionary<string, Sequence> animationGroups = new Dictionary<string, Sequence>();
|
|
|
|
// 添加物体动画并指定物体名
|
|
public static void AddAnimationGroup(string objectName, System.Action<Sequence> animationSetup)
|
|
{
|
|
if (animationGroups.TryGetValue(objectName, out var existingSequence))
|
|
{
|
|
existingSequence.Kill(); // 杀死已有的序列,防止冲突
|
|
}
|
|
Sequence group = DOTween.Sequence(); // 创建一个新的Sequence
|
|
animationSetup(group); // 设置动画组
|
|
group.Pause(); // 初始状态暂停
|
|
animationGroups[objectName] = group; // 将Sequence添加到字典中
|
|
}
|
|
|
|
// 根据物体名播放动画
|
|
public static void PlayAnimationGroup(string objectName)
|
|
{
|
|
if (!animationGroups.TryGetValue(objectName, out var group))
|
|
{
|
|
Debug.LogError($"找不到物体 '{objectName}' 的动画");
|
|
return;
|
|
}
|
|
|
|
group.Restart(); // 重新开始动画
|
|
group.Play(); // 播放动画
|
|
}
|
|
|
|
// 清除所有动画组
|
|
public static void ClearAnimationGroups()
|
|
{
|
|
foreach (var sequence in animationGroups.Values)
|
|
{
|
|
sequence.Kill();
|
|
}
|
|
animationGroups.Clear();
|
|
}
|
|
|
|
// 停止并清除指定物体名的动画
|
|
public static void StopAnimationGroup(string objectName)
|
|
{
|
|
if (animationGroups.TryGetValue(objectName, out var group))
|
|
{
|
|
group.Kill(); // 杀死当前序列
|
|
animationGroups.Remove(objectName); // 从字典中移除
|
|
}
|
|
}
|
|
}
|
|
} |