【战斗】修复战斗跳过时,人物回收,但是延时方法依然会执行的问题

dev_chengFeng
gaoxin 2021-11-22 16:42:14 +08:00
parent 21fa0c1762
commit 66670029dc
1 changed files with 9 additions and 13 deletions

View File

@ -40,29 +40,25 @@ function BattleUnit:DelayFunc(time, func)
end
local timer
timer = Timer.New(function ()
if func then func() func = nil end
if self._DelayFuncList[timer] then
self._DelayFuncList[timer]()
end
self:ClearDelayFunc(timer)
end, time)
timer:Start()
table.insert(self._DelayFuncList, timer)
--
self._DelayFuncList[timer] = func
end
function BattleUnit:ClearDelayFunc(t)
if not self._DelayFuncList then return end
if t then
local rIndex
for index, timer in ipairs(self._DelayFuncList) do
if timer == t then
rIndex = index
break
end
end
if rIndex then
self._DelayFuncList[rIndex]:Stop()
table.remove(self._DelayFuncList, rIndex)
if self._DelayFuncList[t] then
t:Stop()
self._DelayFuncList[t] = nil
end
else
for _, timer in ipairs(self._DelayFuncList) do
for timer, func in pairs(self._DelayFuncList) do
timer:Stop()
end
self._DelayFuncList = {}