标签:ngui tween
大家都知道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的值。
本文出自 “Better_Power_Wisdom” 博客,请务必保留此出处http://aonaufly.blog.51cto.com/3554853/1851152
标签:ngui tween
原文地址:http://aonaufly.blog.51cto.com/3554853/1851152