hotween 详细教程受timescale影响吗

Ohno! This column is so empty! What will I do now?
Maybe writing some non-sentences will help...
Like... CATAPRAXIS!
See the camel?
Revolution?
Megarobots are cool, but the conversation is quite boring
Sanity is overrated
Jelena is an awesome comic artist
History teaches us what went wrong, so that next time we can go wrong more quickly
x + 3 = Mister X
y + 4 = Madame Y
z + 5 = zzzzzz
Don't tell me you're reading this! Seriously?
No, that's not what I said. That's what YOU said
We are going doooown
And dooooowner!
Oh, look, more non-sentences below!
X: "Hey, have you seen my socks?"
Y: "What am I? Your sockretary?"
This will never end
I'm getting hungry. As soon as I finish writing these things I'm eating something big
Exploramation
What happened to Frank Miller?
I have a cat whose name is Blues, but she's not very bluesish
I wonder...
Is that a wall? A typewriter? A pumpkin? Oh no: it's Humbert! Hey, Humbert, you look good today!
I have 23 more of those, but I'll keep them for later...
Catapraxis! Oops, I'm repeating myself
Now this is the punishment for doing such long pages
Is this it?
Told you I was keeping some for later
Ulysses Rejoyce
Yes, I'm inventing all this stuff in a single session: that's what too much coding will bring you
Chester Brown: I just love his stuff
Did I mention that I was hungry?
No really, I'm stopping now
DOTween (HOTween v2) IS OUT!
More than 4x faster, more efficient, and with tons of new features.
All of HOTween methods and properties are fully documented, but code comments will work only with C# (UnityScript isn't able to decode them).
Luckily, automatic code completion will work with any programming language.
Here, we'll have a look at HOTween's installation, plus some basics. To get to know HOTween's full power and options, head to .
Installation
Simply unzip HOTween.zip anywhere inside your Unity project's Assets folder (but keep the DLL and the XML together, or you'll lose the code tooltips).
UnityScript and Boo
Create an Assets/Plugins folder in your Unity project (if you don't have it already), and unzip HOTween.zip there.
HOTween Editor
After installing HOTween's DLL, you can import HOTween's Editor package and it's done. You can
of its usage on the homepage.
Get ready to code
Before using HOTween, you will have to import its namespaces in your script (yes! namespaces! that's a thing I can't live without! the fact that open source Unity code doesn't support neither them nor internal members is the only reason I made a DLL :P):
using Holoville.HOT
using Holoville.HOTween.P
public class MyClass { ... }
UnityScript
import Holoville.HOT
import Holoville.HOTween.P
function Start () { ... }
HOTween basics
The tween creation logic is quite simple, and will be somehow familiar to you if you're used to other tween engines. You always use HOTween.To() (or HOTween.From()), and give it a target (which is the object that contains the property or field you wish to tween), a duration, and a series of parameters (like the properties to tween, the type of easing, the type and number of loops, eventual callbacks, and so on).
In these examples I will use Transforms, but keep in mind that HOTween can animate ANY non-static public property or field of ANY object.
Fast HOTween
Let's start with the most basic example. If you are in a real hurry, and just want to tween a single property using HOTween's default parameters, you can simply do this:
Fast: animate a Transform from its current position to x:10, y:20, z:30
HOTween.To(myGameObject.transform, 1, "position", new Vector3(10,20,30));
Where the parameters are: the object whose properties you want to tween, the duration of the tween, the name of the property to tween, and the value you want to tween to.
TipYou can change HOTween's default parameters at any time, by changing HOTween.defUpdateType, .defEaseType, .defLoopType or defTimeScale.
Full HOTween
If you want to control more parameters (like loop type and amount, ease type, etc.), or tween more than one property/field of the same target, you will need to use a TweenParms object and pass it to HOTween.To parameters (HOTween Sequence uses SequenceParms instead).
Code assist will automatically tell you what type of parameters you have at your disposal, just keep in mind that Prop(propName,endValue) is where you place the name of the property to tween and its end value, and that you can chain as many Prop as you wish.
To use TweenParms, you can either create it inline, adding all the Props and options you want via method chaining...
Inline method chaining to tween position + rotation + scale + set easing and delay
HOTween.To(myGameObject.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.EaseOutBounce).Delay(1));
...or create it separately and then pass it to HOTween...
Create parameters to tween position + rotation + scale + set easing and delay, and then apply them.
TweenParms parms = new TweenParms();
var parms:TweenParms = new TweenParms();
parms.Prop("position", new Vector3(10,20,30));
parms.Prop("rotation", new Vector3(0,720,0));
parms.Prop("localScale", new Vector3(4,4,4));
parms.Ease(EaseType.EaseOutBounce);
parms.Delay(1);
HOTween.To(myGameObject.transform, 1, parms );
...or, obviously, create it separately but inline.
Create inline parameters to tween position + rotation + scale + set easing and delay
TweenParms parms = new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.EaseOutBounce).Delay(1);
var parms:TweenParms = new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.EaseOutBounce).Delay(1);
HOTween.To(myGameObject.transform, 1, parms );
TipIf you want to store a TweenParms object for other HOTweens, changing only the Props, use NewProp(propName,endValue): it will clear any previous Props before applying the new one.
Why method chaining? I studied and implemented many ways (like Hashtables or object initializers), but I ended up deciding that this was the best one, because it's reliable and fast to write: 1) it's type-safe, 2) code assist will show you the available parameters while you type, and 3) code completion will quickly fill them.
TipThere is a special parameter called Pause(), which will force the newly created tween to start in a paused state.
TipHOTween gameObject's full name is HOTween : [total first-level* tweens and sequences]. Thus, if you're in the Editor, you can have an immediate feedback on how many tweens are running, just by looking at your hierarchy.
* First-level means only Tweeners and Sequences not nested inside other Sequences.
HOTween Sequence basics
Each time you call HOTween.To, a new Tweener is created and returned. You can let that object go by itself, or you can place it inside a Sequence, to create complex sequences of tweens and control them dinamically as they were one. Also, you can place Sequences inside other Sequences, to make things more fun.
Think of a Sequence as a timeline, where you place Tweeners or other Sequences at the position you decide. Also, it can be controlled as any video timeline would: play and pause it, but also rewind, restart, reverse, complete, or directly set its position (either with GoTo(position) or with mySequence.position=[time]).
Creating a Sequence
If you want to use a Sequence, first of all you'll have to create one (obviously, you are not limited to just one). You do it by simply calling new Sequence(parms), where parms work exactly the same way as TweenParms, but are of type SequenceParms.
Creating a new Sequence and set loops to 3 and loopType to Yoyo
mySequence = new Sequence(new SequenceParms().Loops(3,LoopType.Yoyo));
Adding tweens to a Sequence
Once you've created the sequence, you can add tweens to it by using mySequence.Append(tween), mySequence.Prepend(tween), or mySequence.Insert(atTime,tween).
Adding 3 Tweeners to a sequence
mySequence.Append(HOTween.To(myGameObject1.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.EaseOutBounce)));
mySequence.Prepend(HOTween.To(myGameObject2.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.EaseInElastic)));
mySequence.Insert(1, HOTween.To(myGameObject3.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.EaseOutQuad)));
TipYou can also append and prepend empty intervals to a Sequence, using AppendInterval(duration) and PrependInterval(duration).
TipTweeners and Sequences share the same IHOTweenComponent interface, with all the same controls like Play, Reverse, GoTo, Kill, etc.
Callbacks are added to a Tweener via TweenParms, and to a Sequence via SequenceParms, and they can be chained like the rest of the parameters:
Using HOTween.To with an onComplete callback
HOTween.To(myGameObject.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).OnComplete(MyFunction));
Creating a Sequence with an onComplete callback
mySequence = new Sequence(new SequenceParms().OnComplete(MyFunction));
You can check all the available callbacks in the .
TipCallbacks added to a Tweener/Sequence will work even if the Tweener/Sequence is added to another Sequence.
You can use 2 types of functions for HOTween callbacks. Which one will be used will depend on if you passed additional parameters when setting a tween's On[Something] parameter.
Callback type A: Parameterless function
A function that returns nothing and has no parameters:
C# Sample parameter-less callback function
HOTween.To(myGameObject.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).OnComplete(MyFunction));
private void MyFunction() {
UnityScript Sample parameter-less callback function
private function MyFunction() {
Callback type B: Function who accepts a TweenEvent parameter
A function that returns nothing (void) and has a single parameter of type TweenEvent, which will be sent by HOTween when a callback is invoked.
The TweenEvent object will contain 2 properties:
tweenEvent.tweena reference to the Tweener or Sequence to which the callback was added.
tweenEvent.parmsan array of the eventual additional parameters you wrote when setting the callback.
C# Sample TweenEvent callback function
HOTween.To(myGameObject.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).OnComplete(MyFunction,1,2,3));
private void MyFunction( TweenEvent e ) {
Debug.Log( e.tween );
if ( e.parms != null ) {
Debug.Log( e.parms[0] );
UnityScript Sample TweenEvent callback function
HOTween.To(myGameObject.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).OnComplete(MyFunction,1,2,3));
private function MyFunction( e:TweenEvent ) {
Debug.Log( e.tween );
if ( e.parms != null ) {
Debug.Log( e.parms[0] );
TipCallback functions can be public, private, static, internal, protected, or whatever.
TipOther than callbacks, you can use Coroutines, like WaitForCompletion. Check it in the Tweener and Sequence documentation.
All HOTween's animations work with plugins, but they are usually managed automatically. When adding a Prop parameter to HOTween.To, you normally just write the name of the property to tween and the end value, then HOTween finds by himself the correct plugin to apply, based on the property's type. This system works if you want to animate values in the default way, but sometimes you wish to use special kinds of animations. That's when you can directly assign special plugins to a Prop parameter.
For example, if you animate a Vector3 property, HOTween automatically uses the PlugVector3 plugin, which animates the x/y/z values linearly from the starting vector to the ending one. If you want to animate only the Y value of the vector, you might instead tell him to use the PlugVector3Y plugin. Or, if you wish to move along a path, you might use the PlugVector3Path plugin.
Let's see a simple example.
Animating only the Y axis of a Vector3 property, with PlugVector3Y
HOTween.To(myGameObject.transform, 1, new TweenParms().Prop("position", new PlugVector3Y(20)));
All plugins have additional optional parameters that you can set, like the easing for that property, or if the value should be considered relative or absolute (think of relative as moving a value BY instead than TO). Also, some plugins have even more additional parameters that are set with method chaining (like PlugVector3Path, which lets you choose if the path should be smoothly closed automatically, and the type of orientation).
That's it for the basics. For a full list of available plugins, see the .shubozhang&
1&基本插值
HOTween&只能对物体的任何非静态共有属性或者字段做插值
TweenParms.Prop(propName,endValue)&设定被插值的属性和最后的值(可以多次调用指定多个被插值的属性)
TweenParms.Ease(easeType)&指定渐变类型,这里使用Linear表示线性渐变
HOTween.To(object,time,params)&To表示从现在的值经过插值后变换到endValue,time表示整个变换进行的时间,params定义了其他参数
(HOTween.From(object,time,params)&把To改用From表示从被指定的endValue经过变换后,成为当前的值)
void&Start&()&
TweenParms&params&=&new&TweenParms();
&&&&parms.Prop("postion",&new&Vector3(2.0f,0.0f,0.0f));&//坐标
&&&&parms.Ease(EaseType.Linear);&//加速度类型
&&&&HOTween.To(gameObject.transform,&2,&params);
绑定到该游戏的对象从原来的位置经过两秒移动到了位置(2.0f,0.0f,0.0f)&最后停止在(2.0f,0.0f,0.0f)
移动的速度为匀速,改变移动的速度可以选用其他的渐变类型
其他可选的渐变类型包括:
EaseInSine&=&1,EaseOutSine&=&2,EaseInOutSine&=&3,
EaseInQuad&=&4,EaseOutQuad&=&5,EaseInOutQuad&=&6,
EaseInCubic&=&7,EaseOutCubic&=&8,EaseInOutCubic&=&9,
EaseInQuart&=&10,EaseOutQuart&=&11,EaseInOutQuart&=&12,
EaseInQuint&=&13,EaseOutQuint&=&14,EaseInOutQuint&=&15,
EaseInExpo&=&16,EaseOutExpo&=&17,EaseInOutExpo&=&18,
EaseInCirc&=&19,EaseOutCirc&=&20,EaseInOutCirc&=&21,
EaseInElastic&=&22,EaseOutElastic&=&23,EaseInOutElastic&=&24,
EaseInBack&=&25,EaseOutBack&=&26,EaseInOutBack&=&27,
EaseInBounce&=&28,EaseOutBounce&=&29,EaseInOutBounce&=&30,
AnimationCurve&=&31
2&使用自定义的曲线关键点进行插值
void&Start&()&
&&&&Vector3[]&points&=&new&Vector3[2];
&&&&points[0]&=&new&Vector3(2.0f,&0.0f,&0.0f);
&&&&points[1]&=&new&Vector3(2.0f,&1.0f,&0.0f);
&&&&TweenParms&parms&=&new&TweenParms();
&&&&parms.Prop("position",&new&PlugVector3Path(points,PathType.Linear));&//坐标
&&&&parms.Ease(EaseType.Linear);&//加速度类型
&&&&HOTween.To(gameObject.transform,&2,&parms);
游戏对象先移动到了(2.0f,&0.0f,&0.0f)然后立即移动到了(2.0f,&1.0f,&0.0f)一共花了两秒
3&将插值的动画进行连续播放
void&Start&()&
&&&&&&&&Sequence&seq&=&new&Sequence(new&SequenceParms().Loops(1,LoopType.Yoyo));
&&&&&&&&TweenParms&parms&=&null;
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",new&Vector3(1.0f,0.0f,0.0f))
&&&&&&&&&&&&.Ease(EaseType.Linear);
&&&&&&&&seq.Append(HOTween.To(gameObject.transform,1,parms));
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",&new&Vector3(1.0f,&1.0f,&0.0f))
&&&&&&&&&&&&.Ease(EaseType.Linear);
&&&&&&&&seq.Append(HOTween.To(gameObject.transform,&1,&parms));
&&&&&&&&seq.Play();
4&在动画结束时进行方法回调
代码:没有参数的
&&&&void&Start&()&
&&&&&&&&TweenParms&parms&=&null;
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",&new&Vector3(1.0f,&0.0f,&0.0f))
&&&&&&&&&&&&.OnComplete(OnComplete);
&&&&&&&&HOTween.To(gameObject.transform,&1,&parms);
&&&&private&void&OnComplete()
&&&&&&&&Debug.Log("OnComplete&Called!");
代码:有参数的
&&&&void&Start&()&
&&&&&&&&TweenParms&parms&=&null;
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",&new&Vector3(1.0f,&0.0f,&0.0f))
&&&&&&&&&&&&.OnComplete(OnComplete,&50,&Vector3.one);
&&&&&&&&HOTween.To(gameObject.transform,&1,&parms);
&&&&private&void&OnComplete(TweenEvent&e)
&&&&&&&&Debug.Log(e.parms[0]);//第一个参数
&&&&&&&&Debug.Log(e.parms[1]);//第二个参数
5&Loops方法
TweenParms.Loops(times,loopType)
通过该方法可以指定一次插值动画的循环属性
包括以下几种loopType
&&&&public&enum&LoopType
&&&&&&&&Restart&=&0,Yoyo&=&1,YoyoInverse&=&2,Incremental&=&3,
Restart代码:
&&&&void&Start&()&
&&&&&&&&TweenParms&parms&=&null;
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",&new&Vector3(1.0f,&0.0f,&0.0f))
&&&&&&&&&&&&.Loops(2,&LoopType.Restart);
&&&&&&&&HOTween.To(gameObject.transform,&1,&parms);
效果:一共播放动画两次,第一次对象从起点运动到了(1.0f,&0.0f,&0.0f),
然后瞬间移动到原点播放第二次动画,效果和第二次相同,最后物体停止在(1.0f,&0.0f,&0.0f)。
Yoyo&代码:
&&&&void&Start&()&
&&&&&&&&TweenParms&parms&=&null;
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",&new&Vector3(1.0f,&0.0f,&0.0f))
&&&&&&&&&&&&.Loops(2,&LoopType.Yoyo);
&&&&&&&&HOTween.To(gameObject.transform,&1,&parms);
效果:一共播放动画两次,第一次对象从起点运动到了(1.0f,&0.0f,&0.0f),
然后开始播放第二次动画,从(1.0f,&0.0f,&0.0f)运动到原点,最后停止在原点。
YoyoInverse代码:
&&&&void&Start&()&
&&&&&&&&TweenParms&parms&=&null;
&&&&&&&&parms&=&new&TweenParms()
&&&&&&&&&&&&.Prop("position",&new&Vector3(1.0f,&0.0f,&0.0f))
&&&&&&&&&&&&.Loops(2,&LoopType.YoyoInverse);
&&&&&&&&HOTween.To(gameObject.transform,&1,&parms);
效果:和Yoyo运动的方式相同先运动到(1.0f,&0.0f,&0.0f)在运动回原点,
但是,Yoyo对EaseType不产生影响,YoyoInverse还会对EaseType产生相反的影响。
6&处理对静态变量的插值
有时一些静态变量也需要插值操作,但是HOTween不能直接对其进行操作,所以需要做一个代理,这里使用Time.timeScale进行举例。
&&&&class&TimeScaleTweenProxy
&&&&&&&&public&float&Value
&&&&&&&&&&&&get
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&return&Time.timeS
&&&&&&&&&&&&}
&&&&&&&&&&&&set
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&Time.timeScale&=&value;
&&&&&&&&&&&&}
void&Start&()&
TimeScaleTweenProxy&proxy&=&new&TimeScaleTweenProxy();
&&&& TweenParms&parms&=&null;
&&&& parms&=&new&TweenParms()
&&&&&&&&&&&.Prop("Value",&0.4)
&&&&&&&&&&&.Ease(EaseType.EaseOutCubic)
HOTween.To(proxy,&duration,&parms);
7&其他:&delay方法,多次设置prop,from的使用
使用Delay动画将被延时播放
void&Start&()&
TweenParms&params&=&new&TweenParms();
&&&& parms.Prop("postion",&new&Vector3(2.0f,0.0f,0.0f));&//坐标
&&&& parms.Ease(EaseType.Linear);&//加速度类型
parms.Delay(1.0f);
&&&& HOTween.To(gameObject.transform,&2,&params);
可以设置多个prop同时进行插值
void&Start&()&
TweenParms&params&=&new&TweenParms();
parms.Prop("postion",&new&Vector3(2.0f,0.0f,0.0f));&//坐标
parms.Prop("rotation",&new&Vector3(0.0f,180.0ff,0.0f));
parms.Ease(EaseType.Linear);&//加速度类型
HOTween.From(gameObject.transform,&2,&params);
使用From播放动画运动路径是和To相反的
void&Start&()&
TweenParms&params&=&new&TweenParms();
parms.Prop("postion",&new&Vector3(2.0f,0.0f,0.0f));&//坐标
parms.Ease(EaseType.Linear);&//加速度类型
HOTween.From(gameObject.transform,&2,&params);
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有iTween那些事儿(二) - 推酷
iTween那些事儿(二)
&&上次我们简单浏览了一番
的使用和原理,这次我们换个角度,转而看看
目前存在的一些缺陷以及一点点可能的改进之处,当然,这些所谓的缺陷或者改进都仅是我的一家之言,不足信也
二.&iTween
参数类型不够安全
&&问题主要出在
的使用上,上篇我们提到了
来作为接口参数传递的媒介容器,而
本身仅使用最松散的
System.Object
类型来管理内部的键值数据,自然就会产生不少安全隐患,考虑以下代码:
&&iTween.ScaleFrom(gameObject,&iTween.Hash(
&&&&&&&scale&,&2,&
&&&&&&&time&,&1,&
&&&&&&&islocal&,&true));
&&明眼人可能马上就发现了问题:
参数对应的数值应该为
,而上面代码中却给出了一个整数
,而相关代码的编译甚至连一个警告都看不到,我们能得到的可能就是运行期
的一个警告以及出人意料的动画效果……不知你对于这个问题看法如何,我本人确实曾在这个问题上栽过跟头,当时不经意间也写出了类似上面一般的代码,然后便是一段很久很久的代码排查……
字符串传参不够健壮
采用了字符串的方式来传递控制参数,譬如“
”便是位置,“
”就是时间,虽然直观方便,但是也至少存在不够健壮的问题,考虑以下代码:
&&iTween.MoveTo(gameObject,&iTween.Hash(
&&&&&&&positoin&,&Vector3.zero,&
&&&&&&&time&,&1,&
&&&&&&&islocal&,&true));
&&代码编译没有任何问题,参数类型似乎也没什么错误,甚至在运行过程中可能都看不到一个警告,但是相应的
gameObject
就是不会按照“指示”来进行移动!问题出在我们错误的将“
”参数输入成了“
”,由于是字符串的关系,编译器自然不会有任何抱怨,甚至于
都仅会认为这是一个他不认识的参数而加以忽略,只剩下我们对着奇怪的动画现象百思不解……
运行机制有待改进
&&正如上篇所说,
GameObject
的方式来实现相应的动画表现,这种运行机制在简单情况下并没有什么问题,但是当我们面对游戏场景中存在大量的动画物体,或者说某个物体需要大量的动画控制的时候,
这种运行方式所带来的内存消耗、效率损失可能就有些让人难以接受了,试想我们仅仅为了新增一个
动画属性,就必须要承担整个
MonoBehaviour
组件所带来的影响,着实有些得不偿失,换个角度,如果我们可以通过某种方式将这些动画控制集中管理,即通过譬如单个组件来统一管理
GameObject
的各个缓动属性,提高效率、节省内存的同时,还能做到集中管理,岂不快哉?
代码实现不够高效
版本(我使用的是
版本)实现中仍然存在一些效率不高的代码,譬如上篇提到的回调处理,
内部使用了
SendMessage
的方法来进行实现,改以代理方式实现我觉得应该更高效,也更整洁&:)
代码实现仍然存在一些细微
版本实现中也依旧存在一些细微
,我所看到的大概有以下两个问题:
&&A.&iTween
在销毁自身的时候,会依据
属性来更新一些内部状态,而这个
GameObject
时内部生成的,也就是说
这个属性对于我们使用者来说是完全透明的,按理不会出什么问题,但是
在生成这个
时使用了简单的随机算法,个人感觉并不能完全做到
生成的唯一性,因此可能产生
冲突,造成内部状态错误,个人认为改用譬如
之类的实现方式应该更好
可能就是一个“笔误”了,问题出在
对于冲突组件的处理上,按照上篇提到的说法,
会将冲突组件进行剔除,譬如以下代码:
using&UnityE
class&iTweenBugTest&:&MonoBehaviour&{
void&Start()&{
iTween.MoveTo(gameObject,&iTween.Hash(
&&&&&&&&&&&&“name”,&“MoveToFirst”,
&&&&&&&&&&&&“position”,&Vector3.zero,
&&&&&&&&&&&&“time”,&5
&&&&&&&&));
iTween.MoveTo(gameObject,&iTween.Hash(
&&&&&&&&&&&&“name”,&“MoveToSecond”,
&&&&&&&&&&&&“position”,&Vector3.zero,
&&&&&&&&&&&&“delay”,&1
&&&&&&&&&&&&“time”,&5
&&&&&&&&));
中运行以上脚本,你会发现初始状态时,
GameObject
会被添加两个
组件,分别名为“
MoveToFirst
MoveToSecond
组件就只剩下“
MoveToSecond
”了,这便是
对于冲突组件的特殊处理,但是,如果你改以运行以下代码:
using&UnityE
class&iTweenBugTest&:&MonoBehaviour&{
void&Start()&{
&&&&iTween.ValueTo(gameObject,&iTween.Hash(
&&&&&&&&&&&&“name”,&“ValueTo”,
&&&&&&&&&&&&“from”,&1,
&&&&&&&&&&&&“to”,&2,
&&&&&&&&&&&&“onupdate”,&“OnUpdate”,
&&&&&&&&&&&&“time”,&5
&&&&&&&&));
iTween.MoveTo(gameObject,&iTween.Hash(
&&&&&&&&&&&&“name”,&“MoveToFirst”,
&&&&&&&&&&&&“position”,&Vector3.zero,
&&&&&&&&&&&&“time”,&5
&&&&&&&&));
iTween.MoveTo(gameObject,&iTween.Hash(
&&&&&&&&&&&&“name”,&“MoveToSecond”,
&&&&&&&&&&&&“position”,&Vector3.zero,
&&&&&&&&&&&&“delay”,&1
&&&&&&&&&&&&“time”,&5
&&&&&&&&));
void&OnUpdate()&{
&&那么你就会发现原本应该被剔除的“
MoveToFirst
”却自始至终完好无损了,原因应该是
实现上的一个疏漏,有兴趣的朋友可以仔细看看相关的
ConflictCheck
实用功能仍然缺乏
&&在游戏中,一个物体的动画并不是离散独立的,往往都是几个动画所组成的序列,所以一个健壮的
实现基本是所有游戏必不可少的组件,譬如
就为此提供了
CCSequence
,但在这点上,
却并没有提供类似功能,我们目前只能借助
oncomplete
回调,或者
之类的机制来模拟实现,让人感觉着实不便
代码实现风格不佳
&&这一点个人倾向多一点,可能自己
接触比较多了,对于
这种“整一块”的实现方式不是特别认同,感觉身材臃肿、逻辑交纵以外,难以扩展也是一大问题;再者
代码实现中有着非常浓重的
味道,可能是历史原因造成,个人也不是很喜欢
二.&iTween
&&说是改进,其实是算不得的,上面提到的很多问题如果真要修改,很多也都是“伤筋动骨”的活儿,真搞起来可能还得不偿失,在此我仅仅写了一个适用于
,意在减轻参数类型不够安全等问题带来的影响,实现很简单,就直接贴代码了:
using&System.C
using&UnityE
class&iTweenHashtable&{
public&delegate&void&iTweenCallback();
public&delegate&void&iTweenCallbackParam(System.Object&param);
Hashtable&m_innerTable&=&new&Hashtable();
public&iTweenHashtable&Name(string&name)&{
m_innerTable[&name&]&=&
&&&&return&
public&iTweenHashtable&From(float&val)&{
&&&&m_innerTable[&from&]&=&
public&iTweenHashtable&From(double&val)&{
&&&&m_innerTable[&from&]&=&
public&iTweenHashtable&From(Vector3&val)&{
&&&&m_innerTable[&from&]&=&
public&iTweenHashtable&From(Vector2&val)&{
&&&&m_innerTable[&from&]&=&
public&iTweenHashtable&From(Color&val)&{
&&&&m_innerTable[&from&]&=&
public&iTweenHashtable&From(Rect&val)&{
&&&&m_innerTable[&from&]&=&
public&iTweenHashtable&To(float&val)&{
&&&&m_innerTable[&to&]&=&
public&iTweenHashtable&To(double&val)&{
&&&&m_innerTable[&to&]&=&
public&iTweenHashtable&To(Vector3&val)&{
&&&&m_innerTable[&to&]&=&
public&iTweenHashtable&To(Vector2&val)&{
&&&&m_innerTable[&to&]&=&
public&iTweenHashtable&To(Color&val)&{
&&&&m_innerTable[&to&]&=&
public&iTweenHashtable&To(Rect&val)&{
&&&&m_innerTable[&to&]&=&
public&iTweenHashtable&Amount(Vector3&amount)&{
m_innerTable[&amount&]&=&
&&&&return&
public&iTweenHashtable&Space(Space&space)&{
&&&&m_innerTable[&space&]&=&
public&iTweenHashtable&Position(Vector3&position)&{
&&&&m_innerTable[&position&]&=&
public&iTweenHashtable&Rotation(Vector3&rotation)&{
&&&&m_innerTable[&rotation&]&=&
public&iTweenHashtable&Scale(Vector3&scale)&{
&&&&m_innerTable[&scale&]&=&
public&iTweenHashtable&IsLocal(bool&isLocal)&{
&&&&m_innerTable[&islocal&]&=&isL
public&iTweenHashtable&Time(float&time)&{
&&&&m_innerTable[&time&]&=&
public&iTweenHashtable&Time(double&time)&{
&&&&m_innerTable[&time&]&=&
public&iTweenHashtable&Speed(float&speed)&{
&&&&m_innerTable[&speed&]&=&
public&iTweenHashtable&Speed(double&speed)&{
&&&&m_innerTable[&speed&]&=&
public&iTweenHashtable&Delay(float&delay)&{
&&&&m_innerTable[&delay&]&=&
public&iTweenHashtable&Delay(double&delay)&{
&&&&m_innerTable[&delay&]&=&
public&iTweenHashtable&EaseType(iTween.EaseType&easeType)&{
&&&&m_innerTable[&easetype&]&=&easeT
public&iTweenHashtable&LoopType(iTween.LoopType&loopType)&{
m_innerTable[&looptype&]&=&loopT
public&iTweenHashtable&OnStart(iTweenCallback&onStart)&{
&&&&m_innerTable[&onstart&]&=&onStart.Method.N
var&target&=&onStart.Target&as&MonoB
AssertUtil.Assert(target&!=&null);
m_innerTable[&onstarttarget&]&=&target.gameO
public&iTweenHashtable&OnStart(iTweenCallbackParam&onStart,&System.Object&param)&{
&&&&m_innerTable[&onstart&]&=&onStart.Method.N
var&target&=&onStart.Target&as&MonoB
AssertUtil.Assert(target&!=&null);
m_innerTable[&onstarttarget&]&=&target.gameO
//&NOTE:&seems&iTween&can&not&handle&this&correct&...
//&&&&&&&in&iTween.CleanArgs,&it&just&do&raw&element&access
AssertUtil.Assert(param&!=&null);
m_innerTable[&onstartparams&]&=&
public&iTweenHashtable&OnUpdate(iTweenCallback&onUpdate)&{
&&&&m_innerTable[&onupdate&]&=&onUpdate.Method.N
var&target&=&onUpdate.Target&as&MonoB
AssertUtil.Assert(target&!=&null);
m_innerTable[&onupdatetarget&]&=&target.gameO
public&iTweenHashtable&OnUpdate(iTweenCallbackParam&onUpdate,&System.Object&param)&{
&&&&m_innerTable[&onupdate&]&=&onUpdate.Method.N
var&target&=&onUpdate.Target&as&MonoB
AssertUtil.Assert(target&!=&null);
m_innerTable[&onupdatetarget&]&=&target.gameO
//&NOTE:&seems&iTween&can&not&handle&this&correct&...
//&&&&&&&in&iTween.CleanArgs,&it&just&do&raw&element&access
AssertUtil.Assert(param&!=&null);
m_innerTable[&onupdateparams&]&=&
public&iTweenHashtable&OnComplete(iTweenCallback&onComplete)&{
&&&&m_innerTable[&oncomplete&]&=&onComplete.Method.N
var&target&=&onComplete.Target&as&MonoB
AssertUtil.Assert(target&!=&null);
m_innerTable[&oncompletetarget&]&=&target.gameO
&&&&return&
public&iTweenHashtable&OnComplete(iTweenCallbackParam&onComplete,&System.Object&param)&{
&&&&m_innerTable[&oncomplete&]&=&onComplete.Method.N
var&target&=&onComplete.Target&as&MonoB
AssertUtil.Assert(target&!=&null);
m_innerTable[&oncompletetarget&]&=&target.gameO
//&NOTE:&seems&iTween&can&not&handle&this&correct&...
//&&&&&&&in&iTween.CleanArgs,&it&just&do&raw&element&access
AssertUtil.Assert(param&!=&null);
m_innerTable[&oncompleteparams&]&=&
&&&&return&
public&iTweenHashtable&IgnoreTimeScale(bool&ignoreTimeScale)&{
&&&&m_innerTable[&ignoretimescale&]&=&ignoreTimeS
public&void&Clear()&{
&&&&m_innerTable.Clear();
public&static&implicit&operator&Hashtable(iTweenHashtable&table)&{
return&table.m_innerT
&&再贴个使用范例,有兴趣的朋友可以看看:
using&UnityE
class&iTweenTest&:&MonoBehaviour&{
void&Start()&{
iTweenHashtable&paramsTable&=&new&iTweenHashtable();
paramsTable.Name(&move_to_test&).
&&&&&&&&Delay(5).
&&&&Position(new&Vector3(10,&0,&0)).Time(5).IsLocal(false).
&&&&OnStart(OnStart).
&&&&OnComplete(OnComplete);
iTween.MoveTo(gameObject,&paramsTable);
void&OnStart()&{
&&&&Debug.Log(&start&time&:&&&+&Time.time);
void&OnComplete()&{
&&&&Debug.Log(&end&time&:&&&+&Time.time);
&&网上还有另一个与
的设计和实现就相对
的多,其官网上还有一些其与
比较的文字,有兴趣的朋友可以仔细看看,个人认为如果项目允许的话,可以考虑使用
,或者说结合使用两者,毕竟就像
作者自己所说那样,
的定位是有所差异的,提供的功能也是各有不同的,并不存在哪个取代哪个的问题
,今天就扯这么多了,有机会下次再见了
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 hotween 教程 的文章

 

随机推荐