Lua监听AnimationEvent
来源:互联网 发布:网络诈骗案证据不足 编辑:程序博客网 时间:2024/05/22 10:34
using System;using UnityEngine;//using LuaInterface;//using UnityEngine.Events;using System.Collections.Generic;namespace LuaFramework{ [RequireComponent(typeof(Animator))] public class AnimEventListener : MonoBehaviour { private Animator animator; private Dictionary<string, AnimEvent> eventsMap; public delegate void ObjectDelegate(object arg0); public class AnimEvent { public object arg0; private event ObjectDelegate m_animEvent; public AnimEvent(object arg0, ObjectDelegate callback) { this.arg0 = arg0; m_animEvent += callback; } public void Invoke() { Invoke(arg0); } public void Invoke(object arg) { if (m_animEvent != null) { m_animEvent(arg); } } public void AddListener(ObjectDelegate callback) { m_animEvent += callback; } public void RemoveListener(ObjectDelegate callback) { m_animEvent -= callback; } public void RemoveAllListeners() { m_animEvent = null; } } public static AnimEventListener Get(GameObject go) { if (go == null) return null; AnimEventListener listener = go.GetComponent<AnimEventListener>(); if (listener == null) listener = go.AddComponent<AnimEventListener>(); return listener; } public bool AddEvent(string animName, float time, ObjectDelegate callback) { AnimationClip[] clips = animator.runtimeAnimatorController.animationClips; AnimationClip target = null; for (int i = 0; i < clips.Length; i++) { if (animName == clips[i].name) { target = clips[i]; break; } } if (target == null) return false; AnimEvent eventParam = null; string animEventName = string.Format("{0}_{1}", animName, time.ToString()); if (!eventsMap.TryGetValue(animEventName, out eventParam)) { AnimationEvent animEvent = new AnimationEvent(); animEvent.time = time; animEvent.functionName = "OnAnimEvent"; animEvent.stringParameter = animEventName; eventParam = new AnimEvent(animEvent, callback); eventsMap[animEventName] = eventParam; target.AddEvent(animEvent); } else { eventParam.AddListener(callback); } return true; } public void RemoveEvent() { } void Awake() { animator = GetComponent<Animator>(); eventsMap = new Dictionary<string, AnimEvent>(); } public void OnAnimEvent(AnimationEvent animEvent) { if (animEvent == null) return; AnimEvent eventParam = null; if (eventsMap.TryGetValue(animEvent.stringParameter, out eventParam)) { eventParam.Invoke(); } } }}
0 0
- Lua监听AnimationEvent
- AnimationEvent
- lua监听内存释放
- AnimationEvent事件问题
- unity 代码添加AnimationEvent
- Unity 动画系统-AnimationEvent
- untiy AnimationEvent添加返回参数
- Cocos2dx+lua中调用按键监听
- cocos2d-x3.2 lua 返回键监听
- cocos2dx-lua sprite增加touch监听
- cocos2dx用lua监听android的返回事件
- 关于lua中事件监听,多次请求网络的问题
- cocos2dx3.13 lua注册、分发监听真机切到后台事件
- Unity3D之Animation中AnimationEvent的BUG?爬坑向
- unity中为mecanim动画动态添加AnimationEvent
- Unity3D “xx AnimationEvent has no function name specified!”解决方案
- 监听
- 监听
- 分布式架构学习之:013--基于Dubbo的分布式系统架构介绍(以第三方支付系统架构为例)
- 快速排序
- Java动态代理模式jdk和cglib的2种实现以及二者的区别(AOP面向切面的前奏)
- CTSC2017总结
- AngularJS 设置img (ng-src 和 src 区别)
- Lua监听AnimationEvent
- MongoDB学习笔记(一)
- 版本管理工具(SVN)
- Java中的注解是如何工作的?
- CodeForces
- gsoap搭建WebService服务和客户端例子
- PHP反转字符串
- 5/10博客
- Water Gate Management