52 lines
1.4 KiB
Lua
52 lines
1.4 KiB
Lua
local BattleHelper = {}
|
|
|
|
function BattleHelper:init()
|
|
self.isClear = false
|
|
self.characterPools = {}
|
|
self.characterMap = {}
|
|
end
|
|
|
|
function BattleHelper:loadBattleHeroModel(id, parent, callback)
|
|
local pool = self.characterPools[id]
|
|
if pool and #pool > 0 then
|
|
local spineObject = table.remove(pool)
|
|
spineObject:setActive(true)
|
|
if self.characterMap then
|
|
self.characterMap[spineObject:getInstanceID()] = spineObject
|
|
end
|
|
callback(spineObject)
|
|
else
|
|
SpineManager:loadHeroAsync(id, parent, function(spineObject)
|
|
if self.characterMap then
|
|
self.characterMap[spineObject:getInstanceID()] = spineObject
|
|
callback(spineObject)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
function BattleHelper:recycleBattleHeroModel(modelId, character)
|
|
if character:isDestroyed() then
|
|
return
|
|
end
|
|
character:setActive(false)
|
|
if self.characterMap then
|
|
self.characterMap[character:getInstanceID()] = nil
|
|
end
|
|
if self.characterPools then
|
|
local pool = self.characterPools[modelId]
|
|
if pool == nil then
|
|
pool = {}
|
|
self.characterPools[modelId] = pool
|
|
end
|
|
table.insert(pool, character)
|
|
end
|
|
end
|
|
|
|
function BattleHelper:clear()
|
|
self.isClear = true
|
|
self.characterPools = nil
|
|
self.characterMap = nil
|
|
end
|
|
|
|
return BattleHelper |