【战斗】优化战斗资源回收机制,修复跳过战斗时灵兽报错

dev_chengFeng
gaoxin 2020-11-17 14:05:46 +08:00
parent 8f3325ad5f
commit 6a515c2374
2 changed files with 42 additions and 23 deletions

View File

@ -881,33 +881,48 @@ function this.LoadAsset(path, battleSorting)
return go
end
--++++++++++++++所有需要延迟回收的资源走该接口,当回调执行前界面已被销毁时,不会报错
--
function this.LateUpdate()
if not this._delayRecycleList then return end
for _, list in pairs(this._delayRecycleList) do
local i = 1
while i <= #list do
-- 没有下一个
if not list[i] then
i = i + 1
end
--
list[i].delayTime = list[i].delayTime - Time.deltaTime
if list[i].delayTime <= 0 then
Util.SetGray(list[i].go, false)
poolManager:UnLoadAsset(list[i].path, list[i].go, PoolManager.AssetType.GameObject)
if list[i].delayFunc then
list[i].delayFunc()
end
table.remove(list, i)
else
i = i + 1
end
end
end
end
function this.AddDelayRecycleRes(path, go, delayTime, delayFunc)
if not this._delayRecycleList[path] then
this._delayRecycleList[path] = {}
end
table.insert(this._delayRecycleList[path], go)
Timer.New(function ()
if not this._delayRecycleList[path] then return end
for i=1, #this._delayRecycleList[path] do
if this._delayRecycleList[path][i] == go then
Util.SetGray(go, false)
poolManager:UnLoadAsset(path, go, PoolManager.AssetType.GameObject)
table.remove(this._delayRecycleList[path], i)
break
end
end
if delayFunc then
delayFunc()
end
end, delayTime):Start()
table.insert(this._delayRecycleList[path], {path = path, go = go, delayTime = delayTime, delayFunc = delayFunc})
end
function this.RecycleAllDelayRes()
--立即回收延迟列表上的资源
for k, v in pairs(this._delayRecycleList) do
for _, v in pairs(this._delayRecycleList) do
for i=1, #v do
Util.SetGray(v[i], false)
poolManager:UnLoadAsset(k, v[i], PoolManager.AssetType.GameObject)
Util.SetGray(v[i].go, false)
poolManager:UnLoadAsset(v[i].path, v[i].go, PoolManager.AssetType.GameObject)
end
end
this._delayRecycleList = {}
@ -943,5 +958,4 @@ end
--++++++++++++++++++++++++++++++++++++++++++
return this

View File

@ -144,14 +144,18 @@ function MonsterView:OnSkillEnd()
end
function MonsterView:OnSkillCastingStart()
-- 提前进入下一阶段
self.RoleLiveGO2:SetActive(true)
self:PlaySpineAnim(self.RoleLiveGOGraphic2, 0, "attack", false)
if self.RoleLiveGO2 then
-- 提前进入下一阶段
self.RoleLiveGO2:SetActive(true)
self:PlaySpineAnim(self.RoleLiveGOGraphic2, 0, "attack", false)
end
end
function MonsterView:OnSkillCastingEnd()
self.RoleLiveGO2:SetActive(false)
if self.RoleLiveGO2 then
self.RoleLiveGO2:SetActive(false)
end
end
@ -162,6 +166,7 @@ function MonsterView:onDispose()
self.RoleLiveGOGraphic2.freeze = false
-- poolManager:UnLoadLive(self.livePath, self.RoleLiveGO2)
GameObject.DestroyImmediate(self.RoleLiveGO2)
self.RoleLiveGO2 = nil
-- 回收本节点
BattlePool.RecycleItem(self.GameObject, BATTLE_POOL_TYPE.ENEMY_ROLE)
end