標籤:
原文連結: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("動畫結束"); } }
【轉載】UGUI動畫