DOTween相比iTween,语法更优雅,效率更高,笔者将尽可能翻译完DOTween的官方文档。
Nomenclature(命名规则)
Tweener:A tween that takes control of a value and animates it.api
补间动画:管理一个值并在这个值上建立动画。app
Sequence:A special tween that, instead of taking control of a value, takes control of other tweens and animates them as a group.ide
序列:序列是特殊的补间动画,它并无论理值,而是管理其余的补间而且以一个群组的方式建立补间集合的动画。
函数
Tween:A generic word that indicates both a Tweener and a Sequence.oop
补间:一个笼统的单词,既能够表明补间动画也能够表明序列。动画
Nested tween:A tween contained inside a Sequence.this
嵌套补间:包含在序列中的补间。url
Prefixes(前缀)
Prefixes are important to use the most out of IntelliSense, so try to remember these:spa
前缀几乎是咱们在感官上识别如何准确使用的最重要的组成,因此请务必记住这些:翻译
-
DO
-
Prefix for all tween shortcuts (operations that can be started directly from a known object, like a transform or a material). Also the prefix of the main DOTween class.
-
DO是全部补间快捷方式(对于快捷方式的含义咱们在下一部分会提到)的前缀 ,DO做为前缀的补间能够对一个已知的对象进行操做,好比transform对象或material对象。这也是主要类 DOTween 的前缀。咱们看如下的示例:
-
1 ransform.DOMoveX(100, 1);
2 transform.DORestart();
3 DOTween.Play();
-
Set
-
Prefix for all settings that can be chained to a tween (except for From, since it’s applied as a setting but is not really a setting).
-
对于一个补间咱们能够还进行一些设置,这些设置咱们用Set做为前缀(From却没有使用Set做前缀,由于它以设置的方式使用但不是真正的设置) 。
-
1 myTween.SetLoops(4, LoopType.Yoyo).SetSpeedBased();
-
On
-
Prefix for all callbacks that can be chained to a tween.
-
对于一个补间,咱们还能够设置回调函数,这些回调函数用On做为前缀。
-
1 myTween.OnStart(myStartFunction).OnComplete(myCompleteFunction);
DOTween.Init(初始化)
The first time you create a tween, DOTween will initialize itself automatically, using default values.
第一次在建立补间,DOTween 会自动初始化自身,使用默认值。
If instead you prefer to initialize it yourself (recommended), call this methods once, BEFORE creating any tween (calling it afterwards will have no effect).
若是你倾向于本身手动将其初始化(推荐),请在建立爱你任何补间以前调用一次此方法(建立以后调用无效)。
Consider that you can still change all init settings whenever your want, by using DOTween’s global settings.
但经过DOTween的全局设置,您仍能够随时更改初始化设定。
Optionally, you can chain SetCapacity
to the Init method, which allows to set the max Tweeners/Sequences initial capacity (it’s the same as calling DOTween.SetTweensCapacitylater).
(可选) 您能够连接 SetCapacity 到 Init 方法中,设置最大补间动画/序列初始容量 (这和之后调用 DOTween.SetTweensCapacity 相同)。
DOTween的初始化函数是这样的:
1 static DOTween.Init(bool recycleAllByDefault = false, bool useSafeMode = true,LogBehaviourlogBehaviour = LogBehaviour.ErrorsOnly);
-
Initializes DOTween. Call it without any parameter to use the preferences you set in DOTween’s Utility Panel (otherwise they will be overrided by any eventual parameter passed).
-
初始化 DOTween时,若是不加任何参数,DOTween.Init方法会使用DOTween's Utility Panel的Preference中设定的值(若是你加了参数,这个参数会覆盖Preference中的设定值)。
-
recycleAllByDefault
-
If TRUE all new tweens will be set for recycling, meaning that when killed they won’t be destroyed but instead will be put in a pool and reused rather than creating new tweens. This option allows you to avoid GC allocations by reusing tweens, but you will have to take care of tween references, since they might result active even if they were killed (since they might have been respawned and might now be in use as other completely different tweens).
若是recycleAllByDefault设定为True,那么全部的补间在被Kill后不会被当即销毁,而是被存放起来而且在建立新的补间时会被重用。这个选项让你避免了重用补间时分配Garbage Collector。但你仍是必须当心对待tween的引用,由于这种模式可能致使tween在kill后被激活。
-
If you want to automatically set your tween references to NULL when a tween is killed you can use the OnKill callback like this
-
若是你想自动的在tween被kill后把tween的引用设置为空,你能够这样设置回调函数:
-
1 .OnKill(()=> myTweenReference = null)
You can change this setting at any time by changing the static DOTween.defaultRecyclable property, or you can set the recycling behaviour for each tween separately, using SetRecyclable.