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("執行完動畫後。。。。。。"); }));
    //}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章