This article is only used to record and share the learning process, if there are mistakes please correct

preface

This paper reference since DOTween dotween.demigiant.com/documentati official document…

The preparatory work

  • Import DOTween into the project
  • Open the DOTween tool panel under Tools/Demigiant and set the Unity version information.

Click the Setup DOTween (green) button. You can change some global Settings in the Preferences panel on the right or disable them if not required

  • Import the DOTween namespace in the script
using DG.Tweening;
Copy the code
  • useInitFunction set partial global options (optional)
DOTween.Init(autoKillMode, useSafeMode, logBehaviour);
Copy the code

Common extension methods

Transform extension method:

The sample

transform.DOMove(Vector3.one, 1);
Copy the code


DOMove(Vector3 to, float duration, bool snapping)
Copy the code

If specified as true, the method will be snapped as integer points. This method also has a derivative of DOMoveX/DOMoveY/DOMoveZ, which moves only in the specified direction

DORotate(Vector3 to, float duration, RotateMode mode)
Copy the code

Rotate an object to a given value in a specified time to: target Angle (Euler Angle) duration: specify time mode: specify rotation mode This method also exists a derivative of DORotateQuaternion, which takes quaternion as argument

DOLookAt(Vector3 towards, float duration, AxisConstraint axisConstraint = AxisConstraint.None, Vector3 up = Vector3.up)
Copy the code

Rotate the object towards the destination for a duration of time axisConstraint defines the vector up

DOScale(float/Vector3 to, float duration)
Copy the code

Scales an object to a given value in the specified time

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)
Copy the code

Duration: elasticity: a value between 0 and 1. If it is 0, the shocks are only between the initial value and the set value

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)
Copy the code

Duration: vibration position/rotation/scaling with a given force, strength: Vector3 also represents the vibration intensity of each axis, vibrato randomness: A value between 0 and 180, representing the randomness of the vibration, 0 only vibrates on a single axis fadeOut: if set to true the vibration animation will fadeOut smoothly

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

Duration: duration: pathtype: pathtype, line/curve (automatic transition)/bezier curve (incoming in groups of three) pathMode: To determine the correct LookAt, there are 3D/side-scroller 2D/top-down 2D Resolution: Path resolution (used for curve paths), the higher the value, the smoother it is

Camera extension method

The sample

Camera.main.DOColor(Color.blue, 1);
Copy the code


DOColor(Color to, float duration)
Copy the code

Changes the camera background color to the given color for the specified time

DOOrthoSize(float to, float duration)
Copy the code

Changes the camera’s orthogonal size to a given value in the specified time

DOShakePosition(float duration, float/Vector3 strength, int vibrato, float randomness, bool fadeOut)
DOShakeRotation(float duration, float/Vector3 strength, int vibrato, float randomness, bool fadeOut)
Copy the code

Vibrate camera position/rotation for a specified time

Material extension method

The sample

GetComponent<MeshRenderer>().material.DOFade(0.1);
Copy the code


DOColor(Color to, float duration)
DOColor(Color to, string property, float duration)
DOColor(Color to, int propertyID, float duration)
Copy the code

Changing the material color to the given color within the specified time can be used to specify the target using the shader’s property name or ID

DOFade(float to, float duration)
DOFade(float to, string property, float duration)
DOFade(float to, int propertyID, float duration)
Copy the code

Changes the alpha value of a material to the given value for the specified time

DOBlendableColor(Color to, float duration)
DOBlendableColor(Color to, string property, float duration)
DOBlendableColor(Color to, int propertyID, float duration)
Copy the code

Blending methods, which allow color changes to be performed in conjunction with other blending methods

UI component extension method

The sample

GetComponent<Text>().DOText("<color=blue>Hello</color> <size=50>World</size>".1.true, ScrambleMode.Lowercase);
Copy the code


Image:

DOFillAmount(float to, float duration)
Copy the code

Changes the padding of the Image to the given value in the specified time

ScrollRect

DONormalizedPos(Vector2 to, float duration, bool snapping)
DOHorizontalNormalizedPos(float to, float duration, bool snapping)
DOVerticalPos(float to, float duration, bool snapping)
Copy the code

Move the display area to specify changing the X or Y axis area

Slider

DOValue(float to, float duration, bool snapping = false)
Copy the code

Changes the value of the slider within the specified time

Text

DOText(string to, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)
Copy the code

To: a given string duration: a given time richTextEnabled: Set to rich text scrambleMode: ScrambleChars: Custom replacement characters that will only be used for oversubstitution when Custom mode is used

The Set Set up

A Tween object followed by a Set is used to Set an example of properties for this object

transform.DOMove(Vector3.one, 1).SetEase(Ease.InOutElastic);
Copy the code


SetAs
SetAs(Tween tween \ TweenParams tweenParams)
Copy the code

Replace the parameters such as the Tween setting and callback with the Settings and callback for the given Tween

SetAutoKill
SetAutoKill(bool autoKillOnCompletion = true)
Copy the code

If set to false, the Tween will not be destroyed upon completion and can be reused

SetEase
SetEase(Ease easeType \ AnimationCurve animCurve \ EaseFunction customEase)
Copy the code

Set Tween’s gentle curve gentle function: controls the rate of parameter value change through time change. Parameters can be selected from existing curves (Ease) or customized AnimationCurve/callback function (EaseFuction)

Using the existing slow curve:

transform.DOMove(Vector3.one, 1).SetEase(Ease.InElastic);
Copy the code

Effect of slow curve:

Here is a source ofeasings.net/cn

Using AnimationCurve using custom curve:

public AnimationCurve curve;
void Start()
{
    transform.DOMove(Vector3.one, 1).SetEase(curve);
}
Copy the code



Use custom callback functions

EaseFunction fuction = (time, duration, overshootOrAmplitude, period) => time / duration;
transform.DOMove(Vector3.one, 1).SetEase(fuction);
Copy the code
SetId
SetId(object id)
Copy the code

Set Tween’s ID before using some static method (e.gDOTween.Pause()), you can use ID as a filter

SetLoops
SetLoops(int loops, LoopType loopType = LoopType.Restart)
Copy the code

Loops: Loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops: loops Loop options, which determine how the next animation in the loop will work at the end of one animation, with Yoyo /Restart /Incremental options

SetRecyclable
SetRecyclable(bool recyclable)
Copy the code

Set Tween to be recycled automatically. If set to true, the animation will be recycled when it is killed

SetRelative
SetRelative(bool isRelative = true)
Copy the code

Set to true to incremental animation

SetUpdate
SetUpdate(UpdateType updateType, bool isIndependentUpdate = false)
Copy the code

Set the Tween updateType Update function: Tween Update function, can in the Update/LateUpdate/FixUpdate/DOTween ManualUpdate updated in isIndependentUpdate: Set to true ignores Unity’s timescale

SetDelay
SetDelay(float delay)
Copy the code

Set delayed start

On the callback

Set an example of the behavior Tween will perform at some point by passing in a callback function

transform.DOMove(Vector3.one, 1).OnComplete(() => transform.DOScale(new Vector3(. 5f, . 5f, . 5f), 1));
Copy the code


// Trigger on completion, or after all loops have been executed
OnComplete(TweenCallback callback)
// Triggered when killed
OnKill(TweenCallback callback)
// Triggered when playing, or when playing after pausing
OnPlay(TweenCallback callback)
// When the animation is paused, or when the animation is finished if Tween's autokill is false
OnPause(TweenCallback callback)
// Triggered when a rollback occurs:
// ReStart the animation with ReStart
// When the painting is finished by ReWind
// When the Flip animation is done through Flip
// Work backwards through PlayBackwards animation
OnRewind(TweenCallback callback)
// Trigger at start, i.e. the first play
OnStart(TweenCallback callback)
// Each time the animation loop completes, it fires
OnStepComplete(TweenCallback callback)
// Each frame is triggered during execution
OnUpdate(TweenCallback callback)
// Triggered when the pathpoint changes during DoPath. The parameter is the subscript of the current pathpoint
OnWaypointChange(TweenCallback<int> callback)
Copy the code

Tween control

Control animation playback through functions

/ / sample
Tween tween = transform.DOMove(Vector3.one, 1).Pause();
tween.Play();
DOTween.PlayBackwardsAll();
Copy the code
// Flip the animation direction
FlipAll/Flip()
// Send the animation to the end position (no effect if it is an infinite loop)
CompleteAll/Complete(bool withCallbacks = false)
// Send the animation to the specified time position, andPlay if true will play immediately after the jump, otherwise pause
GotoAll/Goto(float to, bool andPlay = false)
// Kill the animation immediately. If complete is true, the animation will be completed immediately before Kill
// We can pass in Tween's ID as a filter
KillAll/Kill(bool complete = true.params object[] idsOrTargetsToExclude)
// Pause the animation
PauseAll/Pause()
// Play the animation
PlayAll/Play()
// Play back the animation
PlayBackwardsAll/PlayBackwards()
// Play the animation forward
PlayForwardAll/PlayForward()
If includeDelay is true, you can set the delay time for beginning playback changeDelayTo
RestartAll/Restart(bool includeDelay = true.float changeDelayTo = - 1)
// Backanimate to the starting point and pause
RewindAll/Rewind(bool includeDelay = true)
// Smooth backwards animation to the starting point and skips all loops (except increments)
SmoothRewindAll/SmoothRewind()
// Play animation if animation is paused, pause animation if animation is playing
TogglePauseAll/TogglePause()
Copy the code