DoTween官方文档中文版(三)DOTween.Init
DOTween.Init(初始化)
The first time you create a tween, DOTween will initialize itself automatically, using default values.
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'sglobal settings
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).
- 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).
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).
If you want to automatically set your tween references to NULL when a tween is killed you can use the OnKill callback like this: -
初始化 DOTween。调用不带任何参数,使用你在 DOTween 的实用程序面板中设置的首选项 (否则他们将是脑子里自然所传递的任何最终的参数)。如果为 TRUE,新创建的所有补间将都设置回收,意思说当杀害他们的recycleAllByDefault 不会被破坏但相反会放在一个池子和重用而不是创建新补间。此选项允许您避免 GC 分配通过重用补间动画,但是你将不得不照顾补间的引用,因为他们可能会导致积极的即使他们被杀害 (因为它们可能会被respawned,现在可能正在使用作为其他完全不同的补间)。如果你想要自动设置补间引用为 NULL,当补间被杀害时你可以使用 OnKill 回调像这样:
.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
useSafeMode If set to TRUE tweens will be slightly slower but safer, allowing DOTween to automatically take care of things like targets being destroyed while a tween is running.
WARNING: on iOS safeMode works only if stripping level is set to "Strip Assemblies" or Script Call Optimization is set to "Slow and Safe".
logBehaviour Depending on the chosen mode DOTween will log only errors, errors and warnings, or everything plus additional informations. -
您可以通过更改了静态的 DOTween.defaultRecyclable 属性,更改此设置在任何时间,或者您可以设置为每个补间的回收行为分开,使用 SetRecyclable如果设置为 TRUE 的补间会稍慢,但更安全,允许 DOTween 自动照顾之类的目标被摧毁的补间运行时的 useSafeMode。警告: 安全模式在 iOS 的作品只有剥离级别设置为"地带组件"或脚本调用优化设置为"慢速和安全"。根据空房模式 DOTween logBehaviour 将记录仅错误、 错误和警告,或一切加上额外的信息。
// EXAMPLE A: initialize with the preferences set in DOTween's Utility Panel
DOTween.Init();
// EXAMPLE B: initialize with custom settings, and set capacities immediately
DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);