--- 子物体管理器(动态加载) 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 if GetCurLanguage()~=0 then local textArr=gameObject:GetComponentsInChildren(typeof(UnityEngine.UI.Text),true); for i = 0, textArr.Length-1 do local textStr=textArr[i].text textArr[i].text=GetLanguageStrById(textStr) if GetCurLanguage() == 2 and textArr[i].font and (string.find(textArr[i].font.name,"kaiu",1) or string.find(textArr[i].font.name,"FZJinLS",1)) then textArr[i].font = Util.LoadFont() end end local imageArr=gameObject:GetComponentsInChildren(typeof(UnityEngine.UI.Image),true); for i = 0, imageArr.Length-1 do if imageArr[i].sprite then local imgStr=imageArr[i].sprite.name if string.sub(imgStr,-3)=="_zh" then imageArr[i].sprite=Util.LoadSprite(imgStr) Log("资源名称:"..imgStr) end end end end 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