[Unity]Lua本地时间、倒计时和正计时。

这篇具有很好参考价值的文章主要介绍了[Unity]Lua本地时间、倒计时和正计时。。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

惯例,直接上代码:文章来源地址https://www.toymoban.com/news/detail-657392.html

--正计时开始时的时间戳
self.begin_time = os.time()
--倒计时时长,01:30:00
self.countdown_time = 5400
--是否开始计时
self.is_update_local_time = true

--Unity Update
function time_transition:update_local_timer()
    if not self.is_update_local_time then 
        return
    end
    self.begin_time = self.begin_time + 1
    --正计时
    local positive_time = self.begin_time
    if positive_time > self.countdown_time then
        self.is_update_local_time = false
        self.text_positive_time.text = "01:30:00"
    else
        local positive_time_table = {}
        if positive_time < 60 then
            positive_time_table.hour = 0
            positive_time_table.minute = 0
            positive_time_table.second = positive_time
        elseif positive_time > 60 and positive_time < 3600 then
            positive_time_table.hour = 0
            positive_time_table.minute = math.modf(positive_time / 60)
            positive_time_table.second = positive_time - positive_time_table.minute * 60
        else
            positive_time_table.hour = math.modf(positive_time / 3600)
            positive_time_table.minute = math.modf((positive_time - positive_time_table.hour * 3600) / 60)
            positive_time_table.second = positive_time - positive_time_table.minute * 60 - positive_time_table.hour * 3600
        end
        self.text_positive_time.text = self:local_time_format(positive_time_table)
    end
    --倒计时
    local countdown_time = self.countdown_time - positive_time
    local countdown_time_table = {}
    if countdown_time > 3600 then
        countdown_time_table.hour = math.modf(countdown_time / 3600)
        countdown_time_table.minute = math.modf((countdown_time - countdown_time_table.hour * 3600) / 60)
        countdown_time_table.second = countdown_time - countdown_time_table.minute * 60 - countdown_time_table.hour * 3600
    elseif countdown_time > 60 and countdown_time < 3600 then
        countdown_time_table.hour = 0
        countdown_time_table.minute = math.modf(countdown_time / 60)
        countdown_time_table.second = countdown_time - countdown_time_table.minute * 60
    else
        countdown_time_table.hour = 0
        countdown_time_table.minute = 0
        countdown_time_table.second = countdown_time
    end
    if countdown_time > 0 then
        self.text_countdown_time.text = self:local_time_format(countdown_time_table)
    else
        self.text_countdown_time.text = "00:00:00"
    end
end

--格式化时间:00:00:00
function time_transition:local_time_format(time_table)
	local str_time = ""
	if time_table.hour then
		if time_table.hour >= 0 and time_table.hour < 10 then
			str_time = string.format("0%d" ,time_table.hour)
		else
			str_time = string.format("%d" ,time_table.hour)
		end
	end
	if time_table.minute then
		if time_table.minute >= 0 and time_table.minute < 10 then
			str_time = string.format("%s:0%d" ,str_time ,time_table.minute)
		else
			str_time = string.format("%s:%d" ,str_time ,time_table.minute)
		end
	end
	if time_table.second then
		if time_table.second >= 0 and time_table.second < 10 then
			str_time = string.format("%s:0%d" ,str_time ,time_table.second)
		else
			str_time = string.format("%s:%d" ,str_time ,time_table.second)
		end
	end
	return str_time
end

到了这里,关于[Unity]Lua本地时间、倒计时和正计时。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 基于51单片机交通灯带紧急开关+黄灯倒计时+可调时间

    仿真图proteus 7.8 程序编译器:keil 4/keil 5 编程语言:C语言 设计编号:J000 功能说明: 采用51单片机以及单片机最小系统和三极管驱动电路以及外围的按键和数码管显示等部件,设计一个基于单片机的交通灯设计。 1.四路交通灯,带有红绿灯倒计时,绿灯倒计时结束后转黄灯

    2024年02月06日
    浏览(30)
  • 测试开发面试宝典,涨价倒计时

    大家好,我是洋子,相信在面试软件测试、测试开发岗位的小伙伴都深有体会,考察的知识点越来越多 不仅会考察到软件测试的理论,让你对某种功能进行测试用例的设计,更难一点会给出一个 测试场景 进行测试方案的设计,现如今有的公司在面试时,甚至还会问到接口测

    2024年02月05日
    浏览(50)
  • 帮我写一个跨年html倒计时代码,达到预定时间切换为放烟花

    以下是一个简单的 HTML 倒计时代码,在跨年时会切换为放烟花的效果: 上面的

    2024年02月03日
    浏览(44)
  • vue-element-table表格实现每一条数据绑定定时器实现倒计时或者持续时间

    前言 最近在开发中遇到一个需求,每一条数据前端计算处理时间,或者是倒计时时间。 第一表格不可能展示所有数据,所以我们需要当前时间和数据库开始时间获取一个初始值。 第二我们需要把定时器持续时间绑给每一条数据中,方便展示,和操作时候传递给后端存储。

    2024年01月20日
    浏览(41)
  • arm学习stm32之spi总线数码管倒计时,裸机开发,soc

    由于时间没有用时间计时器操作,有些误差,后续有空会翻新计时器版本 main.c spi.c spi.h

    2024年02月16日
    浏览(36)
  • 蓝桥杯倒计时 | 倒计时4天

    作者🕵️‍♂️:让机器理解语言か 专栏🎇:蓝桥杯倒计时冲刺 描述🎨:蓝桥杯冲刺阶段,一定要沉住气,一步一个脚印,胜利就在前方! 寄语💓:🐾没有白走的路,每一步都算数!🐾 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数 n): 先输入一个自

    2023年04月09日
    浏览(42)
  • 51单片机实现倒计时,按键控制倒计时

    基于AT89C52的答辩倒计时。四个按键分别控制倒计时开始,暂停,时间加和减。剩下30S时蜂鸣器响,倒计时结束蜂鸣器响。  

    2024年02月07日
    浏览(40)
  • 分析 vant4 源码,学会用 vue3 + ts 开发毫秒级渲染的倒计时组件,真是妙啊

    2022年11月23日首发于掘金,现在同步到公众号。 11. 前言 大家好,我是若川。推荐点右上方蓝字若川视野把我的公众号 设为星标 。我倾力持续组织了一年多源码共读,感兴趣的可以加我微信 lxchuan12 参与。另外,想学源码,极力推荐关注我写的专栏《学习源码整体架构系列》

    2024年02月05日
    浏览(79)
  • Flutter实现倒计时功能,秒数转时分秒,然后倒计时

    Flutter实现倒计时功能 发布时间:2023/05/12 本文实例为大家分享了Flutter实现倒计时功能的具体代码,供大家参考,具体内容如下 有一个需求,需要在页面进行显示倒计时,倒计时结束后,做相应的逻辑处理。 实现思路:在Flutter中,Timer.periodic提供了循环功能,查看函数定义:

    2024年02月13日
    浏览(35)
  • 手机短信验证码登录功能的开发实录(机器识别码、短信限流、错误提示、发送验证码倒计时60秒)

    短信验证码是通过发送验证码到手机的一种有效的验证码系统,作为比较准确和安全地保证购物的安全性,验证用户的正确性的一种手段,几乎网站登录都会使用该方式。 其特点是依据某些验证码接入商提供手机短信验证码服务,各网站通过接口发送请求到接入商的服务器,

    2024年02月02日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包