zoukankan      html  css  js  c++  java
  • 【转载】UGUI动画

    原文链接:http://blog.sina.com.cn/s/blog_89d90b7c0102vi4y.html

    Unity暂时没有单独给UGUI提供动画系统,用官方的动画系统也能做只是比较麻烦,所以我们有很多选择了。

    1.修改NGUI的UITweener在用UGUI上,轻量级动画系统。

    2.使用第三方插件入iTween,DoTween,HOTween等。

    发现DoTween不错,就试试了。

    先来看效果图:


    这里用到了位置,旋转,缩放,颜色四个最主要的动画效果,暂时简单写一个例子,以便以后使用时查阅。

    下载地址和详细使用说明如下。

    下载地址:http://dotween.demigiant.com/download.php

    文档地址:http://dotween.demigiant.com/documentation.php

    下载之后复制到工程目录,VS引用DOTween.dll,代码引用using DG.Tweening即可。

    demo代码如下:

    using UnityEngine;  
    using System.Collections;  
    using UnityEngine.UI;  
    using DG.Tweening;   
      
    public class UIFirstAnima : MonoBehaviour   
    {  
        private Tweener m_pos;  
        private Tweener m_rota;  
        private Tweener m_scale;  
        private Tweener m_color;  
        void Start () {  
            // 全局初始化  
            DOTween.Init(true, true, LogBehaviour.ErrorsOnly).SetCapacity(200, 10);  
            Image image = transform.GetComponent();  
            // 位置  
            m_pos = image.rectTransform.DOMove(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f,0), 1f);  
            m_pos.SetEase(Ease.OutCubic);  
            m_pos.SetLoops(10,LoopType.Yoyo);  
            // 旋转  
            m_rota = image.rectTransform.DORotate(new Vector3(0,180,0), 1);  
            m_rota.SetEase(Ease.Linear);  
            m_rota.SetLoops(10, LoopType.Yoyo);  
            // 缩放  
            m_scale = image.rectTransform.DOScale(new Vector3(0.6f, 0.6f, 1f), 1);  
            m_scale.SetEase(Ease.Linear);  
            m_scale.SetLoops(10, LoopType.Yoyo);  
            // 颜色  
            m_color = image.material.DOColor(new Color(0f,1f,1f, 0.7f), 1f);  
            m_color.SetEase(Ease.Linear);  
            m_color.SetLoops(10, LoopType.Yoyo);  
            // 注册开始和结束事件  
            m_pos.OnStart(AnimaStart);  
            m_pos.OnComplete(AnimaEnd);  
        }  
        private void AnimaStart()  
        {  
            Debug.Log("动画开始");  
        }  
        private void AnimaEnd()  
        {  
            Debug.Log("动画结束");  
        }  
    }  
    

      本人使用心得:

           domoveX(target,duration)中的target是指的目标位置;

  • 相关阅读:
    P6007 [USACO20JAN]Springboards G
    CF1000F One Occurrence
    P6100 [USACO19FEB]Painting the Barn G
    P5838 [USACO19DEC]Milk Visits G
    P4085 [USACO17DEC]Haybale Feast
    P4267 [USACO18FEB]Taming the Herd
    P1712 [NOI2016]区间
    CF786B Legacy
    P5665 划分
    NOI2020网上同步赛 游记
  • 原文地址:https://www.cnblogs.com/WongSiuming/p/4868328.html
Copyright © 2011-2022 走看看