unity 代码添加AnimationEvent
来源:互联网 发布:手机健身软件 编辑:程序博客网 时间:2024/05/24 04:17
经过测试只要Animator跟继承monoBehaviour的类A在同一个节点上,就可以注册类A中的public 方法,含0或1个参数(int,float,object,string),注意:只能是0或1个参数
using UnityEngine;class TAnimEvent:MonoBehaviour{[SerializeField]private Animator mAnimator;public bool abc;void Start(){mAnimator = this.GetComponent<Animator>();RuntimeAnimatorController m_runtimeAnimatorController = this.GetComponent<Animator>().runtimeAnimatorController;AnimationEvent newEvent = new AnimationEvent();newEvent.functionName = "Print";newEvent.time = 0.0f;newEvent.intParameter = 9;//newEvent.floatParameter = 9.0f;AnimationClip[] clips = m_runtimeAnimatorController.animationClips;for (int i = 0; i < clips.Length; i++){Debug.Log("Nafio -------!!");if (clips [i].name == "Fuck") {Debug.Log("Nafio find TAnim!!");m_runtimeAnimatorController.animationClips[i].AddEvent(newEvent);;}}mAnimator.Rebind();}void Print(int a){Debug.Log ("Nafio---PrintEvent!!! a:"+a);}}
AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(0);if (currentState.nameHash == Animator.StringToHash("Base Layer.Idle")){if (!hasSet) {Action act = new Action();act.Att = this.transform;act.Def = this.transform;AnimationEvent evt = new AnimationEvent();evt.time = 0;evt.functionName = "Test";evt.objectReferenceParameter = act as Object;AnimationInfo[] info = animator.GetCurrentAnimationClipState(0);foreach (AnimationInfo i in info) {i.clip.AddEvent(evt);hasSet = true;}}}
0 0
- unity 代码添加AnimationEvent
- unity中为mecanim动画动态添加AnimationEvent
- Unity 动画系统-AnimationEvent
- untiy AnimationEvent添加返回参数
- AnimationEvent
- 添加组件和删除组件代码unity
- Unity 给代码添加命名空间
- Unity用程序给Animator控制的某一个动画(AnimationClip)加一个动画事件(AnimationEvent)
- Unity编译到Xcode自动添加文件及代码修改
- Unity用代码给按钮添加点击事件
- unity中代码添加按钮事件的两种方案
- AnimationEvent事件问题
- Lua监听AnimationEvent
- 删除添加子父物体动态添加代码等Unity的小功能
- unity添加图片背景
- unity添加声音方法
- Unity添加GIF动画
- Unity动态添加Tag
- Manifest merger failed : Attribute application@icon value=(@mipmap/ic_launcher) from AndroidManifest
- Eclipse里面安装maven插件
- Codeforces 552B
- 51nod 1631 小鲨鱼在51nod小学 【线段树--】
- 小白的python学习机器学习路(一)
- unity 代码添加AnimationEvent
- 第三届蓝桥杯【省赛试题1】微生物增殖
- Spark Streaming官方文档复习笔记-2
- 树形dp
- 对JS关于对象创建的几种方式的整理
- Storm常用计算模式
- openresty 安装测试
- 使用JQUERY封装Form和input进行提交
- 实现大小字母转换