这是今天做的一个小功能
策划想要一个时间滚动效果
那就搞呗!思路和之前写的tweenFillAmount一样
传送门:http://www.cnblogs.com/shenggege/p/4798923.html
时间格式:00:00:00
以下是代码,可以结合上文的链接一起看
#region HeadComments
/* ========================================================================
* Copyright (C) 2015 Arthun
*
* 作 者:Arthun
* 文件名称:TweenTime
* 功 能:滚动时间
* 创建时间:2015/12/21 15:51:58
*
* =========================================================================
*/
#endregion using UnityEngine; [RequireComponent(typeof(UILabel))]
[AddComponentMenu("NGUI/Tween/Tween Time")]
public class TweenTime : UITweener
{
public float from = 1f;
public float to = 1f; private bool mCached = false;
private UILabel mLable; private void Cache()
{
mCached = true;
mLable = GetComponent<UILabel>();
} public float value
{
get
{
if (!mCached) Cache();
return 0f;
}
set
{
if (!mCached) Cache();
if (mLable != null)
mLable.text = getTimeFormat(value);
}
} protected override void OnUpdate(float factor, bool isFinished) { value = Mathf.Lerp(from, to, factor); } public override void SetStartToCurrentValue() { from = value; } public override void SetEndToCurrentValue() { to = value; } private string getTimeFormat(float time)
{
if (time <= ) return "00:00:00"; System.TimeSpan ts = new System.TimeSpan(, , (int)(time));
return ts.Hours.ToString().PadLeft(, '') + ":" + ts.Minutes.ToString().PadLeft(, '') + ":" + ts.Seconds.ToString().PadLeft(, '');
}
}