经过测试只要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的更多相关文章

  1. unity代码添加动画,并传参数

    测试界面 button一个 sprite一个 测试代码 public class BgObject : MonoBehaviour { void Start() { List<string> ...

  2. Unity 代码编译成dll 更新dll实现热更代码

    Unity 代码编译成dll 更新dll实现热更代码 实现流程 代码编译成DLL DLL打包成AssetBundle 加载AssetBundle 加载代码程序集 获取指定类 使用反射赋值 C#代码编译 ...

  3. VS中如何快捷地给自己的代码添加创建信息注释

    VS中如何快捷地给自己的代码添加创建信息注释 Intro 以下讨论的都是没有使用 GIT 来管理源代码的情况,如果使用 GIT 管理源代码可直接使用VS的Git扩展就不需要考虑以下问题. 什么是创建信 ...

  4. 用Unity代码通过Xml配置生成GameObject之——前两天掉的坑

    1. Resources.Load(path),path不是绝对路径,而是相对"Resources/"的相对路径!如: 要想Instantiate则代码应该如下: string m ...

  5. 【转】iOS学习之Autolayout(代码添加约束) -- 不错不错

    原文网址:http://www.cnblogs.com/HypeCheng/articles/4192154.html DECEMBER 07, 2013 学习资料 文章 Beginning Auto ...

  6. 【转】iOS6中的Auto Layout:通过代码添加约束

        最近做的项目用到了Auto Layout,于是经过了一番大量的google,这是我看到的讲用代码创建约束最清晰的一篇教程,于是想跟更多的人分享一下.原文也比较简单,可以直接过去看,如果我翻译的 ...

  7. 给php代码添加规范的注释phpDocumentor

    给php代码添加规范的注释更多参考 http://phpdoc.org/docs/latest/index.html在phpdocumentor中,注释分为文档性注释和非文档性注释.所谓文档性注释,是 ...

  8. iOS 11开发教程(十八)iOS11应用视图之使用代码添加按钮

    iOS 11开发教程(十八)iOS11应用视图之使用代码添加按钮 由于使用编辑界面添加视图的方式比较简单,所以不在介绍.这里,直接讲解代码中如何添加.使用代码为主视图添加一个按钮的方式和在1.3.3节 ...

  9. iOS 11开发教程(十四)iOS11应用代码添加视图

    iOS 11开发教程(十四)iOS11应用代码添加视图 如果开发者想要使用代码为主视图添加视图,该怎么办呢.以下将为开发者解决这一问题.要使用代码为主视图添加视图需要实现3个步骤. (1)实例化视图对 ...

随机推荐

  1. JAVA各版本更新特性1-8

    JAVA各版本更新特性1-8 原文地址 Java Versions, Features and History This article gives you a highlight of import ...

  2. 使用electron静默打印

    1.使用electron打印的理由 很多情况下程序中使用的打印都是用户无感知的.并且想要灵活的控制打印内容,往往需要借助打印机给我们提供的api再进行开发,这种开发方式非常繁琐,并且开发难度较大. e ...

  3. Ubuntu编译Android使用的FFmpeg

    本文介绍在Ubuntu平台编译FFmpeg库,用于Android使用.前提需要配置好NDK的环境.可以参考之前的文章Android NDK环境搭建. 下载FFmpeg 在官网下载FFmpeg源码,ht ...

  4. GCC的-wl,-rpath=参数

    使用GCC编译动态链接库的项目时,在其他目录下执行很可以出现找不到动态链接库的问题. 这种情况多发生在动态链接库是自己开发的情况下,原因就是程序运行时找不到去何处加载动态链接库. 可能会说在编译时指定 ...

  5. Android蓝牙通讯【转】

    本文转载自:http://blog.csdn.net/vnanyesheshou/article/details/51554852 随着可穿戴设备的流行,研究蓝牙是必不可少的一门技术了. 总结了下蓝牙 ...

  6. LibreOJ 数列分块入门

    题目链接:https://loj.ac/problem/6277 题目描述 给出一个长为 nnn 的数列,以及 nnn 个操作,操作涉及区间加法,单点查值. 输入格式 第一行输入一个数字 nnn. 第 ...

  7. linux命令学习笔记(29):chgrp命令

    在lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理.可以使用chgrp指令取变更文件与目录所属群 组,这种方式采用群组名称或群组识别码都可以.Chgrp命令就是change group ...

  8. 【LeetCode】Reverse Words in a String 反转字符串中的单词

    一年没有管理博客园了,说来实在惭愧.. 最近开始刷LeetCode,之前没刷过,说来也实在惭愧... 刚开始按 AC Rates 从简单到难刷,觉得略无聊,就决定按 Add Date 刷,以后也可能看 ...

  9. POJ3417Network(LCA+树上查分||树剖+线段树)

    Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has jus ...

  10. ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...