UNDERSTANDING ITWEEN CALLBACKS
One of the most frequent problems I see people have with iTween is with callbacks that don’t fire.
At it’s core iTween leverages Unity’s SendMessage method
for carrying out it’s 3 callbacks: “onStart”, “onUpdate” and “onComplete”. When you add an iTween to a GameObject, iTween will throw all callbacks against the GameObject that is being animated. Where most people have difficulties is when they assign iTweens
to GameObjects that don’t physically contain the methods they are attempting to call.
For example, the following code with never execute the “ShakeComplete” method because the “target” GameObject does not have a script attachted to it containing this method:
using UnityEngine;
using System.Collections; public class UnderstandingCallbacks : MonoBehaviour
{
public GameObject target; void Start ()
{
iTween.ShakePosition(target, iTween.Hash("x", 1, "onComplete", ShakeComplete));
} void ShakeComplete(){
Debug.Log("The shake completed!");
}
}
There’s 2 ways to correct the previous script. The long route: create another script, attach it to our actual “target” GameObject and transfer the “ShakeComplete” method to that new script. The easy route: utilize iTween’s callback “target modifiers”!
Each of iTween’s 3 callbacks have an additional “target modifier” that can be used to tell iTween to look somewhere else for the callback method: “onStartTarget”, “onUpdateTarget” and “onCompleteTarget”.
The following corrected script will now fire the “onComplete” callback since we are now using “onCompleteTarget” to tell iTween that the “ShakeComplete” method is located on the GameObject that actually set up the iTween:
using UnityEngine;
using System.Collections; public class UnderstandingCallbacks : MonoBehaviour
{
public GameObject target; void Start ()
{
iTween.ShakePosition(target, iTween.Hash("x", 1, "onComplete", "ShakeComplete", "onCompleteTarget", gameObject));
} void ShakeComplete(){
Debug.Log("The shake completed!");
}
}
I hope this helps clear up unsuccessful callbacks in iTween.
UNDERSTANDING ITWEEN CALLBACKS的更多相关文章
- Understanding Asynchronous IO With Python 3.4's Asyncio And Node.js
[转自]http://sahandsaba.com/understanding-asyncio-node-js-python-3-4.html Introduction I spent this su ...
- [转] Understanding JavaScript’s async await
PS:Promise的用处是异步调用,这个对象使用的时候,call then函数,传一个处理函数进去,处理异步调用后的结果 Promise<Action>这样的对象呢,异步调用后的结果是一 ...
- Understanding JavaScript Function Invocation and "this"
Understanding JavaScript Function Invocation and "this" 11 Aug 2011 Over the years, I've s ...
- Async Performance: Understanding the Costs of Async and Await
Stephen Toub Download the Code Sample Asynchronous programming has long been the realm of only the m ...
- jquery.Callbacks的实现
前言 本人是一个热爱前端的菜鸟,一直喜欢学习js原生,对于jq这种js库,比较喜欢理解他的实现,虽然自己能力有限,水平很低,但是勉勉强强也算是能够懂一点吧,对于jq源码解读系列,博客园里有很多,推荐大 ...
- 解决ugui中Image使用iTween的ColorTo、ColorFrom等不生效
查看iTween的源码找到ColorFrom函数,看该函数的注释“/// Changes a GameObject's color values instantly then returns them ...
- GOOD MEETINGS CREATE SHARED UNDERSTANDING, NOT BRDS!
Deliverables and artifacts were a focal point of BA work during the early part of my career. If I ...
- jQuery.Callbacks之demo
jQuery.Callbacks是jquery在1.7版本之后加入的,是从1.6版中的_Deferred对象中抽离的,主要用来进行函数队列的add.remove.fire.lock等操作,并提供onc ...
- jQuery 2.0.3 源码分析 回调对象 - Callbacks
源码API:http://api.jquery.com/jQuery.Callbacks/ jQuery.Callbacks()是在版本1.7中新加入的.它是一个多用途的回调函数列表对象,提供了一种强 ...
随机推荐
- Angular4学习笔记(五)- 数据绑定、响应式编程和管道
概念 Angular中的数据绑定指的是同一组件中控制器文件(.ts)与视图文件(.html)之间的数据传递. 分类 流向 单向绑定 它的意思是要么是ts文件为html文件赋值,要么相反. ts-> ...
- Map字符串类型去掉空格处理
Iterator it = data.keySet().iterator(); for (; it.hasNext();) { if( data.get(key) instanceof Strin ...
- 如何在Ubuntu 14.04 中使用Samba共享文件
1.安装 Samba 和图形配置工具 sudo apt-get install samba samba-common system-config-samba python-glade2 gksu 2. ...
- CentOS6.x 升级到 CentOS7.x(测试)
博文来源:http://leyewen.blog.163.com/ 官方升级教程:http://wiki.centos.org/TipsAndTricks/CentOSUpgradeTool ...
- 不可思议的颜色混合模式 mix-blend-mode (转)
开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...
- vba 调用 countif 函数问题
源数据是A1:G18,需求是在K列显示A1:A18中各单元格重复出现的次数.在L列中是用countif函数直接计算的, Private Sub test() Dim rng As Range, i A ...
- Matlab 瑞利信道仿真
转眼间三月都已经过去一半,一直找不到有什么可以写的,一直想等自己把LTE仿真平台搭好后,再以连载的形式记录下来.但是,后来一想,我必须先做好充分的铺垫,在这过程中也遇到了很多问题,及时留下点什么,也是 ...
- C++内存管理(转)
C++内存管理 [导语] 内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中获得了更好的性能,更大的自由,C++菜鸟的收获则是一遍一遍的检查代码和对C++的痛恨,但内存管理 ...
- 体验 PHP under .NET Core
昨天在 The week in .NET 中发现 Scott Hanselman 的这篇博文 Peachpie - Open Source PHP Compiler to .NET and WordP ...
- {Django基础八之cookie和session}一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session
Django基础八之cookie和session 本节目录 一 会话跟踪 二 cookie 三 django中操作cookie 四 session 五 django中操作session 六 xxx 七 ...