miduo_client/Assets/ManagedResources/~Lua/Framework/Manager/CardRendererManager2.lua

130 lines
3.9 KiB
Lua

CardRendererManager2 = {}
local this = CardRendererManager2
local maxRender = 20
function CardRendererManager2.Initialize()
if this.root then
return
end
local resObj = resMgr:LoadAsset("CardRendererRoot2")
this.root = GameObject.Instantiate(resObj)
GameObject.DontDestroyOnLoad(this.root)
this.renderList = {}
this.textureList = {}
for i = 1, 12 do
this.renderList[i] = Util.GetGameObject(this.root, "CardRenderer"..i.."/Canvas/root")
this.textureList[i] = resMgr:LoadAsset("CardTexture"..i)
end
this.indexFlag = 0
this.liveList = {}
this.usingList = {}
end
-- 获取RenderTexture对象
--- isReuse 是否可以复用已经存在的Texture
function CardRendererManager2.GetSpineTexture(pos, liveName, scaleV3, posV3, isReuse, onClear)
-- 可复用,判断之前是否存在
-- if isReuse then
-- local index = this.CheckIsExist(liveName)
-- if index then
-- return this.textureList[index], this.liveList[index].node
-- end
-- end
-- flag
this.indexFlag = pos --this.indexFlag + 1
-- if this.indexFlag > 20 then
-- this.indexFlag = 1
-- end
-- 回收老资源
local liveData = this.liveList[this.indexFlag]
if liveData then
local liveName = liveData.name
local liveNode = liveData.node
poolManager:UnLoadLive(liveName, liveNode)
this.liveList[this.indexFlag] = nil
end
-- 创建新资源
local parent = this.renderList[this.indexFlag].transform
parent.transform.localScale = Vector3.one
parent.transform.localPosition = Vector3(0, 0, 0)
local liveNode = poolManager:LoadLive(liveName, parent, scaleV3, posV3 + Vector3(0, -120, 0), onClear)
this.liveList[this.indexFlag] = {
name = liveName,
node = liveNode,
parent = parent
}
--
return this.textureList[this.indexFlag], this.liveList[this.indexFlag].node, this.indexFlag, this.liveList[this.indexFlag].parent
end
function CardRendererManager2.GetSpineTexture2(pos, liveName, scaleV3, posV3, isReuse, onClear)
-- 可复用,判断之前是否存在
if isReuse then
LogError("liveName=="..liveName)
local index = this.CheckIsExist(liveName)
if index then
return this.textureList[index], this.liveList[index].node
end
end
-- flag
this.indexFlag = pos --this.indexFlag + 1
-- if this.indexFlag > 20 then
-- this.indexFlag = 1
-- end
-- 回收老资源
local liveData = this.liveList[this.indexFlag]
if liveData then
local liveName = liveData.name
local liveNode = liveData.node
poolManager:UnLoadLive(liveName, liveNode)
this.liveList[this.indexFlag] = nil
end
-- 创建新资源
local parent = this.renderList[this.indexFlag].transform
parent.transform.localScale = Vector3.one
parent.transform.localPosition = Vector3(0, 0, 0)
local liveNode = poolManager:LoadLive(liveName, parent, scaleV3, posV3 + Vector3(0, -120, 0), onClear)
this.liveList[this.indexFlag] = {
name = liveName,
node = liveNode,
parent = parent
}
--
return this.textureList[this.indexFlag], this.liveList[this.indexFlag].node, this.indexFlag, this.liveList[this.indexFlag].parent
end
-- 判断是否存在
function this.CheckIsExist(liveName)
for index, data in ipairs(this.liveList) do
if data.name == liveName then
return index
end
end
end
-- 检测是否正在使用
function this.CheckIsUsing(index)
return this.usingList[index]
end
-- 设置是否正在使用
function this.SetUsing(index, isUsing)
this.usingList[index] = isUsing
end
-- 清除使用列表
function this.ClearUsing()
this.usingList = {}
end
function CardRendererManager2.Dispose()
GameObject.DestroyImmediate(this.root)
end
return CardRendererManager2