84 lines
2.2 KiB
Lua
84 lines
2.2 KiB
Lua
--- 子物体管理器(动态加载)
|
|
|
|
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 _obj = resMgr:LoadAsset(uiConfig.assetName)
|
|
local gameObject = GameObject.Instantiate(_obj)
|
|
gameObject.name = uiConfig.name
|
|
local transform = gameObject.transform
|
|
transform:SetParent(parent)
|
|
transform.localScale = Vector3.one
|
|
local recTransform = transform:GetComponent("RectTransform")
|
|
if recTransform then
|
|
recTransform.anchoredPosition3D = Vector3.New(0, 0, 0)
|
|
recTransform.sizeDelta = Vector2.New(0, 0)
|
|
end
|
|
|
|
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.lspLoader = SpriteLoader.New()
|
|
UIManager.DoLanguageCheck(sub.lspLoader, 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
|
|
if sub.lspLoader then
|
|
sub.lspLoader:Destroy()
|
|
sub.lspLoader = nil
|
|
end
|
|
resMgr:UnLoadAsset(sub.assetName)
|
|
GameObject.Destroy(sub.gameObject)
|
|
-- LogError("sub UI close: "..sub.assetName)
|
|
end
|
|
|
|
|
|
return this |