大家都知道NGUI中自帶了緩動(Tween),我一開始使用的時候,只能讓他緩動1次。這里面有一個UIPlayTween可以幫你多次的運行Tween。當然,你可以借助DOTween , ITween等專業的第三方緩動插件。本篇文章只講解: NGUI的Tween
首先對栗子進行一些簡單的講解:
主要是對“目標GO”進行位移操作

對于“目標GO”需要掛載:TweenPosition , UIPlayTween , 還有我自己的一個腳本 : TestTweenPos(只要是操作TweenPosition,UIPlayTween)
關于 : TweenPosition:

關于 UIPlayTween:

關于 TestTweenPos:

有2個參數 : 分別是上面的TweenPosition和UIPlayTween
上 TestTweenPos代碼 :
using UnityEngine;
using System.Collections;
public class TestTweenPos : MonoBehaviour {
// Use this for initialization
public TweenPosition _tweenPos;
public UIPlayTween _playTween;
private bool _isRe = false;
void Start () {
}
// Update is called once per frame
void Update () {
}
public void StartTween( Vector2 _location )
{
if( !this._isRe)
{
this._tweenPos.from = new Vector3(this.gameObject.transform.localPosition.x, this.gameObject.transform.localPosition.y, 0);
this._tweenPos.to = new Vector3(_location.x, _location.y, 0.0f);
}
else
{
this._tweenPos.to = new Vector3(this.gameObject.transform.localPosition.x, this.gameObject.transform.localPosition.y, 0);
this._tweenPos.from = new Vector3(_location.x, _location.y, 0.0f);
}
this._isRe = !this._isRe;
this._playTween.Play(true);
}
}這個UIPlayTween的“Toggle”,它就是可開關的意思( 點一下從From 運行到 To , 在點一下從To 運行到 From ,再點從From 運行到To ), 若需要TweenPosition持續的運行,那就需要實時的改變(交換)From和To的值。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。