[Unity 3d] Plug-in----DoTween animation method calling and execution

[Unity 3d] Plug-in----DoTween animation method calling and execution

Insert image description here

1. Movement and rotation (methods 1 to 4 mainly applied to Transform)
1. To use DoTween, you must first reference the namespace Using DG.Tweening;
2. transform.DOMove (target position, time spent/s) //Move method
3. transform.DoLocalMoveX (target position, time spent) //Single movement method
4. transform.DoLocalMove()//Move your own local coordinates
5. transform.DoRotate (target position, time) //Rotation
6. transform.DoLocalRotate() // Rotate local angle
7. transform.DORotateQuaternion (target position, time) // Quaternion rotation
8. transform.DOLookAt (looking target position, time); // Animation of looking at the target
2. Parameter explanation of the scaling of the object and the Punch (spring effect) function
1. transform.DOScale(Vector3.one * 2, 2); //Target position, time
2. transform.DOPunchPosition(new Vector3(0, 1, 0 ), 2, 2, 0.1f);//Similar spring effect//Parameters: (1), Punch: direction of movement and magnitude of force, (2), duration, (3), number of vibrations (frequency ) // (4) When it is 0, it only travels back and forth to the target point. If it is greater than 0, the round trip is larger than the starting point!
3. transform.DOPunchRotation(); //Parameter effects are the same as above
4. transform.DOPunchScale();//The parameter effect is the same as above
. 3. Shake effect of the object Shake
1. transform.DOShakePosition();//The first parameter is its duration, the second parameter is the intensity of the vibration, and the third parameter is the duration of the shake. The number of vibrations, the direction of the fourth vibration
2. transform.DOShakeRotation(); // Parameter effects are the same as above
3. transform.DOShakeScale(); // Parameter effects are the same as above
4. Blend mixing animation
method with Blend name, allowing mixing Animation
Originally, if two Move methods are executed at the same time, only the latest animation command will be executed (because the two moves will conflict, the latest command will be 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 simultaneous executions
. For example:
transform.DOBlendableMoveBy(new Vector3(1, 1, 1), 1);
transform.DOBlendableMoveBy(new Vector3(-1, 0, 0), 1);
Assuming the starting point is (0,0,0), the coordinates when the final animation stops are (0,1, 1), which is equivalent to moving to the added point of two positions.
2) It is an incremental animation transform.DOBlendableMoveBy(new Vector3(1, 1, 1), 1); Assuming that the real point is (1,1,1), the coordinates when the animation stops at the end are (2,2,2) Its parameter is not the target point, but the amount to be moved (the main explanation is that the first parameter is different from DOMove, DoMove is the target point, and this is the increment) The following three
functions are the same transform.DOBlendableRotateBy() transform.DOBlendableScaleBy( ) transform.DOBlendablePunchRotation()
5. Material (material animation) color methods
1), get the material ball
Material material = GetComponent().material;
2), change the color of the material
material.DOColor(Color.black, 2) ;//Parameters: 1. Target color, gradient time
! What is called is the _Color attribute on the Shder of the object itself. If there is no such property, the call will fail. If we want to call this to make it change color, we need to pass in the name of the Color on the Shder, such as material.DOColor(Color.black," "Fill in the name of the shder color variable in this", 2);
3) Modify the alpha value and transparency to change
material.DOFade(0, 2);
4) Color gradient
Gradient is the gradient editor of unity. We can apply for a Gradient variable and set it OK, call
material.DOGradientColor(Gradient, “_Color”, 3); directly in the method below.
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 attribute
material.DOVector(new Vector4(0, 0, 0, 1) , “_Color”, 3);
7) Color mixing
is the same as position mixing animation. It can be executed at the same time without interference, producing colors mixed together.
material.DOBlendableColor(Color.red, “_Color”, 3);
material.DOBlendableColor (Color.greew “_Color”, 3);
6. Camera methods Camera
1) Adjust the aspect ratio of the screen viewing angle. The first parameter is the ratio of width to height (width/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 camera's near plane
camera.DONearClipPlane(200, 2);
4) Change the value of the camera's far plane
camera.DOFarClipPlane( 2000, 2);
5) Change the value of the camera's FOV, such as the magnification effect
camera.DOFieldOfView(30, 2);
6) Change the camera's orthogonal size
camera.DOOrthoSize(10, 2);
7) Display range calculated according to screen pixels (method to change resolution size)
camera.DOPixelRect(new Rect(0f, 0f, 600f, 500f), 2);
8) Display range calculated according to screen percentage (change resolution through percentage method of rate size)
camera.DORect(new Rect(0.5f, 0.5f, 0.5f, 0.5f), 2);
7 and 8 can achieve multi-camera split screen effect
9) Camera shake
Camera shake effect parameters: duration, Strength, number of vibrations, randomness, fade out.
Power: Actually it is the amplitude of vibration, which can be understood as the amount of force exerted by the camera. Using Vector3, you can choose different strengths for each axis. Vibration
: number of vibrations
. Randomness: a random value that changes the direction of vibration. (Size: 0~180)
Fade out: whether the movement slowly moves back to the original position at the end
camera.DOShakePosition(1, 10, 10, 50, false);
7. Introduction to Text expansion method
text.DOColor(Color.black, 2) ; text.DOFade(0, 2); text.DOBlendableColor(Color.black, 2);
This method is more interesting because it inputs the content passed in the first parameter into the text box one by one according to time
. The first parameter is the word to be realistic, and the second parameter is time, which comes with the effect of fast first and then slow. text.DOText(“context”, 2); if it is
implemented at a constant speed:
text.DOText(“context”, 2);.SetEase(Ease.Linear);
8. Queue (DoTween’s own method implementation)
Sequence quence = DOTween.Sequence();
1) Add animation to the queue (use this method to To realize that when an animation is finished playing and you need to follow the next animation, just write this method in sequence)
quence.Append(transform.DOMove(Vector3.one, 2));
2) Add a time interval (when you need to implement an animation to play) After completion, you need to pause for a few seconds and then call the following method when executing other methods)
quence.AppendInterval(1);
3) Insert animation according to time points (add animation within the time specified by yourself, if it overlaps with other animations, the animation will be overwritten) )
The first parameter is time. This method inserts the animation to the specified time point. Taking this sentence as an example, it adds the DORotate animation to this queue and executes it at 0 seconds, although it is not the first quence
added to the queue.
Insert(0, transform.DORotate(new Vector3(0, 90, 0), 1));
4) Join the current animation (play both animations at the same time)
Join will join and let the animation be executed together with the currently executing animation
In the following two lines of code, DOMove will execute
quence.Append(transform.DOScale(new Vector3(2, 2, 2), 2));
quence.Join(transform.DOMove(Vector3.zero, 2)); together with DOScale.
5) Pre-add animation
Pre-add will add animation directly in front of Append, that is, at the beginning
quence.Prepend(transform.DOScale(Vector3.one * 0.5f, 1));
Here we need to talk about the execution of pre-add. Sequence issue
It also takes the nature of a queue here, but pre-add is a reverse queue compared to the original queue.
For example:
Sequence quence = DOTween.Sequence();
quence.Append(transform.DOMove(Vector3.one, 2));
quence.Prepend(transform.DOMove(-Vector3.one*2, 2));
quence.PrependInterval(1);
The execution order is PrependInterval----Prepend-----Append
is the last one added At the top of the queue
6) Pre-add the time interval
quence.PrependInterval(1);
9. Callback function
1) Pre-add the callback
quence.PrependCallback(PreCallBack);
2) Add the callback at the specified time point (the first parameter is the callback time, the second parameter is the callback method)
quence.InsertCallback(0, InsertCallBack);
3) Add callback
quence.AppendCallback(CallBack);
10. Tween setting
can be directly behind the animation. The parameters can also be assigned line by line as follows, and the parameters are finally passed in through SetAs.
TweenParams para = new TweenParams();
1) Set
the first animation loop The parameter is the number of loops - 1 represents an infinite loop.
The second parameter is the loop mode
Restart.
Yoyo moves from the starting point to the target point, and then back from the target point. In this way, the cycle
Incremental keeps moving in the direction of movement
para.SetLoops(-1, LoopType.Yoyo);
2) Set the parameter
transform.DOMove(Vector3.one, 2).SetAs(para);
3) Set the automatic killing animation (if the parameter is True, the animation will end directly after the animation ends)
transform.DOMove( Vector3.one, 1).SetAutoKill(true);
4)from tweening
For example; is to return from the target point to the starting point
transform.DOMove(Vector3.one, 2).From(true);
From parameter isRelative (relative) :
is true, the passed in is the offset, that is, the current coordinate + the passed in value = the target value; if it is
false, the passed in is the target value, that is, the passed in value = the target value
5) Set animation delay
transform.DOMove(Vector3.one, 2).SetDelay(1);

  6)设置动画运动以速度为基准
     例如:
     transform.DOMove(Vector3.one, 1).SetSpeedBased();
      使用SetSpeedBased时,移动方式就变成以速度为基准
      原本表示持续时间的第二个参数,就变成表示速度的参数,每秒移动的单位数

  7)设置动画ID (下面这个动画的 就以"Id”表示了)
    transform.DOMove(Vector3.one, 2).SetId("Id");
    我们直接可以在其他部位这么调用它 DoTween.Play("Id");

  8)设置是否可回收
    为true的话,动画播放完会被回收,缓存下来,不然播完就直接销毁
    transform.DOMove(Vector3.one, 2).SetRecyclable(true);

  9)设置动画为增量运动
      例如:
       transform.DOMove(Vector3.one, 2).SetRelative(true);
        SetRelative参数 isRelative(相对的):
        为true,传入的就是偏移量,即当前坐标 + 传入值 = 目标值
        为falese,传入的就是目标值,即传入值 = 目标值

  10)设置动画的帧函数
   例如:
    transform.DOMove(Vector3.one, 2).SetUpdate(UpdateType.Normal, true);
     第一个参数 UpdateType :选择使用的帧函数
     UpdateType.Normal:更新每一帧中更新要求。 
     UpdateType.Late:在LateUpdate调用期间更新每一帧。 
     UpdateType.Fixed:使用FixedUpdate调用进行更新。 
     UpdateType.Manual:通过手动DOTween.ManualUpdate调用进行更新。
     第二个参数:为TRUE,则补间将忽略Unity的Time.timeScale

11. Setting of the Ease motion curve
1) Use the Ease enumeration as a parameter.
For example:
transform.DOMove(Vector3.one, 2).SetEase(Ease.Flash, 3, 0f);
The second parameter Amplitude (amplitude): actual It is the number of moves. When the starting point is moved to the target, it is counted as one move, and then moved back twice.
The range of the third parameter period value is - 1~1.
When the value > 0, it is the attenuation value of the activity range, and the activity range will change from large to large. When the small value (like a basketball falling to the ground)
= 0, it means that the movement is uniform between the starting coordinate and the target coordinate.
When the value is < 0, a force will be exerted towards the target coordinate, and the range of movement will increase little by little, and finally it will approach Target point
These two parameters are only useful for the four curves of Flash, InFlash, OutFlash, and InOutFlash. For other curves, only the Ease enumeration parameters are effective.

    2)使用AnimationCurve当作参数
      例如:
       transform.DOMove(Vector3.one * 2, 1).SetEase(curve);
      AnimationCurve 横轴是时间,不过不是具体的时间,而是时间比例
      AnimationCurve 纵轴是倍数
      假设纵轴的值为v,传入DOMove的第一个参数endValue是e,起始点坐标是s
      此物体最后动画结束时的实际坐标即为 v* (e -s)+ s

     3)以回调函数为参数
      例如:
       transform.DOMove(Vector3.one * 2, 1).SetEase(MyEaseFun);

       //返回值是运动距离的百分比 值应为0~1之间,最后的值需为1,不然停留的位置不会是目标位置
       private float MyEaseFun(float time, float duration, float overshootOrAmplitude, float period)
       {
           return time / duration;
       }

12. Callback function
1) Animation completion callback
transform.DOMove(Vector3.one, 2).OnComplete(() => { });

  2)动画被杀死时回调
    transform.DOMove(Vector3.one, 2).OnKill(() => { });

  3)动画播放时回调,暂停后重新播放也会调用
    transform.DOMove(Vector3.one, 3).OnPlay(() => { });

  4)动画暂停时回调
    transform.DOMove(Vector3.one, 2).OnPause(() => { });

  5)动画回退时回调
    以下情况会被调用
    使用DORestart重新播放时
    使用Rewind倒播动画完成时
    使用DOFlip翻转动画完成时
    使用DOPlayBackwards反向播放动画完成时
    transform.DOMove(Vector3.one, 2).OnRewind(() => { });

  6)只在第一次播放动画时调用,在play之前调用
    transform.DOMove(Vector3.one, 2).OnStart(() => { });

  7)完成单个循环周期时触发
    transform.DOMove(Vector3.one, 2).OnStepComplete(() => { });
  8)帧回调
    transform.DOMove(Vector3.one, 2).OnUpdate(() => { });

  9)在路径动画时,改变目标点时的回调,参数为当前目标点的下标
    transform.DOMove(Vector3.one, 2).OnWaypointChange((value) => { });

13. Animation control method
1) Play
transform.DOPlay();

  2)暂停
    transform.DOPause();

  3)重播
    transform.DORestart();

  4)倒播,此方法会直接退回起始点
    transform.DORewind();

  5)平滑倒播,此方法会按照之前的运动方式从当前位置退回起始点
    transform.DOSmoothRewind();

  6)杀死动画
    transform.DOKill();   
  7)翻转补间的方向
    transform.DOFlip();
  8)跳转时间点
    第一个参数跳转的时间点,第二个参数是跳转后是否播放动画
    transform.DOGoto(1.5f, true);

  9)反向播放动画
    反向播放动画,在动画播放到一半时执行,会退回起始点,在一开始执行看不到效果是因为,物体本身就在起始点
    transform.DOPlayBackwards();

  10)正向播放动画
    正向播放动画
    transform.DOPlayForward();

  11)TogglePause
    当暂停时,执行就继续播放,播放时,执行就暂停
    transform.DOTogglePause();

14. Methods to obtain data
1. Class method
1) Return all paused animations, if not, return null
DOTween.PausedTweens();
2) Return all real played animations, if not, return null
DOTween.PlayingTweens();
3) Get an array of 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 only collect the animation that is playing.
4) Return the given An array of objects.
For example:
DOTween.TweensByTarget(transform, true);
Returns an animation array that meets the conditions.
The first parameter is the object to play the animation.
For example: transform.DOMove(Vector3.one, 2); The first parameter is passed in transform.
material.DOColor(Color.White, 2); The first parameter is passed in the material object material. The
second parameter is whether to only collect the animation that is playing.
5) Collect whether the passed in object has animations active
. For example:
DOTween.IsTweening (transform);
The first parameter is the detected object.
The second parameter is whether to detect whether the animation is in the playing state
. When it is true, the given object returns true when it is in the playing state.
When it is false, it only detects whether the given object has animation (also counted in the pause state). If so, it returns true
6) The total number of animations being played. Animations currently in the delayed playback state are also counted.
DOTween.TotalPlayingTweens();
2. Instance method
_tweener = transform.DOMove(Vector3.one, 2)
1) Indicates the attribute of animation execution time, readable and writable
_tweener.fullPosition = 1;
2) Indicates the number of times the animation has been executed_tweener.CompletedLoops
()
3) Get animation The delay time of
_tweener.Delay();
4) Get the duration of the animation.
The parameter true means the calculation loop time, and the infinite loop is Infinity
_tweener.Duration(false)
5) The animation has played time.
The parameter true means the calculation loop time
_tweener.Elapsed()
6) Returns the percentage of animation progress.
The starting point is 0 and the target point is 1. When in yoyo loop mode, the value will change from 0 to 1 and then from 1 to 0.
_tweener.ElapsedDirectionalPercentage()
7) Returns the animation interval. The percentage used.
The value of a single loop is 0 to 1.
The parameter is whether to include a loop. When it is true, the return value is the used percentage of the total interval of the loop. 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 it is
initialized_tweener.IsInitialized ();
12) Whether it is playing
_tweener.IsPlaying();
13) Return the number of loops, infinite loop is Infinity
_tweener.Loops();

Resource acquisition: https://download.csdn.net/download/g947195395/87684350

Guess you like

Origin blog.csdn.net/g947195395/article/details/130126698