DoTween常用动画效果

首先记得引入命名空间:using DG.Tweening;

1.渐隐渐现

    protected CanvasGroup canvasGroup;
    protected void Start()
    {
        if(canvasGroup == null)
        {
            canvasGroup = GetComponent();
        }
    }
    /// 
    /// 界面被显示出来。可设置显示界面动画
    /// 
    public virtual  void OnEnter()
    {
        if (canvasGroup == null) canvasGroup = GetComponent();
        canvasGroup.alpha = 0;
        canvasGroup.blocksRaycasts = true;
        canvasGroup.DOFade(1, .2f);
    }

DoTween常用动画效果_第1张图片

2.左移右移

    public override void OnEnter()
    {
        if (canvasGroup == null) canvasGroup = GetComponent();
        canvasGroup.alpha = 1;
        canvasGroup.blocksRaycasts = true;

        Vector3 temp = transform.localPosition;
        temp.x = 600;
        transform.localPosition = temp;
        transform.DOLocalMoveX(0, .3f);
    }

    public override void OnExit()
    {
        canvasGroup.blocksRaycasts = false;

        transform.DOLocalMoveX(600, .3f).OnComplete(() => canvasGroup.alpha = 0);
    }

DoTween常用动画效果_第2张图片

3.由小变大

    public override void OnEnter()
    {
        if (canvasGroup == null) canvasGroup = GetComponent();
        canvasGroup.alpha = 1;
        canvasGroup.blocksRaycasts = true;

        transform.localScale = Vector3.zero;
        transform.DOScale(0.5f, .3f);
    }

    public override void OnExit()
    {
        canvasGroup.blocksRaycasts = false;

        transform.DOScale(0, .3f).OnComplete(() => canvasGroup.alpha = 0);
    }

DoTween常用动画效果_第3张图片

你可能感兴趣的:(DoTween动画插件)