Health/Assets/Scripts/UI/Component/GudieAnimationManager.cs

67 lines
1.8 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;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GudieAnimationManager : MonoBehaviour
{
private Animator _animator;
private string _currName;
private List<AvatarAction> _actionList = new List<AvatarAction>();
public Animator Animator
{
get
{
if (_animator == null)
{
_animator = transform.GetComponentInChildren<Animator>();
}
return _animator;
}
}
private void Awake()
{
_animator = transform.GetComponentInChildren<Animator>();
}
public void Play(string name)
{
Animator.CrossFade(name, 0.5f);
_currName = name;
}
public void PlayCurrentActionList(List<AvatarAction> actionList)
{
_actionList = actionList;
YogaManager.Instance.ActionIndex = 0;
Play(Enum.GetName(typeof(AvatarAction), _actionList[YogaManager.Instance.ActionIndex]));
}
private void Update()
{
if (string.IsNullOrEmpty(_currName))
return;
//当未达到指标且动画播放完毕时,重新播放
if (Animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f)
{
//如果列表动画index小于列表长度播放下一个动画
YogaManager.Instance.ActionIndex++;
//如果列表动画index大于等于列表长度说明动画播放完毕停止播放
if (YogaManager.Instance.ActionIndex >= YogaManager.Instance.LevelData.Actions.Count)
{
Stop();
return;
}
Play(Enum.GetName(typeof(AvatarAction), _actionList[YogaManager.Instance.ActionIndex]));
}
}
public void Stop()
{
Animator.StopPlayback();
}
}