unity 代码添加AnimationEvent
经过测试只要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;
}
}
}
unity 代码添加AnimationEvent的更多相关文章
- unity代码添加动画,并传参数
测试界面 button一个 sprite一个 测试代码 public class BgObject : MonoBehaviour { void Start() { List<string> ...
- Unity 代码编译成dll 更新dll实现热更代码
Unity 代码编译成dll 更新dll实现热更代码 实现流程 代码编译成DLL DLL打包成AssetBundle 加载AssetBundle 加载代码程序集 获取指定类 使用反射赋值 C#代码编译 ...
- VS中如何快捷地给自己的代码添加创建信息注释
VS中如何快捷地给自己的代码添加创建信息注释 Intro 以下讨论的都是没有使用 GIT 来管理源代码的情况,如果使用 GIT 管理源代码可直接使用VS的Git扩展就不需要考虑以下问题. 什么是创建信 ...
- 用Unity代码通过Xml配置生成GameObject之——前两天掉的坑
1. Resources.Load(path),path不是绝对路径,而是相对"Resources/"的相对路径!如: 要想Instantiate则代码应该如下: string m ...
- 【转】iOS学习之Autolayout(代码添加约束) -- 不错不错
原文网址:http://www.cnblogs.com/HypeCheng/articles/4192154.html DECEMBER 07, 2013 学习资料 文章 Beginning Auto ...
- 【转】iOS6中的Auto Layout:通过代码添加约束
最近做的项目用到了Auto Layout,于是经过了一番大量的google,这是我看到的讲用代码创建约束最清晰的一篇教程,于是想跟更多的人分享一下.原文也比较简单,可以直接过去看,如果我翻译的 ...
- 给php代码添加规范的注释phpDocumentor
给php代码添加规范的注释更多参考 http://phpdoc.org/docs/latest/index.html在phpdocumentor中,注释分为文档性注释和非文档性注释.所谓文档性注释,是 ...
- iOS 11开发教程(十八)iOS11应用视图之使用代码添加按钮
iOS 11开发教程(十八)iOS11应用视图之使用代码添加按钮 由于使用编辑界面添加视图的方式比较简单,所以不在介绍.这里,直接讲解代码中如何添加.使用代码为主视图添加一个按钮的方式和在1.3.3节 ...
- iOS 11开发教程(十四)iOS11应用代码添加视图
iOS 11开发教程(十四)iOS11应用代码添加视图 如果开发者想要使用代码为主视图添加视图,该怎么办呢.以下将为开发者解决这一问题.要使用代码为主视图添加视图需要实现3个步骤. (1)实例化视图对 ...
随机推荐
- 怎样拆分View Controller进而实现轻量级的View Controller[UIKit]
參考文章来自objcio站点 为什么要编写轻量级的View Controller?? 1.作为iOS项目中最大的文件,ViewControllers中的代码复用率差点儿是最低的 2.重量级的V ...
- Java for LeetCode 129 Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- 剑指Offer:字符串排列【38】
剑指Offer:字符串排列[38] 题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bc ...
- 微信小程序开发:学习笔记[7]——理解小程序的宿主环境
微信小程序开发:学习笔记[7]——理解小程序的宿主环境 渲染层与逻辑层 小程序的运行环境分成渲染层和逻辑层. 程序构造器
- 用ant编译打包时 警告:编码 GBK 的不可映射字符
原因,参考http://zhidao.baidu.com/question/26901568.html 添加如下的红色一行后编译通过<target name="compile" ...
- 计算机行业工作者-->面试的总结博文(【*持续补充】)
1.博文题目:找实习/工作经验心得分享-偏IT技术向 http://blog.csdn.net/koudaidai/article/details/8063288 2.博文题目:百度,阿里 笔试面试 ...
- HDU 6170 Two strings (dp)
/** * 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 * 字符串match, '.'代表匹配任意一个字符,"*" 代表 ...
- leetcode 104 Maximum Depth of Binary Tree(DFS)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- PyNLPIR python中文分词工具
官网:https://pynlpir.readthedocs.io/en/latest/ github:https://github.com/tsroten/pynlpir NLP ...
- [算法]从Trie树(字典树)谈到后缀树
我是好文章的搬运工,原文来自博客园,博主July_,地址:http://www.cnblogs.com/v-July-v/archive/2011/10/22/2316412.html 从Trie树( ...