Unity 5.6.1 动态添加Animation动画事件回调
///
/// 添加动画事件回调
///
/// 动画
/// clip名字
/// 自定义事件类型
/// 回调方法
private void AddAnimationEvent(Animation animation, string clipName, EvnetPlace evnetPlace, string evnetFunction)
{
//clip = animator.GetCurrentAnimatorClipInfo(0)[0].clip;
clip = animation.GetClip(clipName);
//创建动画事件
AnimationEvent animationEvent = new AnimationEvent();
//设置事件回掉函数名字
animationEvent.functionName = evnetFunction;
//传入参数
//animationEvent.objectReferenceParameter = target;
//设置触发帧
if (evnetPlace == EvnetPlace.Start)
animationEvent.time = 0f;
else if (evnetPlace == EvnetPlace.End)
animationEvent.time = clip.length;
//注册事件
clip.AddEvent(animationEvent);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimEventChh : MonoBehaviour {
public ModuleGameCenter moduleGameCenter;
#region CrystalHeadPractical
private void Peel_End()
{
moduleGameCenter.Peel_End();
}
private void TrimThread_End()
{
moduleGameCenter.TrimThread_End();
}
#endregion
}
这个AnimEventChh脚本要放在带动画的物体上 要不找不到回调方法