您当前的位置: 首页 >  unity

unity工具人

暂无认证

  • 4浏览

    0关注

    205博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity Animator动态添加事件

unity工具人 发布时间:2020-01-15 19:36:47 ,浏览量:4

using UnityEngine;

 public class Myscript01 : MonoBehaviour {
     #region --变量定义
     private Animator animator;
     private AnimationClip[] clips;
     #endregion
 
     #region --系统函数
     private void Start()
     {
         animator = this.GetComponent();
         clips = animator.runtimeAnimatorController.animationClips;
 
         AnimationClip _clip = clips[0];
         AddAnimationEvent(animator, _clip.name, "StartEvent", 0);
         AddAnimationEvent(animator, _clip.name, "HalfEvent", _clip.length* 0.5f);
         AddAnimationEvent(animator, _clip.name, "EndEvent", _clip.length);
     }
     private void OnDestroy()
     {
         CleanAllEvent();
     }
     #endregion
 
     #region --自定义函数
     private void StartEvent()
     {
         Debug.Log("开始播放动画");
     }
     private void HalfEvent()
     {
         Debug.Log("动画播放了一半");
     }
     private void EndEvent()
     {
         Debug.Log("播放动画完毕");
     }
 
     /// 
     /// 添加动画事件
     /// 
     /// 
     /// 动画名称
     /// 事件方法名称
     /// 添加事件时间。单位:秒
     private void AddAnimationEvent(Animator _animator, string _clipName, string _eventFunctionName, float _time)
     {
         AnimationClip[] _clips = _animator.runtimeAnimatorController.animationClips;
         for (int i = 0; i            
关注
打赏
1656671177
查看更多评论
0.0354s