require("Base/BasePanel") LoadingPanel = Inherit(BasePanel) local this = LoadingPanel local sprites = {"loding1","loding2","loding3","loding4","loding5","loding6"} local tipsConfig = ConfigManager.GetConfig(ConfigName.Tips) --初始化组件(用于子类重写) function LoadingPanel:InitComponent() this.Slider = Util.GetGameObject(self.gameObject, "Slider"):GetComponent("Slider") this.Tip = Util.GetGameObject(self.gameObject, "Slider/Image/LoadingText"):GetComponent("Text") this.SliderText = Util.GetGameObject(self.gameObject, "Slider/Fill Area/Fill/Image/Text"):GetComponent("Text") this.bg = Util.GetGameObject(self.gameObject, "bg1"):GetComponent("Image") screenAdapte(Util.GetGameObject(self.gameObject, "bg1")) screenAdapte(Util.GetGameObject(self.gameObject, "bg2")) end function LoadingPanel:OnOpen() local index = 0 math.randomseed(os.time()) index = math.random(1, #sprites) this.bg.sprite = Util.LoadSprite(sprites[index]) math.randomseed(os.time()) index = math.random(1, 20) this.Tip.text = GetLanguageStrById(tipsConfig[index].Tips) end local callList = {} local curIndex = 0 local lerp = 0 local maxIndex = 0 local function update() if this.Slider and this.SliderText then lerp = math.clamp(lerp + Time.fixedDeltaTime * 15,0,1) local curValue = this.Slider.value * (1-lerp) + curIndex * lerp this.Slider.value = curValue local curTextValue = math.floor(((this.Slider.value * (1-lerp) + curIndex * lerp)/32)*100) curTextValue = curTextValue > 100 and 100 or curTextValue this.SliderText.text = curTextValue .."%" end end function LoadingPanel.AddStep(func) table.insert(callList, func) maxIndex = maxIndex + 1 end function LoadingPanel.OnStep() lerp = 0 curIndex = curIndex + 1 if callList[curIndex] then callList[curIndex]() end end -- 登录时有接口报错时执行,防止登录报错卡死导致进不去游戏的问题 function LoadingPanel.ErrorStep(msg) -- if curIndex >= maxIndex then return end LogError("登录接口"..curIndex..", 报错:"..msg.errCode .. "|"..msg.errMsg) -- 强制进入下一步 LoadingPanel.OnStep() end function LoadingPanel.Start() if #callList <= 1 then return end UIManager.OpenPanel(UIName.LoadingPanel) UpdateBeat:Add(update) lerp = 0 curIndex = 0 this.Slider.maxValue = #callList - 1 this.Slider.value = curIndex --"你知道嘛:充值会让你变得更强!" --"白驹工作室倾情奉献" LoadingPanel.OnStep() end function LoadingPanel.End() UpdateBeat:Remove(update) this:ClosePanel() callList = {} end return LoadingPanel