倒计时更新组件 每秒更新一次时间文字
来源:互联网 发布:最短距离算法 编辑:程序博客网 时间:2024/05/10 14:43
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
/// <summary>
/// Time text update. 倒计时更新组件 每秒更新一次时间文字
/// </summary>
public class TimeTextUpdate : MonoBehaviour {
Text text;
long time;
long increment = -1;
/// <summary>
/// Add the specified go, time and s.
/// </summary>
/// <param name="go">Go.</param>
/// <param name="time">Time. 秒</param>
public static void Add(GameObject go,long time,long increment= -1){
//毫秒 <== 秒 * 1000;
TimeTextUpdate timeTextUpdate = go.GetComponent<TimeTextUpdate>() ;
if(timeTextUpdate == null){
timeTextUpdate = go.AddComponent<TimeTextUpdate>() ;
}
timeTextUpdate.time = time;
timeTextUpdate.increment = increment;
timeTextUpdate.StartUpdate();
}
// Use this for initialization
void Start () {
}
void _setInterval(){
text.text = _getTimeStr(time);
time += increment;
}
/// <summary>
/// _gets the time string.
/// </summary>
/// <returns>The time string.</returns>
/// <param name="timeLong">Time long.毫秒</param>
string _getTimeStr(long timeLong){
if(timeLong <= 0){
StopUpdate();
if(text != null){
Hashtable data = new Hashtable();
data.Add("go",text.gameObject);
EventManager.I.send("OnTimeTextUpdateCmp",data);
}
return "";
}
long h = timeLong/3600;
long m = (timeLong%3600)/60;
long s = (timeLong%3600)%60;
string str = (h > 0 ? (h +"小时") :"" ) + (m > 0 ? (m +"分") :"" ) + (s > 0 ? (s +"秒") :"" );
return str;
}
public void StartUpdate () {
StopUpdate();
text = gameObject.GetComponent<Text>();
if(text != null && time > 0)
this.InvokeRepeating("_setInterval", 1.0f, 1.0f);
}
public void StopUpdate () {
this.CancelInvoke();
}
void OnDestroy() {
StopUpdate ();
}
}
using UnityEngine.UI;
using System.Collections;
/// <summary>
/// Time text update. 倒计时更新组件 每秒更新一次时间文字
/// </summary>
public class TimeTextUpdate : MonoBehaviour {
Text text;
long time;
long increment = -1;
/// <summary>
/// Add the specified go, time and s.
/// </summary>
/// <param name="go">Go.</param>
/// <param name="time">Time. 秒</param>
public static void Add(GameObject go,long time,long increment= -1){
//毫秒 <== 秒 * 1000;
TimeTextUpdate timeTextUpdate = go.GetComponent<TimeTextUpdate>() ;
if(timeTextUpdate == null){
timeTextUpdate = go.AddComponent<TimeTextUpdate>() ;
}
timeTextUpdate.time = time;
timeTextUpdate.increment = increment;
timeTextUpdate.StartUpdate();
}
// Use this for initialization
void Start () {
}
void _setInterval(){
text.text = _getTimeStr(time);
time += increment;
}
/// <summary>
/// _gets the time string.
/// </summary>
/// <returns>The time string.</returns>
/// <param name="timeLong">Time long.毫秒</param>
string _getTimeStr(long timeLong){
if(timeLong <= 0){
StopUpdate();
if(text != null){
Hashtable data = new Hashtable();
data.Add("go",text.gameObject);
EventManager.I.send("OnTimeTextUpdateCmp",data);
}
return "";
}
long h = timeLong/3600;
long m = (timeLong%3600)/60;
long s = (timeLong%3600)%60;
string str = (h > 0 ? (h +"小时") :"" ) + (m > 0 ? (m +"分") :"" ) + (s > 0 ? (s +"秒") :"" );
return str;
}
public void StartUpdate () {
StopUpdate();
text = gameObject.GetComponent<Text>();
if(text != null && time > 0)
this.InvokeRepeating("_setInterval", 1.0f, 1.0f);
}
public void StopUpdate () {
this.CancelInvoke();
}
void OnDestroy() {
StopUpdate ();
}
}
0 0
- 倒计时更新组件 每秒更新一次时间文字
- NSTimer 倒计时自动登录,每秒更新UI
- java每秒更新页面时间,用jquery ajax方法调用
- js获取当前时间并每秒刷新更新
- 微信小程序倒计时组件更新,加入时间校准、多计时器功能
- 获取系统时间,每一秒钟更新一次
- 记录-C#组件循环更新时间
- 用JS每秒刷新一次时间实现当前时间
- 更新时间
- 封装一个进度条倒计时更新
- 更新JMAIL组件下
- 更新-清理sga组件
- React组件更新混乱
- shell每秒执行一次
- while 每秒执行一次
- 一次更新Datagrid 中多列数据
- 一次更新Datagrid 中多列数据
- 令人沮丧的一次更新
- Android中WebView使用小结
- strerror()
- Leetcode no. 338
- CSS或JS实现gif动态图片的停止与播放
- 清除数据的
- 倒计时更新组件 每秒更新一次时间文字
- Firefox 新增容器标签:可同时登录多个用户
- 如果你30岁还未赚到100万,你就应该看看了
- 一个圆角显示的控件封装
- ios 多个参数的block
- iOS-你真的会用UIMenuController吗?(详细)
- Android:View的测量/onMeasure()方法解析
- 用iPhone 4S带着Ubuntu Linux上网
- 使用gitbook写文档