Unity 动画事件(播放、播放回调)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public delegate void AniCallBack();
//[RequireComponent(typeof(Animator))]
public class AnimationManager : MonoBehaviour
{
    public static AnimationManager Instance;

    //public Animator _Animator;
    public void Awake()
    {
        Instance = this;
    }
    //Public
    public void AniPlay(Animator animator, AniCallBack aniCallBack)
    {
        StartCoroutine(DelayAni(animator, aniCallBack));
    }
    IEnumerator DelayAni(Animator animator, AniCallBack aniCallBack)
    {
        yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
        aniCallBack();
    }


    public void AniPlay(Animator animator, AniCallBack aniCallBack, float DelayTime)
    {
        StartCoroutine(DelayAni(animator, aniCallBack, DelayTime));
    }
    IEnumerator DelayAni(Animator animator, AniCallBack aniCallBack, float DelayTime)
    {
        yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length + DelayTime);
        aniCallBack();
    }


    //void Start()
    //{
    //    AniPlay(_Animator, (()=> { Debug.Log("执行完动画后。。。。。。"); }));
    //}
}

猜你喜欢

转载自blog.csdn.net/li1214661543/article/details/106680758