Unity Dotween plugin _ detailed explanation of common methods

1. Expansion method of commonly used components in Unity

(1) Transform extension method

1、Position

1) Change the world coordinates of
the movement method, the first parameter is the target point to move to, not the distance to move this vector
transform.DOMove(new Vector3(1, 1, 1), 2);
only controls the movement on the x-axis , the other two directions are the same
transform.DOMoveX(1, 2);

2) Change local coordinates
transform.DOLocalMove(new Vector3(1, 1, 1), 2);
transform.DOLocalMoveX(1, 2);

2、Rotation

1) World rotation
Rotate to a given value, change the Euler angle
transform.DORotate(new Vector3(0, 90, 0), 2);
rotate to a given value, change the quaternion
transform.DORotateQuaternion (new Quaternion(0.1f, 0.1f, 0.1f, 0.1f), 2);

2) Local rotation
Rotate to a given value, changing the Euler angle
transform.DOLocalRotate(new Vector3(0, 90, 0) , 2);
Rotate to a given value, changing the quaternion
transform.DOLocalRotateQuaternion(new Quaternion(0.1f, 0.1f, 0.1f, 0.1f), 2);

within a given time, let yourself smoothly The positive direction of the z-axis points to the target point
transform.DOLookAt(new Vector3(0, 0, 0), 2);

3、Scale

Same as above, here change the zoom of the object to the target value
transform.DOScale(new Vector3(2, 2, 2), 2);
the other two axes are the same
transform.DOScaleX(3, 2);

4、Punch

The first parameter punch: Indicates the direction and intensity
The second parameter duration: Indicates the animation duration
The third parameter vibrato: The number of vibrations
The fourth parameter elascity: This value is from 0 to 1.
When it is 0, it is at the starting point When the movement between the target point
is not 0, the value you assign will be multiplied by a parameter, which will be used as a point in the opposite direction of your movement direction, and the object will move between this point and the target point. transform.DOPunchPosition(new Vector3(0
, 1, 0), 2, 2, 0.1f);
transform.DOPunchRotation(new Vector3(0, 90, 0), 2, 2, 0.1f);
transform.DOPunchScale(new Vector3(2, 2, 2), 2 , 2, 0.1f);

Taking position as an example, the value of elascity is 0 to 1.
When the elascity is 0, the object will move between the starting point and the target point
. When the elascity is not 0, it will be automatically calculated and generate a reverse direction point, the larger the value is, the farther the direction point is from

5、Shake

Parameters: Duration, Power, Vibration, Randomness, Fade-out
Power: Actually, it is the magnitude of the vibration, which can be understood as the magnitude of the force exerted by the camera. Using Vector3, you can choose different strengths for each axis. Vibration
: The number of vibrations
. Randomness: Change the vibration The random value of the direction (size: 0~180)
fades out: whether the movement will slowly move back to the original position at the end
transform.DOShakePosition(1, 5, 10, 50, true);
transform.DOShakeRotation(3);
transform.DOShakeScale(3 );

6、Blend

The method with the Blend name allows blending animations.
Originally, two Move methods were executed at the same time, and only the latest animation command was executed.
For example:
transform.DOMove(Vector3.one, 2);
transform.DOMove(Vector3.one * 2, 2) ;
The result is that the object moves to the (2,2,2) coordinates.

The DOBlendableMoveBy method has two characteristics
1) Allows multiple executions at the same time
. For example:
transform.DOBlendableMoveBy(new Vector3(1, 1, 1), 1);
transform.DOBlendableMoveBy (new Vector3(-1, 0, 0), 1);
Assuming the actual point is (0,0,0), the coordinates when the final animation stops are (0,1,1)
2) It is an incremental animation
transform. DOBlendableMoveBy(new Vector3(1, 1, 1), 1);
Assume that the actual point is (1,1,1), and the coordinates when the final animation stops are (2,2,2).
Its parameter is not the target point, but The amount to move

The following three functions are the same
transform.DOBlendableRotateBy()
transform.DOBlendableScaleBy()
transform.DOBlendablePunchRotation()


(2) Camera extension method

1. Adjust the aspect ratio of the screen viewing angle The first parameter is the ratio of width to height
camera.DOAspect(0.6f, 2);

2. Change the color of the camera background parameter
camera.DOColor(Color.blue, 2);

3. Change The value of the near plane of the camera
camera.DONearClipPlane(200, 2);

4. Change the value of the far plane of the
camera camera.DOFarClipPlane(2000, 2);

5. Change the value of the FOV of the
camera camera.DOFieldOfView(30, 2);

6. Change Camera orthogonal size
camera.DOOrthoSize(10, 2);

7. Display range calculated by screen pixels
camera.DOPixelRect(new Rect(0f, 0f, 600f, 500f), 2);

8. Display range calculated by screen percentage
camera.DORect(new Rect(0.5f, 0.5f, 0.5f, 0.5f), 2);

9. Camera shake
Camera shake effect parameters: duration, power, vibration, randomness, fade-out
power: actually the magnitude of the vibration , can be understood as the size of the force exerted by the camera. Using Vector3, you can choose different strengths for each axis
Vibration: The number of vibrations
Randomness: Change the random value of the vibration direction (size: 0~180)
Fade-out: Whether the movement will move back slowly at the end to original position
camera.DOShakePosition(1, 10, 10, 50, false);


(3) Material extension method

1. Change the color
material.DOColor(Color.black, 2);

2. According to the attribute name of the shader, modify the color
material.DOColor(Color.clear, "_Color", 2);

3. Modify the alpha value
material.DOFade(0 , 2);

4. The color gradient
Gradient is the gradient editor of unity (the picture of the gradient editor is shown below)
material.DOGradientColor(Gradient, "_Color", 3);

5. Change the value of material offset
material.DOOffset(new Vector2 (1, 1), 2);

6. Change the Vector4 value corresponding to the name of the provided shader property
material.DOVector(new Vector4(0, 0, 0, 1), "_Color", 3);

7) Color mixing
with The same is true for position blending animations, which can be executed at the same time without interference, resulting in mixed colors
material.DOBlendableColor(Color.red, "_Color", 3);
Gradient editor

(4) Text extension method

The first three are conventional methods, not much introduction
text.DOColor(Color.black, 2);
text.DOFade(0, 2);
text.DOBlendableColor(Color.black, 2);

This method is more interesting
because the first Enter the content of a parameter into the text box one by one according to the time
text.DOText("context", 2);


Two, Dotween common methods

(1) Sequence

Sequence queue = DOTween.Sequence();

1. Add animation to the queue
queue.Append(transform.DOMove(Vector3.one, 2));

2. Add time interval
queue.AppendInterval(1);

3. Insert by time point Animation
The first parameter is time, this method inserts the animation at the specified time point
Take this sentence as an example, it adds the DORotate animation to the queue and executes it at 0 seconds, although it is not the first queue added to the queue
. Insert(0, transform.DORotate(new Vector3(0, 90, 0), 1));

4. Join the current animation Join will join and let the animation execute the following two lines of code
together with the animation currently being executed , DOMove and DOScale Execute quence.Append(transform.DOScale(new Vector3(2, 2, 2), 2))
together ; quence.Join(transform.DOMove(Vector3.zero, 2)); 5. Pre-added animation will be added directly Animation to the front of Append, that is, at the very beginning, queue.Prepend(transform.DOScale(Vector3.one * 0.5f, 1)); Here we need to talk about the execution order of pre-addition. It also adopts the nature of the queue here. , however, pre-add is a reverse queue compared to the original queue . For example:









Sequence queue = DOTween.Sequence();
quence.Append(transform.DOMove(Vector3.one, 2));
quence.Prepend(transform.DOMove(-Vector3.one*2, 2));
quence.PrependInterval(1) ; The order of execution is PrependInterval ---- Prepend
-----Append is the last one added and it will
be at the top of the queue . PreCallBack); 2) Add callback queue.InsertCallback(0, InsertCallBack); 3) Add callback queue.AppendCallback(CallBack);














(2) Tweener settings

TweenParams para = new TweenParams();

1. Set the animation loop. 
The first parameter is the number of loops - 1 means infinite loop.
The second parameter is the loop mode 
Restart to restart 
Yoyo from the starting point to the target point, and then back from the target point, so that the loop 
Incremental is always moving towards the direction of motion. movement
para.SetLoops(-1, LoopType.Yoyo);

2. Set the parameter
transform.DOMove(Vector3.one, 2).SetAs(para);

3. Set the automatic kill animation
transform.DOMove(Vector3.one, 1).SetAutoKill(true);

4. From tween
For example;
transform.DOMove(Vector3.one, 2).From(true);
From parameter isRelative (relative):
if true, what is passed in is the offset, that is, current coordinates + passed in value = target
value false, passed in The target value is the target value, that is, the input value = target value

5. Set the animation delay 
transform.DOMove(Vector3.one, 2).SetDelay(1);

6. Set the animation movement based on the speed
For example:
transform.DOMove(Vector3 .one, 1).SetSpeedBased();
When using SetSpeedBased, the movement method becomes based on the speed.
The second parameter originally representing the duration becomes a parameter representing the speed, and the number of moving units per second

7. Setting Animation ID
transform.DOMove(Vector3.one, 2).SetId("Id");

8. If the setting is recyclable
is true, the animation will be recycled after playing and cached, otherwise it will be directly destroyed after playing
transform.DOMove(Vector3.one, 2).SetRecyclable(true);

9. Set the animation to incremental motion
For example:
transform.DOMove(Vector3.one, 2).SetRelative(true);
SetRelative parameter isRelative(relative):
if true, the input is the offset, that is, the current coordinate + the passed If input value = target value
is false, the input value is the target value, that is, input value = target value

10, frame function for setting animation
For example:
transform.DOMove(Vector3.one, 2).SetUpdate(UpdateType.Normal, true) ;
The first parameter UpdateType: Select the frame function to use
UpdateType.Normal: Update the update request in each frame. 
UpdateType.Late: Updates every frame during a LateUpdate call. 
UpdateType.Fixed: Use the FixedUpdate call for updates. 
UpdateType.Manual: Update via manual DOTween.ManualUpdate call.
The second parameter: TRUE, the tween will ignore Unity's Time.timeScale


(3) Setting of Ease motion curve

1. Take the Ease enumeration as a parameter.
For example:
transform.DOMove(Vector3.one, 2).SetEase(Ease.Flash, 3, 0f);
The second parameter Amplitude (amplitude): is actually the number of moves, and the starting point moves to The target moves once, then moves back and moves twice.
The range of the third parameter period value is - 1~1.
When the value > 0, it is the attenuation value of the active range. The active range will change from large to small.
When the value = 0, it is uniform When the value of the movement between the initial coordinates and the target coordinates is
< 0, a force will be applied to the target coordinates, and the active range will increase a little bit, and finally approach the target point.
These two parameters are only applicable to Flash, InFlash, OutFlash, InOutFlash These four curves are useful, other curves only work with Ease enumeration parameter

2, use AnimationCurve as a parameter
For example:
transform.DOMove(Vector3.one * 2, 1).SetEase(curve);
AnimationCurve horizontal axis is time , but not the specific time, but the time ratio
AnimationCurve vertical axis is a multiple
Assuming the value of the vertical axis is v, the first parameter endValue passed to DOMove is e, and the starting point coordinates are s The
actual coordinates at the end of the final animation of this object That is v* (e -s) + s

3. Take the callback function as a parameter
For example:
transform.DOMove(Vector3.one * 2, 1).SetEase(MyEaseFun);

//The return value is the percentage value of the movement distance, which should be between 0 and 1, and the final value must be 1, otherwise the stop position will not be the target position. private float MyEaseFun(float time, float
duration, float overshootOrAmplitude, float period)
{ return time / duration; }


 

(4) Callback function

1. Call back
transform.DOMove(Vector3.one, 2).OnComplete(() => { }); 2. Call back transform.DOMove(Vector3.one, 2).OnKill(() =

when the animation is killed
> { });

3. Call back when the animation is playing, and replay after pausing will also call
transform.DOMove(Vector3.one, 3).OnPlay(() => { });

4. Call back
transform.DOMove( when the animation is paused Vector3.one, 2).OnPause(() => { });

5. Callback when the animation rolls back.
The following situations will be called
when using DORestart to replay. When
using Rewind to reverse the animation. When
using DOFlip to flip the animation,
use DOPlayBackwards to reverse.
transform.DOMove(Vector3.one, 2).OnRewind(() => { });

6. It is only called when the animation is played for the first time, and transform.DOMove
(Vector3.one, 2).OnStart(() => { });

7. Trigger
transform.DOMove(Vector3.one, 2).OnStepComplete(() => { });
8. Frame callback
transform.DOMove(Vector3.one, 2).OnUpdate(() => { });

9. During the path animation, the callback when changing the target point, the parameter is the subscript of the current target point
transform.DOMove(Vector3.one , 2).OnWaypointChange((value) => { });


(5) Animation control method

1. Play
transform.DOPlay();

2. Pause
transform.DOPause();

3. Replay
transform.DORestart();

4. Rewind, this method will directly return to the starting point
transform.DORewind();

5. Smooth reverse , this method will return from the current position to the starting point
transform.DOSmoothRewind();

6. Kill the animation
transform.DOKill();

7. Flip the direction of the tween
transform.DOFlip();

8. Jump time Point
The first parameter is the time point of the jump, and the second parameter is whether to play the animation after the jump.
transform.DOGoto(1.5f, true);

9. Play the animation in reverse and
play the animation in reverse, and execute it when the animation is halfway through , it will return to the starting point, and the effect cannot be seen at the beginning because the object itself is at the starting point
transform.DOPlayBackwards();

10.
Play the animation forward
transform.DOPlayForward();

11. TogglePause
when paused When playing, the execution will continue to play, and when playing, the execution will pause
transform.DOTogglePause();
 

(6) Data acquisition method

1. Class method

1) Return all paused animations, if none, return null
DOTween.PausedTweens();

2) Return all real playing animations, if none, return null
DOTween.PlayingTweens();

3) Get an array with a given ID
For example:
DOTween.TweensById ("id", true);
returns an array of animations that meet the conditions
The first parameter is the ID of the animation
The second parameter is whether to collect only the animation that is playing

4) Return an array of given objects
For example:
DOTween.TweensByTarget(transform, true);
returns an array of animations that meet the conditions.
The first parameter is the object to play the animation.
For example: transform.DOMove(Vector3.one, 2); The first parameter is passed to transform
material.DOColor(Color.White, 2); The first parameter is to pass in the material object material, and
the second parameter is whether to collect only the animation that is playing

5) Collect whether the incoming object has animation active
For example:
DOTween.IsTweening(transform);
Object
The second parameter is whether to detect whether the animation is in the playback state
and return true when the given object is in the playback state
When it is false, it only detects whether the given object has animation (it is also counted in the pause state) and returns true if it is.

6) The total number of animations being played, and the animation currently in the delayed playback state is also counted as
DOTween.TotalPlayingTweens();
 

2. Instance method

_tweener = transform.DOMove(Vector3.one, 2)

1) The attribute indicating the execution time of the animation, readable and writable
_tweener.fullPosition = 1;

2) Indicates the number of times the animation has been executed
_tweener.CompletedLoops()

3) Obtaining the delay time of the animation
_tweener.Delay();

4) Obtaining the animation's time Duration
The parameter is true to indicate the calculation cycle time, and the infinite loop is Infinity
_tweener.Duration(false)

5) The animation has played time
The parameter is true to indicate the calculation cycle time
_tweener.Elapsed() 6) Return the percentage starting point

of the animation progress
It is 0 and the target point is 1. When in yoyo cycle mode, the value will change from 0 to 1 and then from 1 to 0
_tweener.ElapsedDirectionalPercentage()

7) Return the percentage used in the animation interval.
The value of a single cycle is 0 to 1.
The parameter is If it is true, the return value is the used percentage of the total interval of the cycle. If it is an infinite loop, the return value is 0
_tweener.ElapsedPercentage(true)

8) Whether the animation is active
_tweener.IsActive();

9) Whether it is a reverse animation
_tweener .IsBackwards();

10) Whether the animation is
completed_tweener.IsComplete();

11) Whether to initialize with
_tweener.IsInitialized();

12) Whether to play
_tweener.IsPlaying();

13) Return the number of loops, the infinite loop is Infinity
_tweener.Loops();
 

(7) Ctrip method

private IEnumerator Wait()
{ _tweener = transform.DOMove(Vector3.one, 2); } 1. Wait for the animation to complete yield return _tweener.WaitForCompletion(); 2. Wait for the specified number of cycles. After the number of loops, continue to execute If the number of times passed in is greater than the number of animation loops, continue to execute at the end of the animation yield return _tweener.WaitForElapsedLoops(2); 3. Wait for the animation to be killed yield return _tweener.WaitForKill(); 4. Wait The specified time for animation execution The parameter is time, after the time passed in for animation execution or after the animation execution is completed, continue to execute yield return _tweener.WaitForPosition(0.5f); 5. Wait for the animation to roll back The following situations will continue to execute the function when using DORestart to replay When the Rewind reverse animation is completed When the flip animation is completed using DOFlip When the animation is reversed using DOPlayBackwards when the animation is completed yield return _tweener.WaitForRewind(); 6. Continue to execute after waiting for Start to execute


























yield return _tweener.WaitForStart();

Guess you like

Origin blog.csdn.net/weixin_43705303/article/details/104918555