UGUI(五)动画系统

来源:互联网 发布:电脑桌面设置软件 编辑:程序博客网 时间:2024/04/29 15:00

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

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

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

 

发现DoTween不错,就试试了。

先来看效果图:

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

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

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

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

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

 

demo代码如下:

  1. using UnityEngine;  
  2. using System.Collections;  
  3. using UnityEngine.UI;  
  4. using DG.Tweening;   
  5.   
  6. public class UIFirstAnima MonoBehaviour   
  7.  
  8.     private Tweener m_pos;  
  9.     private Tweener m_rota;  
  10.     private Tweener m_scale;  
  11.     private Tweener m_color;  
  12.     void Start ()  
  13.         // 全局初始化  
  14.         DOTween.Init(truetrueLogBehaviour.ErrorsOnly).SetCapacity(20010);  
  15.         Image image transform.GetComponent();  
  16.         // 位置  
  17.         m_pos image.rectTransform.DOMove(new Vector3(Screen.width 0.5f, Screen.height 0.5f,0), 1f);  
  18.         m_pos.SetEase(Ease.OutCubic);  
  19.         m_pos.SetLoops(10,LoopType.Yoyo);  
  20.         // 旋转  
  21.         m_rota image.rectTransform.DORotate(new Vector3(0,180,0), 1);  
  22.         m_rota.SetEase(Ease.Linear);  
  23.         m_rota.SetLoops(10LoopType.Yoyo);  
  24.         // 缩放  
  25.         m_scale image.rectTransform.DOScale(new Vector3(0.6f, 0.6f, 1f), 1);  
  26.         m_scale.SetEase(Ease.Linear);  
  27.         m_scale.SetLoops(10LoopType.Yoyo);  
  28.         // 颜色  
  29.         m_color image.material.DOColor(new Color(0f,1f,1f, 0.7f), 1f);  
  30.         m_color.SetEase(Ease.Linear);  
  31.         m_color.SetLoops(10LoopType.Yoyo);  
  32.         // 注册开始和结束事件  
  33.         m_pos.OnStart(AnimaStart);  
  34.         m_pos.OnComplete(AnimaEnd);  
  35.      
  36.     private void AnimaStart()  
  37.      
  38.         Debug.Log("动画开始");  
  39.      
  40.     private void AnimaEnd()  
  41.      
  42.         Debug.Log("动画结束");  
  43.      
  44.  
0 0
原创粉丝点击