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.