local UIPrefabObject = require "app/bf/unity/uiprefab_object" local BattleHelper = {} function BattleHelper:init() self.isClear = false self.characterPools = {} self.characterMap = {} self.buffEffectPool = {} self.battleEffectTextMap = {} self.battleEffectTextPool = {} self.seed = tonumber(tostring(os.time()):reverse():sub(1,6)) end function BattleHelper:setTimeScale(timeScale) if self.effectMap then for k, effect in pairs(self.effectMap) do effect:setTimeScale(timeScale) end end if self.characterMap then for k, character in pairs(self.characterMap) do character:setTimeScale(timeScale) end end end function BattleHelper:random(min, max) self.seed = (self.seed*9301 + 49297)%233280 return min + self.seed*(max - min + 1)//233280 end function BattleHelper:getSupportInterval() if self.supportInterval == nil then self.supportInterval = GFunc.getConstIntValue("support_interval")/1000 end return self.supportInterval 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 local timeScale = DataManager.BattleData:getTimeScale() spineObject:setTimeScale(timeScale) callback(spineObject) else SpineManager:loadHeroAsync(id, parent, function(spineObject) spineObject:setDefaultMix(0) if self.characterMap then self.characterMap[spineObject:getInstanceID()] = spineObject local timeScale = DataManager.BattleData:getTimeScale() spineObject:setTimeScale(timeScale) 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:setEffectTextCache(cache1, cache2, cache3, cache4) if self.effectTextCacheList == nil then self.effectTextCacheList = {} end self.effectTextCacheList[1] = cache1 self.effectTextCacheList[2] = cache2 self.effectTextCacheList[3] = cache3 self.effectTextCacheList[4] = cache4 end function BattleHelper:getEffectText(parent, colorType) local pool = self.battleEffectTextPool[colorType] if #pool <= 0 then local prefab = CS.UnityEngine.Object.Instantiate(self.effectTextCacheList[colorType]:getGameObject()) local prefabObject = UIPrefabObject:create() prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab) prefabObject:initPrefabHelper() prefabObject:getTransform():SetAsLastSibling() prefabObject:setParent(parent, false) local comp = prefabObject:addLuaComponent(GConst.BattleConst.TYPEOF_LUA_COMP.BATTLE_NUMBER_COMPONENT) comp:setColorType(colorType) comp:setEnabled(true) return comp else local effectComp = table.remove(pool) effectComp:setEnabled(true) effectComp.baseObject:getTransform():SetAsLastSibling() self.battleEffectTextMap[effectComp.baseObject:getInstanceID()] = effectComp return effectComp end end function BattleHelper:recycleEffectText(comp) if comp:isDestroyed() then return end comp:setEnabled(false) local colorType = comp:getColorType() local pool = self.battleEffectTextPool[colorType] table.insert(pool, comp) if self.battleEffectTextMap then self.battleEffectTextMap[comp.baseObject:getInstanceID()] = nil end end function BattleHelper:getBuffEffect() if #self.buffEffectPool > 0 then return table.remove(self.buffEffectPool) end return {} end function BattleHelper:recycleBuffEffect(buffEffect) table.insert(self.buffEffectPool, buffEffect) end function BattleHelper:clear() self.isClear = true self.characterPools = nil self.characterMap = nil self.effectTextCache = nil self.buffEffectPool = nil self.battleEffectTextMap = nil self.battleEffectTextPool = nil end return BattleHelper