编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Xlua开发笔记:计时器(计时器程序员)

wxchong 2024-09-14 15:08:32 开源技术 8 ℃ 0 评论
-- 计时器对象
local xluaTimer
-- 是否存在计时器
local isTimerExist = false
-- 记录上次执行操作的时间
local lastTime = CS.UnityEngine.Time.time
-- 计时器间隔
local interval = 1.0

-- 创建计时器
function createXluaTimer()
  isTimerExist = true
  if xluaTimer = nil then
    xluaTimer = GameObject("xluaTimer")
    xluaTimer = CS.UnityEngine.Object.Instantiate(xluaTimer)
    local timerBehaviour = xluaTimer:AddComponent(typeof(CS.xxx(自命名namespace).LuaBehavior))
    timerBehaviour:Init('xl')
  end
end

-- 停止计时
function cancelXluaTimer()
  if not isTimerExist then
  	return
  end
  isTimerExist = false
end

function xlUpdate()
  if unityEngine.Time.time - lastGcdTime > interval and isTimerExist then
  lastGcdTime = CS.UnityEngine.Time.time
    -- 定时执行的方法
    excuteFunc()
  end
end

function excuteFunc()
  print('定时执行的方法')
end

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表