unity-7 (DoTween)

Download DoTween

Find Windows in the Unity project and select Asset Store.
insert image description here
After that, you will jump to the Unity store, search for Dotween, choose a free Dotween plug-in (you can also choose a paid one, depending on your personal needs) and add it to my resources (login is required), after the download is complete, import it into Unity.
In Unity's Project, there will be two files, Plugin and Resource, and the import is successful.
insert image description here

Use of DoTween

Use code to realize the use of Dotween: first create a Cube object, and then add the script.
insert image description here
When writing code, pay attention to using DG.Tweening;the namespace to be added.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

Move



 //对物体进行移动,前一个参数是坐标,后一个是时间
  transform.DOMove(new Vector3(1,1,1),2);//世界坐标,将物体移动到1,1,1 用时2s
  transform.DOLocalMove(new Vector3(1, 1, 0), 2);//局部坐标
  transform.DOMoveX(1,2);//只对X轴移动
  transform.DOMoveY(2,2);//只对Y轴移动
  transform.DOMoveZ(2,2);//只对Z轴移动
//另一种移动方式
  transform.DOMove(Vector3.one,2);//将物体移动到1,1,1,Vector3.one*2是可以将移动距离*2

Rotate

transform.DORotate(new Vector3(0,90,0),2);//对物体进行旋转改变角度Vector3(0,90,0)是绕Y轴旋转90°
transform.DORotateQuaternion(new Quaternion(0.1f,0.1f,0.1f,0.1f),2);    //以四元数的方式进行旋转

Zoom (Scale)

      //对物体的大小进行缩放
        transform.DOScale(new Vector3(2, 2, 2), 2);//对物体进行缩放X,Y,Z同时在2s内放大二倍;
        transform.DOScaleX(2,2);//仅X轴缩放二倍
        transform.DOScaleY(2,2);//仅Y轴缩放二倍
        transform.DOScaleZ(2,2);//仅Z轴缩放二倍

Bouncing (Punch)


        //第一个参数是施加力的大小和方向
        //第二个参数是持续时间
        //第三个是震动频率
        //第四的值为0到1,如果为0,就是在起始点到目标点之间运动;不为0时,会把你赋的值乘上一个参数,作为你运动方向反方向的点,物体在这个点和目标点之间运动。注:可以看成弹簧
      transform.DOPunchPosition(new Vector3(0, 10, 0), 5, 5, 0.1F);//位移,在Y轴像弹簧一样弹动
      transform.DOPunchRotation(new Vector3(0,90,0),2,2,0.1f);//旋转,
      transform.DOPunchScale(new Vector3(3, 0, 0), 2, 2, 0.1f);//缩放,缩放的弹动

Shake

//第一个参数是持续时间
//第二个参数是施加力的大小和方向
//第三个是震动频率
//第四个是震动的随机性(可以不添加)
 transform.DOShakePosition(3,new Vector3(0,2,0),2);//在Y轴方向3s内震动2次距离为2
 transform.DOShakeScale(2,new Vector3(3,0,0),1,90);
 transform.DOShakeRotation(2,new Vector3(90,0,0),1);
 //震动与弹动相似但又有不同,弹动像弹簧一样弹,震动是来回震。

Increment (Blend)
can only run one of the above-mentioned similar functions at the same time. If you write more than one similar function, run the last one, because the latter function will overwrite the previous one.

 transform.DOScale(new Vector3(2, 2, 2), 2);
 transform.DOScale(new Vector3(0, 2, 2), 2);

These similar functions can only run transform.DOScale(new Vector3(0, 2, 2), 2) ,
but Blend can implement the addition of similar functions.

  transform.DOBlendableMoveBy(new Vector3 (0,2,0),2);//在原位置的基础上进行增加
  transform.DOBlendableMoveBy(new Vector3(2, 0, 0), 2);
  //Blend相当于向量的相加
  transform.DOBlendableScaleBy(new Vector3(0, 2, 0), 2);//缩放增加
  transform.DOBlendablePunchRotation(new Vector3(0, 90, 0), 2, 2, 0.1f);//弹动相加

Material (Material)
The DoTween plug-in can change the material of the object, so the material must be attached to the object first.

public Gradient gradient;
  Material material = GetComponent<MeshRenderer>().material;//得到材质组件
  material.DOColor(Color.red,2);//改变物体的颜色为红色时间2s
  material.DOColor(Color.clear,2);//改变材质透明度
  material.DOFade(1,2);//改变材质透明度的另一方式
  material.DOGradientColor(gradient,2);//材质颜色渐变,必须声明Gradient组件
  material.DOBlendableColor(Color.red, 2);
  material.DOBlendableColor(Color.blue, 2);//颜色混合

Camera (Camera)
Before writing the camera code, the script should be assigned to the camera, delete the script on the Cube, otherwise an error will be reported.

   Camera camera = GetComponent<Camera>();//得到相机组件
   camera.DOAspect(1,2);//改变相机的宽高比,(1,2)2s内宽高比变为1:1
   camera.DOColor(Color.green,2);//改变相机的背景颜色
   camera.DONearClipPlane(3,2);//改变相机的近切面
   camera.DOFarClipPlane(30,0.1f);//改变相机的远切面
   camera.DOFieldOfView(30,2);//相机视野,可用于游戏中的倍镜
   camera.DOOrthoSize(3,1);//用于相机正交视野的大小;正交视野:2D图形下相机的视野
   camera.DOPixelRect(new Rect(0,0,360,540),2);//相机的分辨率前两个数值是相机的位置,后两个数值是相机的分辨率;可以用于屏幕的分屏
   camera.DORect( new Rect(0.5f,0.5f,0.5f,0.5f),2);//百分比形式将相机缩小
   camera.DOShakePosition(1,10,10);//相机抖动三个参数是:时间,震动力量,震动次数
   

insert image description here
insert image description here
Screen split screen effect
insert image description here
text (Text)

    Text text = GetComponent<Text>();
    text.DOBlendableColor(Color.red,2);//混合颜色
    text.DOText("qqqqqqq", 2);//让文本中的内容一个一个显示,text.DOText("qqqqqqq",5).SetEase<Ease.Linear>;//让文本内容均速显示
    text.DOText("qqqqqqq", 2).SetEase(Ease.Linear);
    text.DOFade(0.5F,2);
    text.DOBlendableColor(Color.blue,2);

Guess you like

Origin blog.csdn.net/AD_GOD/article/details/123586715