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

72 lines
1.9 KiB
Lua
Raw Normal View History

2020-05-09 13:31:21 +08:00
--- 子物体管理器(动态加载)
SubUIManager = {}
local this = SubUIManager
local function playUIAnimsOnStart(gameObject, callback)
local anims = gameObject:GetComponentsInChildren(typeof(PlayFlyAnim))
if anims.Length > 0 then
for i=0, anims.Length-1 do
local anim = anims[i]
if anim.isPlayOnOpen then
anim:PlayAnim(false, callback)
end
end
end
end
local function createPanel(uiConfig, parent)
local gameObject = poolManager:LoadAsset(uiConfig.assetName, PoolManager.AssetType.GameObject)
gameObject.name = uiConfig.name
local transform = gameObject.transform
transform:SetParent(parent)
transform.localScale = Vector3.one
local recTransform = transform:GetComponent("RectTransform")
recTransform.anchoredPosition3D = Vector3.New(0, 0, 0)
recTransform.sizeDelta = Vector2.New(0, 0)
transform.localRotation = Quaternion.identity
return gameObject
end
function this.Open(config,parent,...)
local view = reimport(config.script)
local gameObject = createPanel(config,parent)
if gameObject then
playUIAnimsOnStart(gameObject)
end
local sub = view:New(gameObject)
sub.assetName = config.assetName
if sub.Awake then
sub:Awake()
end
if sub.InitComponent then
sub:InitComponent()
end
if sub.BindEvent then
sub:BindEvent()
end
if sub.AddListener then
sub:AddListener()
end
if sub.Update then
UpdateBeat:Add(sub.Update, sub)
end
if sub.OnOpen then
sub:OnOpen(...)
end
return sub
end
function this.Close(sub)
if sub.RemoveListener then
sub:RemoveListener()
end
if sub.Update ~= nil then
UpdateBeat:Remove(sub.Update, sub)
end
if sub.OnClose then
sub:OnClose()
end
poolManager:UnLoadAsset(sub.assetName, sub.gameObject, PoolManager.AssetType.GameObject)
end
return this