HotUpdateProgress.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const JMLoadProgressBar = require('JMLoadProgressBar');
  2. // 热更新进度条
  3. cc.Class({
  4. editor: {
  5. menu: 'Launch/HotUpdateProgress'
  6. },
  7. extends: cc.Component,
  8. properties: {
  9. loadProgressBar: JMLoadProgressBar
  10. },
  11. onLoad () {
  12. this.status = JMC.UPDATE_STATUS.UNSTART;
  13. let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo || {};
  14. this.isForceUpdate = remoteUpdateInfo.newResForce;
  15. },
  16. onEnable () {
  17. cc.game.on('e_mgr_launch_update_progression', this._handleUpdateProgression, this);
  18. cc.game.on('e_mgr_launch_update_finished', this._handleUpdateFinished, this);
  19. cc.game.on('e_mgr_launch_update_failed', this._handleUpdateFailed, this);
  20. this.reloadView();
  21. },
  22. onDisable () {
  23. cc.game.targetOff(this);
  24. },
  25. // 刷新进度
  26. reloadView () {
  27. let status = G.HotUpdateMgr.status;
  28. if (this.status != status) {
  29. this.status = status;
  30. }
  31. if (status == JMC.UPDATE_STATUS.DOWNLOAD_FINISHED) {
  32. this._setProgress(1);
  33. } else if (status == JMC.UPDATE_STATUS.DOWNLOAD_FAILED) {
  34. this._setProgress(1);
  35. } else {
  36. let realTotalBytes = G.HotUpdateMgr.realTotalBytes;
  37. let downloadedBytes = G.HotUpdateMgr.downloadedBytes;
  38. let progress = downloadedBytes / realTotalBytes;
  39. this._setProgress(progress);
  40. }
  41. },
  42. // 进度
  43. _setProgress (progress) {
  44. this.loadProgressBar.setProgress(0.1, progress);
  45. },
  46. // 调整到下一个场景
  47. _loadScene (sceneName) {
  48. if (this._endScene) { // 避免重复跳转
  49. return;
  50. }
  51. this._endScene = true;
  52. G.AppUtils.loadScene(sceneName);
  53. },
  54. // 热更新 进度更新
  55. _handleUpdateProgression () {
  56. this.reloadView();
  57. },
  58. // 热更新 更新完成
  59. _handleUpdateFinished () {
  60. this.reloadView();
  61. },
  62. // 热更新 更新失败
  63. _handleUpdateFailed () {
  64. this.reloadView();
  65. }
  66. });