这是今天做的一个小功能
策划想要一个时间滚动效果
那就搞呗!思路和之前写的tweenFillAmount一样
传送门:http://www.cnblogs.com/shenggege/p/4798923.html
时间格式:00:00:00
以下是代码,可以结合上文的链接一起看
1 #region HeadComments 2 /* ======================================================================== 3 * Copyright (C) 2015 Arthun 4 * 5 * 作 者:Arthun 6 * 文件名称:TweenTime 7 * 功 能:滚动时间 8 * 创建时间:2015/12/21 15:51:58 9 * 10 * ========================================================================= 11 */ 12 #endregion 13 14 using UnityEngine; 15 16 [RequireComponent(typeof(UILabel))] 17 [AddComponentMenu("NGUI/Tween/Tween Time")] 18 public class TweenTime : UITweener 19 { 20 public float from = 1f; 21 public float to = 1f; 22 23 private bool mCached = false; 24 private UILabel mLable; 25 26 private void Cache() 27 { 28 mCached = true; 29 mLable = GetComponent<UILabel>(); 30 } 31 32 public float value 33 { 34 get 35 { 36 if (!mCached) Cache(); 37 return 0f; 38 } 39 set 40 { 41 if (!mCached) Cache(); 42 if (mLable != null) 43 mLable.text = getTimeFormat(value); 44 } 45 } 46 47 protected override void OnUpdate(float factor, bool isFinished) { value = Mathf.Lerp(from, to, factor); } 48 49 public override void SetStartToCurrentValue() { from = value; } 50 51 public override void SetEndToCurrentValue() { to = value; } 52 53 private string getTimeFormat(float time) 54 { 55 if (time <= 0) return "00:00:00"; 56 57 System.TimeSpan ts = new System.TimeSpan(0, 0, (int)(time)); 58 return ts.Hours.ToString().PadLeft(2, ‘0‘) + ":" + ts.Minutes.ToString().PadLeft(2, ‘0‘) + ":" + ts.Seconds.ToString().PadLeft(2, ‘0‘); 59 } 60 }
本文链接:http://www.cnblogs.com/shenggege/p/5063852.html
时间: 2024-10-27 12:10:15