DoTween

dotween最原始的用法
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class DotweenText : MonoBehaviour {
    public GameObject cube;
    public RectTransform rectTransform;
    Vector3 MyValue = new Vector3(10,0,0);
    float x = 0;
    // Use this for initialization
    void Start () {
        // DOTween.To(()=>MyValue,pos=>MyValue=pos,new Vector3(10,10,2),5);
        //对当前变量坐标pos的动画改变得插值,只是对x的一个改变,而MyValue表示的是一个返回值,x表示的事差值
        // DOTween.To(()=>x,num=>x=num,10,5);//最原始的Dotween用法可以操作各种值
        DOTween.To(()=> MyValue,vec=>MyValue=vec,new Vector3(0,0,0),5);
    }
    
    // Update is called once per frame
    void Update () {
        // print(x);
        // cube.transform.position = MyValue;//赋值给当前位置
       // rectTransform.position = MyValue;//世界坐标的0,0,0
        rectTransform.localPosition = MyValue;//局部坐标0,0,0

    }
}
***************************
using UnityEngine;
2
using System.Collections;
3
using DG.Tweening;//引入DoTween命名空间
4
public class GameStart : MonoBehaviour
5
{
67
    public Vector3 myValue = new Vector3(0, 0, 0);
8
    void Start()
9
    {
10
        //对变量做一个动画,通过插值的方式去修改一个值的变化
11
        DOTween.To(() => myValue, x => myValue = x, new Vector3(10, 0, 0), 2);//用两秒的时间从0,0,0变化到10,10,10
12
         //()=> myValue,表示返回值为myValue,x=>myValue=x,表示将系统计算好的x值(当前值到目标值的插值)赋给myValue,new Vector3(10,0,0),表示达到的目标值,2表示所需时间
13
    }
***************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class DoMoveText : MonoBehaviour {
    // RectTransform rt;
    // Use this for initialization
    bool b = false;
    void Start () {
        //  rt.DOMove(new Vector3(0,0,0),5);//移动到世界坐标原点
        // rt.DOLocalMove(Vector3.zero,5);//本地坐标原点
        // rt.DOLocalMoveX(0,5);
        Tweener t =  transform.DOLocalMove(Vector3.zero,5);//动画播放完默认自动销毁
        t.SetAutoKill(false);//动画不销毁
    }
    public void PlayTweener() {
        if (b)
        {
            transform.DOPlayForward();
        }
        else
        {
        transform.DOPlayBackwards();

        }
        b = !b;

    }
    
    // Update is called once per frame
    void Update () {
        
    }
}
*****************************
//  transform.DOLocalMove(Vector3.zero, 5).From();//从0,0,0的位置移动到当前位置,false为默认选项
       // transform.DOShakePosition(3,Vector3.up);


******************************
dotween字体显示:

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

public class Dotween002 : MonoBehaviour {
    public Text text;
    // Use this for initialization
    void Start () {
        text = text.GetComponent<Text>();
        text.DOText("欢迎来到王者荣耀,请选择你的英雄", 5);//使字一个一个的打出
        text.DOColor(Color.green, 7);//颜色渐变
    }

    
    // Update is called once per frame
    void Update () {
        
    }
}
莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
原文地址:https://www.cnblogs.com/huang--wei/p/9609395.html