changhong/lua_probject/base_project/Core/TimerManager.lua

97 lines
1.4 KiB
Lua

TimerManager={}
local timerList={}
local isEnableTimer=false
function TimerManager.New()
timerList={}
UpdateBeat:Add(TimerManager.UpdateTimer)
isEnableTimer=true
end
function TimerManager.IsHas(funcIns)
if timerList then
for k,v in pairs(timerList) do
if v.Self==funcIns then
return true
end
end
end
return false
end
function TimerManager.AddTimer(timerFunc,funcIns)
if timerFunc then
if TimerManager.IsHas(funcIns) then
printlog("已经存在计时器对象")
return
end
local tempList={}
tempList.func=timerFunc
tempList.Self=funcIns
table.insert(timerList,tempList)
else
printlog("添加计时器失败===>>>")
if debug_print==true then
printlog(debug.traceback())
end
end
end
function TimerManager.RemoveTimer(timerFunc,Self)
if timerFunc then
for k,v in pairs(timerList) do
if v.func==timerFunc and v.Self==self then
timerList[k]=nil
--table.remove(timerList,k)
end
end
end
end
function TimerManager.IsEnableTimer(isEnabe)
isEnableTimer=isEnabe
end
function TimerManager.UpdateTimer()
if isEnableTimer and #timerList>0 then
for k,v in pairs(timerList) do
if v.func then
v.func(v.Self)
end
end
end
end
function TimerManager.Clear()
timerList={}
end
function TimerManager.EnableTimer()
isEnableTimer=true
end
function TimerManager.StopAllTimer()
isEnableTimer=false
timerList={}
end
return TimerManager