Recommended reading

  • CSDN home page
  • GitHub open source address
  • Unity3D plug-in sharing
  • Jane’s address book
  • My personal blog
  • QQ group: 1040082875

One, foreword

DOTween is a fast, efficient, fully type-safe object-oriented animation engine for Unity, optimized for c# users, free and open source, with a number of advanced features

DOTween is compatible with Unity 2019 through 4.6. Suitable for: WebPlayer, WebGL, iOS, Android, Windows Phone, Windows Store, PS Vita (PSM) PS3/PS4, Xbox 360/One, Nintendo Switch + More (no additional platforms tested, but it should work anywhere except Flash export)

DOTweenPro extends DOTweenPro with new script shortcuts, a visual animation editor, a visual path editor, and additional features. The 2D kit and TextMesh Pro. DoTweenPro are available for a fee

Second, the download

The official download address: dotween.demigiant.com/downloads/D… Download page: dotween.demigiant.com/download.ph… Open source: github.com/Demigiant/d…

3. Installation steps

Step 1: Import Settings

First, once the download is complete, unzip the package anywhere and place it under your project folder Assets (just don’t put it in your Editor, Plugins or Resources directory) You must set up DoTween and activate/deactivate the module in order to import/re-import additional libraries based on your Unity version. To Setup DoTween, open the DoTween panel in Unity and select Setup DoTween from Tools/Demigiant

Step 2: Import the namespace

Import the DOTween namespace in each class/script that will use it:

using DG.Tweening;
Copy the code

Step 3 (Optional) : Set global parameters

Initializing the DOTWIN To set global options, perform the following operations:

DOTween.Init(autoKillMode, useSafeMode, logBehaviour);
Copy the code

If you don’t do this (or do so after you create the first DOTween), then the DOTween will be automatically initialized with the default Settings.

4. Global and specific Settings

You can set it globally and it will apply to all newly created Tweens, or compulsive Settings. Certain Settings will apply to the particular tweent you create

Global Settings

Global Settings allow you to set default autoPlay and autoKill behaviors, ease Type, global time scaling, and more.

Specific Settings

Certain Settings, the ease Type, the callback, the number of loops can be set by linking, so intellisense can help you find them.

Here are some examples of link operations:

// Create a Transform tween and set its Ease, Loops, and OnComplete callbackstransform.DOMove(new Vector3(2.2.2), 2).SetEase(Ease.OutQuint).SetLoops(4).OnComplete(myFunction);// Same as above, but use newlines to make it easier to readtransform.DOMove(new Vector3(2.2.2), 2)  .SetEase(Ease.OutQuint)  .SetLoops(4)  .OnComplete(myFunction);// Same as above, but there is no link between storing tween and applying SettingsTween myTween = transform.DOMove(new Vector3(2.2.2), 2); myTween.SetEase(Ease.OutQuint); myTween.SetLoops(4); myTween.OnComplete(myFunction);Copy the code

SetOptions() is a special function. SetOptions() is used to instantly link the transform while tween is being animated. Take a look at this example:

transform.DOMove(new Vector3(2.2.2), 2)  .SetOptions(true)  .SetEase(Ease.OutQuint)  .SetLoops(4)  .OnComplete(myFunction);Copy the code

In addition, you can use SetAs to copy all the current Settings from one middle to another without having to copy a lot of code:

// Use some Settings to create a tween and store it as a tweenTween myTween = transform.DOMove(new Vector3(2.2.2), 2)  .SetEase(Ease.OutQuint)  .SetLoops(4)  .OnComplete(myFunction);// Create another Tween and apply the same Settings as the previous onematerial.DOColor(Color.red,2).SetAs(myTween);
Copy the code

Cache and maximise Tween

To avoid unnecessarily using more resources, it sets itself up to 200 Tweener and 50 sequences running simultaneously. If you need more, DOTween will automatically increase its size, but you can also set it directly when auto resizing:

// Set maximum gradient to 3000 and maximum sequence to 200DOTween.SetTweensCapacity(3000.200);
Copy the code

Start Tween

DOTween can be used in a fully generic way, like this:

Or you can use its shortcut keys, like this:

Create a DOTween

So far, DOTween can convert between values of these types: Float, double, int, uint, Long, ulong, Vector2/3/4, Quaternion, Rect, RectOffset, Color, String (some of these values can be in special ways)

In addition, you can create a custom DOTween plug-in to switch between custom value types:

There are three ways to create a DOTween: the general way, the shortcut keys, and some other general way

A. General

This is the most flexible way to create and allows you to convert between all the values. Public or private, static or dynamic: Examples:Getter: a delegate that returns a property value as tween. It can be written like this: ()=> myValue, the name of the myValue attribute:. Setter: delegate that sets the property value to a gradient. This can be written in the form x=> myValue = x to: the final value to be reached. Duration: Indicates the duration of the transition.

Example:

// add a vector called myVector to (3,4,8) in 1 secondDOTween.To(()=> myVector, x=> myVector = x,new Vector3(3.4.8), 1);// Tween a float named myFloat to 52 in 1 secondDOTween.To(()=> myFloat, x=> myFloat = x,52.1);
Copy the code

B. Shortcut keys

DOTween controls known Unity objects such as Transform, rigidbody, Material, etc. References to these objects can be directly manipulated using shortcut keys, such as:

transform.DOMove(new Vector3(2.3.4), 1); rigidbody.DOMove(new Vector3(2.3.4), 1); material.DOColor(Color.green,1);
Copy the code

Basic shortcut keys

AudioMixer (Unity 5)

  • DOSetFloat(string floatName, float to, float duration)

AudioSource

  • DOFade(float to, float duration)
  • DOPitch(float to, float duration)

Camera

  • DOAspect(float to, float duration)
  • DOColor(Color to, float duration)
  • DOFarClipPlane(float to, float duration)
  • DOFieldOfView(float to, float duration)
  • DONearClipPlane(float to, float duration)
  • DOOrthoSize(float to, float duration)
  • DOPixelRect(Rect to, float duration)
  • DORect(Rect to, float duration)
  • DOShakePosition(float duration, float/Vector3 strength, int vibrato, float randomness, bool fadeOut)
  • DOShakeRotation(float duration, float/Vector3 strength, int vibrato, float randomness, bool fadeOut)

Light

  • DOColor(Color to, float duration)
  • DOIntensity(float to, float duration)
  • DOShadowStrength(float to, float duration)
  • Blendable tweens
  • DOBlendableColor(Color to, float duration)

LineRenderer

  • DOColor(Color2 startValue, Color2 endValue, float duration)

Material

  • DOColor(Color to, float duration)
  • DOColor(Color to, string property, float duration)
  • DOColor(Color to, int propertyID, float duration)
  • DOFade(float to, float duration)
  • DOFade(float to, string property, float duration)
  • DOFade(float to, int propertyID, float duration)
  • DOFloat(float to, string property, float duration)
  • DOFloat(float to, int propertyID, float duration)
  • DOGradientColor(Gradient to, float duration)
  • DOGradientColor(Gradient to, string property, float duration)
  • DOGradientColor(Gradient to, int propertyID, float duration)
  • DOOffset(Vector2 to, float duration)
  • DOOffset(Vector2 to, string property, float duration)
  • DOOffset(Vector2 to, int propertyID, float duration)
  • DOTiling(Vector2 to, float duration)
  • DOTiling(Vector2 to, string property, float duration)
  • DOTiling(Vector2 to, int propertyID, float duration)
  • DOVector(Vector4 to, string property, float duration)
  • DOVector(Vector4 to, int propertyID, float duration)

Blendable tweens

  • DOBlendableColor(Color to, float duration)
  • DOBlendableColor(Color to, string property, float duration)
  • DOBlendableColor(Color to, int propertyID, float duration)

The Rigidbody shortcuts use the move position/move rotate method of the Rigidbody in the background to properly animate things related to the physical object. Move

  • DOMove(Vector3 to, float duration, bool snapping)
  • DOMoveX/DOMoveY/DOMoveZ(float to, float duration, bool snapping)
  • DOJump(Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping)

EndValue jumpPower: the force of the jump numJumps: the height of the jump duration: The duration of the jump If true, tanner will successfully capture all values to integers. Rotate

  • DORotate(Vector3 to, float duration, RotateMode mode)
  • DOLookAt(Vector3 towards, float duration, AxisConstraint axisConstraint = AxisConstraint.None, Vector3 up = Vector3.up)
  • DOSpiral(float duration, Vector3 axis = null, SpiralMode mode = SpiralMode.Expand, float speed = 1, float frequency = 10, float depth = 0, bool snapping = false)

Rigidbody2D these shortcuts in the background using Rigidbody2D MovePosition/MoveRotation method to correctly animation related to physical objects. Move

  • DOMove(Vector2 to, float duration, bool snapping)
  • DOMoveX/DOMoveY(float to, float duration, bool snapping)
  • DOJump(Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping)

Rotate

  • DORotate(float toAngle, float duration)

SpriteRenderer

  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)
  • DOGradientColor(Gradient to, float duration)

Blendable tweens

  • DOBlendableColor(Color to, float duration)

TrailRenderer

  • DOResize(float toStartWidth, float toEndWidth, float duration)
  • DOTime(float to, float duration)

Transform Move

  • DOMove(Vector3 to, float duration, bool snapping)
  • DOMoveX/DOMoveY/DOMoveZ(float to, float duration, bool snapping)
  • DOLocalMove(Vector3 to, float duration, bool snapping)
  • DOLocalMoveX/DOLocalMoveY/DOLocalMoveZ(float to, float duration, bool snapping)
  • DOJump(Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping)
  • DOLocalJump(Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping)

Rotate

  • DORotate(Vector3 to, float duration, RotateMode mode)
  • DORotateQuaternion(Quaternion to, float duration)
  • DOLocalRotate(Vector3 to, float duration, RotateMode mode)
  • DOLocalRotateQuaternion(Quaternion to, float duration)
  • DOLookAt(Vector3 towards, float duration, AxisConstraint axisConstraint = AxisConstraint.None, Vector3 up = Vector3.up)

Scale

  • DOScale(float/Vector3 to, float duration)
  • DOScaleX/DOScaleY/DOScaleZ(float to, float duration)
  • DOPunchPosition(Vector3 punch, float duration, int vibrato, float elasticity, bool snapping)
  • DOPunchRotation(Vector3 punch, float duration, int vibrato, float elasticity)
  • DOPunchScale(Vector3 punch, float duration, int vibrato, float elasticity)

Shake

  • DOShakePosition(float duration, float/Vector3 strength, int vibrato, float randomness, bool snapping, bool fadeOut)
  • DOShakeRotation(float duration, float/Vector3 strength, int vibrato, float randomness, bool fadeOut)
  • DOShakeScale(float duration, float/Vector3 strength, int vibrato, float randomness, bool fadeOut)

Path

  • DOPath(Vector3[] waypoints, float duration, PathType pathType = Linear, PathMode pathMode = Full3D, int resolution = 10, Color gizmoColor = null)
  • DOLocalPath(Vector3[] waypoints, float duration, PathType pathType = Linear, PathMode pathMode = Full3D, int resolution = 10, Color gizmoColor = null)

Blendable tweens

  • DOBlendableMoveBy(Vector3 by, float duration, bool snapping)
  • DOBlendableLocalMoveBy(Vector3 by, float duration, bool snapping)
  • DOBlendableRotateBy(Vector3 by, float duration, RotateMode mode)
  • DOBlendableLocalRotateBy(Vector3 by, float duration, RotateMode mode)
  • DOBlendableScaleBy(Vector3 by, float duration)
  • DOSpiral(float duration, Vector3 axis = null, SpiralMode mode = SpiralMode.Expand, float speed = 1, float frequency = 10, float depth = 0, bool snapping = false)
  • DOTimeScale(float toTimeScale, float duration)

Unity UI 4.6 shortcut keys

CanvasGroup (Unity UI 4.6)

  • DOFade(float to, float duration)

Graphic (Unity UI 4.6)

  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)

Blendable tweens

  • DOBlendableColor(Color to, float duration)

Image (Unity UI 4.6)

  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)
  • DOFillAmount(float to, float duration)
  • DOGradientColor(Gradient to, float duration)

Blendable tweens

  • DOBlendableColor(Color to, float duration)

LayoutElement (Unity UI 4.6)

  • DOFlexibleSize(Vector2 to, float duration, bool snapping)
  • DOMinSize(Vector2 to, float duration, bool snapping)
  • DOPreferredSize(Vector2 to, float duration, bool snapping)

The Outline (Unity UI 4.6)

  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)

RectTransform (Unity UI 4.6)

  • DOAnchorMax(Vector2 to, float duration, bool snapping)
  • DOAnchorMin(Vector2 to, float duration, bool snapping)
  • DOAnchorPos(Vector2 to, float duration, bool snapping)
  • DOAnchorPosX/DOAnchorPosY(float to, float duration, bool snapping)
  • DOAnchorPos3D(Vector3 to, float duration, bool snapping)
  • DOAnchorPos3DX/DOAnchorPos3DY/DOAnchorPos3DZ(float to, float duration, bool snapping)
  • DOJumpAnchorPos(Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping)
  • DOPivot(Vector2 to, float duration)
  • DOPivotX/DOPivotY(float to, float duration)
  • DOPunchAnchorPos(Vector2 punch, float duration, int vibrato, float elasticity, bool snapping)
  • DOShakeAnchorPos(float duration, float/Vector3 strength, int vibrato, float randomness, bool snapping, bool fadeOut)
  • DOSizeDelta(Vector2 to, float duration, bool snapping)

ScrollRect (Unity UI 4.6)

  • DONormalizedPos(Vector2 to, float duration, bool snapping)
  • DOHorizontalNormalizedPos(float to, float duration, bool snapping)
  • DOVerticalPos(float to, float duration, bool snapping)

The Slider (Unity UI 4.6)

  • DOValue(float to, float duration, bool snapping = false)

The Text (Unity UI 4.6)

  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)
  • DOText(string to, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)

Blendable tweens

  • DOBlendableColor(Color to, float duration)

PRO ONLY ➨ 2D Toolkit shortcut key

  • DOScale(Vector3 to, float duration)
  • DOScaleX/Y/Z(float to, float duration)
  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)

2dSlicedSprite

  • DOScale(Vector2 to, float duration)
  • DOScaleX/Y(float to, float duration)

2dTextMesh

  • DOColor(Color to, float duration)
  • DOFade(float to, float duration)
  • DOText(string to, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)

PRO ONLY ➨ TextMesh PRO shortcut key TextMeshPro + TextMeshProUGUI

  • DOScale(float to, float duration)
  • DOColor(Color to, float duration)
  • DOFaceColor(Color to, float duration)
  • DOFaceFade(float to, float duration)
  • DOFade(float to, float duration)
  • DOFontSize(float to, float duration)
  • DOGlowColor(Color to, float duration)
  • DOMaxVisibleCharacters(int to, float duration)
  • DOOutlineColor(Color to, float duration)
  • DOText(string to, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)

C. Other general methods

These are additional generic methods that allow switching between values in specific ways.

  • static DOTween.Punch(getter, setter, Vector3 direction, float duration, int vibrato, float elasticity)
  • Point in a given direction, and then go back to the starting direction, as if it’s connected to the starting position by elasticity.
  • static DOTween.Shake(getter, setter, float duration, float/Vector3 strength, int vibrato, float randomness, bool ignoreZAxis)
  • Shake the Vector3 along its X and Y axes with a given value.
  • static DOTween.ToAlpha(getter, setter, float to, float duration)
  • Alpha for Color from its current value to the given value.
  • static DOTween.ToArray(getter, setter, float to, float duration)
  • Converts vector 3 to the given end value. Ease of use applies between paragraphs, not as a whole.
  • static DOTween.ToAxis(getter, setter, float to, float duration, AxisConstraint axis)

Virtual Tween a single axis Vector3 from its current value to a given value.

  • static DOTween.To(setter, float startValue, float endValue, float duration)

Changes a virtual property from a given start value to a given end value, and implements a setter that allows the value to be used using an external method or lambda.

Sequence frame animation

1. Create a sequence

// Returns a usable sequence that you can store and add a gradient to.
Sequence mySequence = DOTween.Sequence();
Copy the code

2. Add animations, intervals and callbacks to your sequence

Note that all of these methods need to be applied before the sequence begins. This means that the sequence must be set before the program starts and cannot be added dynamically. Also note that any nested tweener/ sequence needs to be fully created before it is added to the sequence. Because it’s locked up after that. Latency and looping (when not infinite) work even in nested Tweens.

API:

  • Append(Tween tween)
Add the given tween to the end of the sequence
mySequence.Append(transform.DOMoveX(45.1));
Copy the code
  • AppendCallback(TweenCallback callback)
// Add the given callback function to the end of the sequence.
mySequence.AppendCallback(MyCallback);
Copy the code
  • AppendInterval(float interval)
// Adds the given interval to the end of the sequence.
mySequence.AppendInterval(interval);
Copy the code
  • Insert(float atPosition, Tween tween)
// Inserts a given Tween at a given time position, allowing you to overlap the Tween instead of playing them one after the other.
mySequence.Insert(1, transform.DOMoveX(45.1));
Copy the code
  • InsertCallback(float atPosition, TweenCallback callback)
// Insert the given callback function at the given time and place.
mySequence.InsertCallback(1, MyCallback);
Copy the code
  • Join(Tween tween)
// Insert the given tween at the same time as the last tween added to the sequence or the callback.
// The rotation animation will play with the move animationmySequence.Append(transform.DOMoveX(45.1)); mySequence.Join(transform.DORotate(new Vector3(0.180.0), 1));
Copy the code
  • Prepend(Tween tween)
// Add the given tween to the beginning of the sequence and advance the rest in time
mySequence.Prepend(transform.DOMoveX(45.1));
Copy the code
  • PrependCallback(TweenCallback callback)
// Add the given callback function to the beginning of the sequence.
mySequence.PrependCallback(MyCallback);
Copy the code
  • PrependInterval(float interval)
// Add the given interval to the beginning of the sequence and advance the rest in time.
mySequence.PrependInterval(interval);
Copy the code

Tip: You can create sequences consisting only of callbacks and use them as timers or something similar.

Instance creation sequence

// Get a free sequence availableSequence mySequence = DOTween.Sequence();// Add a moving tween at the beginningmySequence.Append(transform.DOMoveX(45.1));// Add a rotating tween immediately after the previous tween completesmySequence.Append(transform.DORotate(new Vector3(0.180.0), 1));// Delay the entire sequence by 1 secondmySequence.PrependInterval(1);// Insert a scaling tween throughout the sequencemySequence.Insert(0, transform.DOScale(new Vector3(3.3.3), mySequence.Duration()));
Copy the code

Same as in the previous example, but with links (plus sign newlines to make things clearer) :

Sequence mySequence = DOTween.Sequence(); mySequence.Append(transform.DOMoveX(45.1))  .Append(transform.DORotate(new Vector3(0.180.0), 1))  .PrependInterval(1)  .Insert(0, transform.DOScale(new Vector3(3.3.3), mySequence.Duration()));
Copy the code

Settings, options, and callbacks

DOTween uses a chaining approach when it comes to applying Settings to DOTween. Or you can change the global default options that will apply to all newly created Tween.

1. Global Settings

General Settings

  • static LogBehaviour DOTween.logBehaviour

Depending on the mode selected, DOTween will record either errors, errors and warnings only, or all content and additional information. LogBehaviour.ErrorsOnly: Logs errors and nothing else. LogBehaviour.Default: Logs errors and warnings. LogBehaviour.Verbose: Logs errors, warnings and additional information.

  • static bool DOTween.maxSmoothUnscaledTime
  • static bool DOTween.nestedTweenFailureBehaviour
  • static bool DOTween.onWillLog<LogType,object>
  • static bool DOTween.showUnityEditorReport
  • static float DOTween.timeScale
  • static bool DOTween.useSafeMode
  • static bool DOTween.useSmoothDeltaTime
  • static DOTween.SetTweensCapacity(int maxTweeners, int maxSequences)

The Settings apply to all newly created Tweens

  • static bool DOTween.defaultAutoKill
  • static AutoPlay DOTween.defaultAutoPlay
  • static float DOTween.defaultEaseOvershootOrAmplitude
  • static float DOTween.defaultEasePeriod
  • static Ease DOTween.defaultEaseType
  • static LoopType DOTween.defaultLoopType
  • static bool DOTween.defaultRecyclable
  • static bool DOTween.defaultTimeScaleIndependent
  • static UpdateType DOTween.defaultUpdateType

Tweener and sequence Settings

Instance property float timeScale; Tip: This value can be used to set the smoothing effect from one animation to another:

myTween.timeScale = 0.5 f;
Copy the code

These Settings can be set for all types of animations and can be set at run time

  • SetAs(Tween tween \ TweenParams tweenParams)

Function: Copy the animation parameters that have been set to another animation

  • SetAutoKill(bool autoKillOnCompletion = true)

What it does: When autoKillOnCompletion is true, the animation will be destroyed immediately upon completion. Note: By default, Tweens terminates upon completion, so this method only works if the setting does not terminate automatically

  • SetEase(Ease easeType \ AnimationCurve animCurve \ EaseFunction customEase)

What it does: Sets the easeType category of the gradient. Note: Ease. Flash/InFlash/OntFlas/InOutFlash, will apply to attribute the flashing effect examples: Iamge.DoColor(Color Color,float time). Seangle (Ease easeType,int Overshoot,int Period) Overshoot: Indicates the total number of flashes to apply. Even numbers will end at the starting value, and odd numbers will end at the ending value. Period: indicates the power during the relaxation period and must be between -1 and 1. 0 is balanced, 1 completely weakens the comfort of time, -1 begins with ease completely weakens, and gives it power until the end

  • SetId(object id)

What it does: Sets the ID of the animation (you can then use the static method of DOTween as a filter). It can be an int, a string, an object or something. Note: Using int or stringID makes filtering faster (where int is also faster than string). Example: the transform DOMoveX (4, 1). SetId (” supertween “);

  • SetLink(GameObject target, LinkBehaviour linkBehaviour = LinkBehaviour.KillOnDestroy)

What it does: Links this to this GameObject and assigns behavior based on its activity state. This also causes the animation to be automatically destroyed when the GameObject is destroyed. Note: Animation is invalid if added to the sequence. Example: the transform DOMoveX (4, 1). SetLink (aGameObject, LinkBehaviour. PauseOnDisableRestartOnEnable);

  • SetLoops(int loops, LoopType loopType = LoopType.Restart)

What it does: Sets the animation loop options. There are three options: Restart, Yoyo, Incremental. Note: If the animation has already started, it has no effect. Also, if the animation is in a sequence, the infinite loop is not applied. Setting Loops to -1 causes the twain loop to be infinite. Looptype. Restart: When the loop ends, it will be restarted from the beginning. Looptype. Yoyo: When a loop ends, it plays backwards until it completes another loop, then forwards, then backwards, and so on. Looptype.incremental: At the end of each loop, the difference between its endValue and startValue is added to the endValue, creating Tweens that increments its value with each loop. This loop type is only applicable to Tweeners.

  • SetRecyclable(bool recyclable)

Function: Sets whether it can be recycled. If set to true, it can be recycled after being destroyed, otherwise it will be destroyed

  • SetRelative(bool isRelative = true)

Effect: Set the relative value of endValue, instead of using endValue directly, it will calculate statValue+endValue

  • SetUpdate(UpdateType updateType, bool isIndependentUpdate = false)

Updatetype. Normal: Updates each frame during the update call. Updatetype. Late: Updates each frame during LateUpdate calls. Updatetype.fixed: Update using the FixedUpdate call. Updatetype. Manual: Manually notifies dotween. ManualUpdate of updates.

Chain callback

  • OnComplete(TweenCallback callback)

Transform.domovex (4, 1).onComplete (MyCallback);

  • OnKill(TweenCallback callback)

// Set a callback that will fire transform.domovex (4, 1).onkill (MyCallback);

  • OnPlay(TweenCallback callback)

DOMoveX(4, 1).onPlay (MyCallback);

  • OnPause(TweenCallback callback)

DOMoveX(4, 1).onPause (MyCallback); // Set a callback that will trigger transform.domovex (4, 1).onPause (MyCallback);

  • OnRewind(TweenCallback callback)

// Set a callback that will trigger transform.domovex (4, 1).onrewind (MyCallback);

  • OnStart(TweenCallback callback)

// Set a callback that will trigger transform.domovex (4, 1).onStart (MyCallback) when the animation starts;

  • OnStepComplete(TweenCallback callback)

Transform.domovex (4, 1).onStepComplete (MyCallback); // Set a callback that will fire each time the animation completes a loop.

  • OnUpdate(TweenCallback callback)

Transform.domovex (4, 1).onUpdate (MyCallback); // Set a callback to fire every time the animation is updated.

  • OnWaypointChange(TweenCallback callback)

// Sets a callback that will be fired if the path between the current path changes. This is a special callback that, in contrast to other callbacks, takes a parameter of a type. Int (this will be the newly changed waypoint index). void Start() { transform.DOPath(waypoints, 1).OnWaypointChange(MyCallback); } void MyCallback(int waypointIndex) { Debug.Log(“Waypoint index changed to ” + waypointIndex); }

Note: If you want to use nested callbacks, they are still valid, but in the right order.

If you want to use a callback with arguments, you can use a Lambdas expression:

// The callback function takes no argumentstransform.DOMoveX(4.1).OnComplete(MyCallback);// The callback function takes argumentstransform.DOMoveX(4.1).OnComplete(()=>MyCallback(someParam, someOtherParam));
Copy the code

Get data from Tweens

10.1 Static Methods

  • static List PausedTweens()

Returns a list of all active animations that are in the paused state, or NULL if there are no active paused animations. Caution: Calling this method will create a garbage allocation because each call will generate a new list.

  • static List PlayingTweens()

Returns a list of all active animations that are playing, or NULL if there is no active play message. Note: Calling this method creates a garbage allocation because each call generates a new list.

  • static List TweensById(object id, bool playingOnly = false)

Returns a list of all active Tweens with the given ID, or NULL if there is no active Tweens with the given ID. Caution: Calling this method will create a garbage allocation because each call will generate a new list. PlayingOnly: Returns only the Tweens of the given ID currently playing if true, otherwise all.

  • static List TweensByTarget(object target, bool playingOnly = false)

Returns a list of all active Tweens with the given target, or NULL if the given target has no active Tweens. Note: The Tweens target is automatically set when you use the shortcut, rather than the usual way. Note: The DOTween animation visual editor specifies its game object as the target (not the actual target for transformations, materials, or other shortcuts), so use it if you want to get a visually created Tweens. Caution: Calling this method will create a garbage allocation because each call will generate a new list. PlayingOnly: Returns only the Tweens of the given ID currently playing if true, otherwise all.

  • static bool IsTweening(object idOrTarget, bool alsoCheckIfPlaying = false)

Returns true if the animation with the given ID or target is active. You can also use it to see if shortcuts exist on the target. AlsoCheckIfPlaying: Return true if false(default), as long as the animation of the given target /ID is active, otherwise it is also required to be playing.

  • static int TotalPlayingTweens()

Returns the total number of animations active and played.

10.2 Instance Methods

  • float fullPosition

Gets and sets the time position of the gradient (including loop, but not delay).

  • int CompletedLoops()

Returns the total number of loops Tweens has completed

  • float Delay()

Returns the final delay time of Tweens

  • float Duration(bool includeLoops = true)

Returns the duration of Tweens (excluding delays, or true includeLoops if loops are included). With includeLoops true, return the full duration cycle time, otherwise return the duration of a single cycle

  • float Elapsed(bool includeLoops = true)

Returns the current running time of Tweens (excluding latency, set includeLoops to true if loops are included)

  • float ElapsedDirectionalPercentage()

Returns the running percentage (0 to 1) of the tween (except for delays) based on a single loop, and calculates the final inverted Yoyo loop as 1 to 0 instead of 0 to 1.

  • float ElapsedPercentage(bool includeLoops = true)

Returns the percentage of runs between this (0 to 1)(excluding latency, or true includeLoops if loops are included).

  • bool IsActive()

Returns whether Tweens is started

  • bool IsBackwards()

Returns whether Tweens is rewinding

  • bool IsComplete()

Return whether Tweens is done, true is done, and flase if Tweens is destroyed

  • bool IsInitialized()

Return true if Tweens has been initialized

  • bool IsPlaying()

Return true if Tweens is playing

  • int Loops()

Returns the total number of loops assigned to Tweens

10.3 Instance method — Path tweens

  • Vector3 PathGetPoint(float pathPercentage)

Return a point on the path based on a given path percentage the path is initialized after Tweens starts, or immediately if Tweens is created using the path editor (DOTweenPro feature). You can initialize path pathPercentage: Percentage of paths to the point (0 to 1) by calling Init. Example: Vector3 myPathMidPoint = MyTween. PathGetPoint(0.5f);

  • Vector3[] PathGetDrawPoints(int subdivisionsXSegment = 10)

Return the group of points that can be used to draw the path (return NULL if this is not a path between paths, if Tweens is invalid, or if the path has not been initialized). Note: This method generates an allocation because it creates a new array. Example: Vector3 [] myPathDrawPoints = myTween. PathGetDrawPoints ();

  • float PathLength()

Return the length of the path (-1 if this is not a path between paths, or if the path is invalid, or the path has not been initialized). Example: float myPathLength = mytween.pathLength ();

Xi. Collaborative method

Tweens provides a useful set of coroutine that you can set in the coroutine so that you can wait for something to happen. These methods all have an optional bool argument that sets whether returns are allowed:

  • WaitForCompletion

IEnumerator SomeCoroutine() {Tween myTween = transform.domovex (45, 1); yield return myTween.WaitForCompletion(); Debug.Log(“Tween completed!” ); }

  • WaitForElapseLoops

Create a cooperative instruction, IEnumerator SomeCoroutine() {Tween myTween = transform.domovex (45, 1).setloops (4); yield return myTween.WaitForElapsedLoops(2); Debug.Log(“Tween has looped twice!” ); }

  • WaitForKill

IEnumerator SomeCoroutine() {Tween myTween = transform.domovex (45, 1); yield return myTween.WaitForKill(); Debug.Log(“Tween killed!” ); }

  • WaitForPosition

IEnumerator SomeCoroutine() {Tween myTween = transform.domovex (45, 1); Yield return myTween. WaitForPosition (0.3 f); // This log will happen after the tween has played for 0.3 seconds debug.log (“Tween has played for 0.3 seconds!”) ); }

  • WaitForRewind

Create a cooperative instruction, IEnumerator SomeCoroutine() {Tween myTween = transform.domovex (45, 1).SetAutoKill(false).OnComplete(myTween.Rewind); yield return myTween.WaitForRewind(); Debug.Log(“Tween rewinded!” ); }

  • WaitForStart

IEnumerator SomeCoroutine() {Tween myTween = transform.domovex (45, 1); yield return myTween.WaitForStart(); Debug.Log(“Tween started!” ); }

Xii. Summary

Tweens API: How to set global parameters, how to use Tweens, how to create sequences, how to set callbacks, and so on. All right, that’s it