local UILoadingPanel = UIViewClass() local curProgress = 0 local LoadingTexPathAB = ConstAssetPathConfig.LoadingTexPathAB local progressShow = "%s%s/%s(%s/S)" local PlotReviewBG = "Loading_2" -- **************** 通用部分 ******************* -- function UILoadingPanel:OnCreated() UIUtils.SetActive(self.btn_Download, false) end function UILoadingPanel:OnOpened() self.targetProgress = 0 curProgress = 0 self.bgPath = nil self.bgTex = nil self:RegisterEvents() if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.HotFix then --刚打开Loading显示资源检测文本 UIUtils.SetLabelText(self.ProgressLabel, Const_IDS.IDS_LoginCheckResource) else if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.PlotReview then self:UpdateLoadingTex(PlotReviewBG) else self:SetLoadingImgBg() end self:SetLoadingTips() end self:StartRepeatFunc(self.OnUpdateFun, 0) --版本显示 if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.HotFix or MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.FastFollowAssetPack or MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.StagePackage then self.txt_Version.text = MDL.HotFix.GetVersionInfo() else self.txt_Version.text = nil end self.txt_Version.gameObject:SetActive(false) self:SetVN18LogoConfig() if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.StagePackage then self.pack1MaxSize = CTL.HotFix.GetStage1TotalDownloadSize() end UTL.UIRender.AdaptiveImageSizeFit(self.LoadingTex) UIUtils.SetActive(self.img_Frame2, not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UILoginVideo, true)) end function UILoadingPanel:OnButtonClicked(comp) if comp == self.btn_Download then CTL.HotFix.ContinueDownload() end end function UILoadingPanel:SetLoadingImgBg() local idRange = DataSheetManager.LoadingExpressionData:GetDataCount() local randomId = CTL.Loading.GetRandomNumber(idRange) self:UpdateLoadingTex(DataSheetManager.LoadingExpressionData:GetDataByID(randomId).ParamStr1) end function UILoadingPanel:EnableBG(enable) UIUtils.SetActive(self.LoadingTex, enable) end function UILoadingPanel:SetLoadingTips() if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.None then UIUtils.SetLabelText(self.ProgressLabel, Const_IDS.IDS_LoginCheckResource) else local tipsNum = DataSheetManager.LoadingTips:GetDataCount() local randomId = CTL.Loading.GetRandomNumber(tipsNum) local tip = DataSheetManager.LoadingTips:GetDataByID(randomId).LoadingTextIDS UIUtils.SetLabelText(self.ProgressLabel, Const_IDS[tip]) end end function UILoadingPanel:RegisterEvents() self:RegistSystemEvent(EventID.UI_Loading_UpdateFastFollowProgress, self.UpdateFastFollowProgress) self:RegistSystemEvent(EventID.UI_Loading_HandleStep, self.HandleLoadStep) self:RegistSystemEvent(EventID.UI_Loading_UpdateTips, self.UpdateProgressLabel) if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.HotFix or MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.StagePackage then self:RegistSystemEvent(EventID.UI_Loading_UpdateDownloadProgress, self.UpdateHotFixProgress) self:RegistSystemEvent(EventID.Pause_Download, self.OnDownloadPause) end self:RegistSystemEvent(EventID.UpdateDownloadState, self.SetDownloadBtn) self:RegistSystemEvent(EventID.UI_Loading_EnableBG, self.EnableBG) end function UILoadingPanel:OnUpdateFun(deltaTime, timeSinceUpdate) if MDL.Loading.GetIsLoadingState() == false then self:UpdateProgress(1) self:CloseView() return end if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.None then self:UpdateProgress(1) return end --处理登录前进度条 if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.HotFix or MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.StagePackage then self:UpdateProgress(self.targetProgress) elseif MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.EnterWorld then --处理登录到主城的进度条 local progress = CTL.Loading.GetLoginLoadingProgress() if progress > curProgress then -- 登录到50% ,后面的都是靠switchLevel调用的UILoadingPanel:HandleLoadStep控制的更新进度 self:UpdateProgress(progress) end end end function UILoadingPanel:HandleLoadStep(step) if step == LuaConst.Enum_LoadingStep.EnterLevel then self:UpdateProgress(1) elseif step == LuaConst.Enum_LoadingStep.FastPlay then local preProgress = CTL.Loading.GetInGameLoadingProgress(step) self:UpdateProgress(preProgress) if preProgress > 0.8 then UIUtils.SetLabelText(self.ProgressLabel , Const_IDS.IDS_ConnectingBattle2 )-- 更新进度条下面的文字 else UIUtils.SetLabelText(self.ProgressLabel , Const_IDS.IDS_ConnectingBattle1 )-- 更新进度条下面的文字 end else local preProgress = CTL.Loading.GetInGameLoadingProgress(step) local curProgressTemp = curProgress if preProgress> curProgressTemp then self:UpdateProgress(preProgress) end end end function UILoadingPanel:UpdateLoadingTex(texName) if self.bgPath and self.bgTex then TK2API.ReturnAsset(self.bgPath, self.bgTex) end self.bgPath = string.format(LoadingTexPathAB, texName) self.bgTex = TK2API.GetTextureAsset(self.bgPath) self.LoadingTex.texture = self.bgTex end function UILoadingPanel:UpdateProgressLabel(value) UTL.String.SetLabelContent(self.ProgressLabel,value) end function UILoadingPanel:UpdateHotFixProgress(curSize, maxSize, speed) if MDL.Loading.LoadingType == MDL.Loading.LoadingTypeEnum.HotFix then self.ProgressLabel.text = string.format(progressShow, UIUtils.GetLocalizedTxt(Const_IDS.IDS_LoginDownload), UTL.String.TransferKiloBytesSize(curSize), UTL.String.TransferKiloBytesSize(maxSize), UTL.String.TransferKiloBytesSize(speed)) self.targetProgress = curSize / maxSize else --分包下载的进度应该是所有小分包的总和的进度 maxSize = self.pack1MaxSize curSize = curSize + CTL.HotFix.GetStage1DownloadedSize(LoginProxy.GetCurStage()) self.ProgressLabel.text = string.format(progressShow, UIUtils.GetLocalizedTxt(Const_IDS.IDS_LoginDownload), UTL.String.TransferKiloBytesSize(curSize), UTL.String.TransferKiloBytesSize(maxSize), UTL.String.TransferKiloBytesSize(speed)) self.targetProgress = curSize / maxSize end end function UILoadingPanel:UpdateFastFollowProgress(progress, downloadSize, totalSize) self.ProgressLabel.text = string.FormatByIdsId(Const_IDS.IDS_AABDownload_Tips, UTL.String.TransferBytesSize(downloadSize), UTL.String.TransferBytesSize(totalSize)) self:UpdateProgress(progress) end --下载暂停,将下载速度置零 function UILoadingPanel:OnDownloadPause() local curSize = CTL.HotFix.GetLastDownloadSize() local maxSize = self.maxDownloadSize self.ProgressLabel.text = string.format(progressShow, UIUtils.GetLocalizedTxt(Const_IDS.IDS_LoginDownload), UTL.String.TransferKiloBytesSize(curSize), UTL.String.TransferKiloBytesSize(maxSize), UTL.String.TransferKiloBytesSize(0)) end function UILoadingPanel:SetDownloadBtn(isShow) UIUtils.SetActive(self.btn_Download, isShow) end function UILoadingPanel:UpdateProgress(value) self.progressBar.value = value curProgress = self.progressBar.value local percent = math.floor(value*100) self.PercentLabel.text = string.format("%u%%",percent) end function UILoadingPanel:OnClosed() self:UpdateProgress(1) if self.bgPath and self.bgTex then TK2API.ReturnAsset(self.bgPath, self.bgTex); self.bgTex = nil self.LoadingTex.texture = nil end end function UILoadingPanel:SetVN18LogoConfig() --越南版本开启 其他版本默认关闭 if not UNITY_EDITOR and GameAppInfo.IsVietnamPackage() then UIUtils.SetLocalizationImage(self.icon_VN_AgeLimit18, "icon_VN_AgeLimit18.png") UIUtils.SetActive(self.icon_VN_AgeLimit18, GameAppInfo.IsShowVietnam18Logo()) end end return UILoadingPanel