温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Unity NGUI TWEEN

发布时间:2020-06-29 23:32:30 来源:网络 阅读:1038 作者:Aonaufly 栏目:开发技术

大家都知道NGUI中自带了缓动(Tween),我一开始使用的时候,只能让他缓动1次。这里面有一个UIPlayTween可以帮你多次的运行Tween。当然,你可以借助DOTween , ITween等专业的第三方缓动插件。本篇文章只讲解: NGUI的Tween


首先对栗子进行一些简单的讲解:

主要是对“目标GO”进行位移操作


Unity NGUI TWEEN

对于“目标GO”需要挂载:TweenPosition , UIPlayTween , 还有我自己的一个脚本 : TestTweenPos(只要是操作TweenPosition,UIPlayTween)

关于 : TweenPosition:

Unity NGUI TWEEN

关于 UIPlayTween:

Unity NGUI TWEEN

关于 TestTweenPos:

Unity NGUI TWEEN

有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的值。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI