2025-06-04 05:02:57 +08:00

65 lines
1.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

FunctionCD = class("FunctionCD")
function FunctionCD:ctor(interval)
interval = interval or 33
self:Reset()
self.timeTick = TimeTickManager.Me():CreateTick(0,interval,self.Update,self,1,true)
end
function FunctionCD:Reset()
self:SetEnable(false)
self.objs = {}
end
function FunctionCD:SetInterval(time)
self.interval = time
self.passedTime = 0
end
function FunctionCD:IsRunning()
if(self.timeTick~=nil) then
return self.timeTick.isTicking
end
return self.running
end
function FunctionCD:SetEnable(val)
if(self.timeTick~=nil) then
if(val) then
self.timeTick:StartTick()
else
self.timeTick:StopTick()
end
end
self.running = val
if(not val) then self.passedTime = 0 end
end
function FunctionCD:Update(deltaTime)
for k,v in pairs(self.objs) do
if(v:RefreshCD(deltaTime)) then
self.objs[k] = nil
end
end
end
--所有add進來的對象必須有RefreshCD函式進行cd重新整理並且cd時間到后返回true否則為false
function FunctionCD:Add(obj)
-- print(self.__cname.." add obj")
self.objs[obj.id] = obj
end
function FunctionCD:Remove(obj)
if(type(obj) == "table") then
obj = obj.id
end
local removed = self.objs[obj]
if(removed and removed.ClearCD) then
removed:ClearCD()
end
self.objs[obj] = nil
end
function FunctionCD:RemoveAll()
self:Reset()
end