DOTween开发⽂档中⽂版
DOTween相⽐iTween,语法更优雅,效率更⾼,笔者将尽量翻译完DOTween的官⽅⽂档。
Nomenclature(命名规则)
Tweener:A tween that takes control of a value and animates it.
补间动画:管理⼀个值并在这个值上创建动画。
Sequence:A special tween that, instead of taking control of a value, takes control of other tweens and animates them as a group.
序列:序列是特殊的补间动画,它并不管理值,⽽是管理其他的补间并且以⼀个组的⽅式创建补间集合的动画。
Tween:A generic word that indicates both a Tweener and a Sequence.
补间:⼀个笼统的单词,既可以代表补间动画也可以代表序列。
Nested tween:A tween contained inside a Sequence.
嵌套补间:包含在序列中的补间。
Prefixes(前缀)
Prefixes are important to use the most out of IntelliSense, so try to remember these:
前缀⼏乎是我们在感官上识别如何准确使⽤的最重要的组成,所以请务必记住这些:
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.
transform中文翻译DO是所有补间快捷⽅式(对于快捷⽅式的含义我们在下⼀部分会提到)的前缀,DO作为前缀的补间可以对⼀个已知的对象进⾏操作,⽐如transform对象或material对象。这也是主要类 DOTween 的前缀。我们看以下的⽰例:
1 ransform.DOMoveX(100, 1);
2t ransform.DORestart();
3D OTween.Play();
Set
Prefix for all settings that can be chained to a tween (except for , 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
但通过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 later).
(可选)您可以链接 SetCapacity 到 Init ⽅法中,设置最⼤补间动画/序列初始容量(这和以后调⽤ DOTween.SetTweensCapacity 相同)。
DOTween的初始化函数是这样的:
1static 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 no
w 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 property, or you can set the recycling behaviour for each tween separately, using
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论