KLUILoadingPanelPanel.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ---@class KLUILoadingPanelPanel:UIKmlLuaPanelBase
  2. ---@field view KLUILoadingPanelPanelView
  3. local KLUILoadingPanelPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUILoadingPanelPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.Coroutine = nil
  10. end
  11. ---注册UI事件和服务器消息
  12. function this:RegistEvents()
  13. end
  14. ---界面显示时调用一次
  15. function this:Show()
  16. self.ProgressType = ProgressType.NormalProgress
  17. if self.args and self.args.ProgressType then
  18. self.ProgressType = self.args.ProgressType
  19. if self.args.texure2DPath then
  20. local texure2DPath = string.format('Texture/%s.jpg', self.args.texure2DPath)
  21. GUI:Image_loadTexture(self.view.RawImage_Background, texure2DPath)
  22. end
  23. end
  24. self.loadTracker = SL:CtorResourceLoadTracker()
  25. self.progress = 0
  26. self:RegistEvents()
  27. self:Refresh()
  28. self:Update()
  29. end
  30. ---创建或者刷新界面数据时调用
  31. function this:Refresh()
  32. if self.ProgressType == ProgressType.NoProcess then
  33. GUI:Image_setFillAmount(self.view.Image_Progress, 1)
  34. GUI:Text_setString(self.view.Text_Message, '')
  35. else
  36. GUI:Image_setFillAmount(self.view.Image_Progress, self.progress)
  37. local progressInt = Mathf.Round(self.progress * 100)
  38. if self.progressInt ~= progressInt then
  39. self.progressInt = progressInt
  40. local str = ""
  41. if self.ProgressType == ProgressType.DownProgress then
  42. str = string.format("%s/%s", progressInt, "100MB")
  43. elseif self.ProgressType == ProgressType.NormalProgress or self.ProgressType == ProgressType.TryEnterMapMessage then
  44. str = string.format("正在加载场景 %d%%", progressInt)
  45. end
  46. GUI:Text_setString(self.view.Text_Message, str)
  47. end
  48. end
  49. ---@type UnityEngine.RectTransform
  50. local rect= GUI:GetRectTransform(self.view.root)
  51. SL:ScheduleOnce(0.05,function (rect)
  52. rect:SetAnchoredPosition(0,0)
  53. end,rect)
  54. end
  55. function this:Update()
  56. self:StopUpdate()
  57. self.Coroutine = SL:StartLoopForever(0.05,
  58. function()
  59. self:UpdateProgress()
  60. end)
  61. end
  62. function this:StopUpdate()
  63. if self.Coroutine then
  64. SL:UnSchedule(self.Coroutine)
  65. self.Coroutine = nil
  66. end
  67. end
  68. function this:OnHide()
  69. self:StopUpdate()
  70. end
  71. function this:Close()
  72. self.loadTracker:Dispose()
  73. SL:onLUAEvent(LUA_EVENT_LOADING_PANEL_HIDE, self.ProgressType)
  74. self:StopUpdate()
  75. end
  76. local DAMPING = 3
  77. function this:SetProgress(progress)
  78. local t = math.min(Time.deltaTime * DAMPING, 0.1)
  79. if self.progress < progress then
  80. self.progress = Mathf.Lerp(self.progress, progress, t)
  81. end
  82. if self.progress > 0.999 then
  83. GUI:UIPanel_Close("dev/ui/LoadingPanel/Panel/KLUILoadingPanel/KLUILoadingPanelPanel")
  84. if SL:GetIsXtra() then
  85. SL.SceneEditorManager:SetProgressState(self.ProgressType)
  86. end
  87. else
  88. self:Refresh()
  89. end
  90. end
  91. function this:UpdateProgress()
  92. local count = 0
  93. local progress = 1
  94. local totalProgress = 1
  95. if self.ProgressType == ProgressType.DownProgress then
  96. totalProgress = 1
  97. count = 1
  98. progress = count == 0 and 1 or totalProgress / count
  99. elseif self.ProgressType == ProgressType.NormalProgress then
  100. totalProgress = self.loadTracker.totalProgress
  101. count = self.loadTracker.count + SL:GetMetaValue("CS_STREAMING_SCENE_OBJ_SHOW_COUNT")
  102. progress = count == 0 and 1 or totalProgress / count
  103. end
  104. if self.ProgressType ~= ProgressType.NoProcess then
  105. self:SetProgress(progress)
  106. end
  107. end
  108. return this