HotUpdateCtrl.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const SceneCtrlBase = require('SceneCtrlBase');
  2. // 热更新ctrl
  3. // 主要控制显示小资源更新还是大资源更新
  4. cc.Class({
  5. extends: SceneCtrlBase,
  6. editor: {
  7. menu: 'Launch/HotUpdateCtrl'
  8. },
  9. properties: {
  10. hotupdateProgressNode: cc.Node,
  11. updateCtrNode: cc.Node
  12. },
  13. start () {
  14. this._super();
  15. cc.game.on('e_launch_enter_scene', this._handleEnterScene, this);
  16. cc.game.on('e_mgr_launch_update_finished', this._handleUpdateFinished, this);
  17. cc.game.on('e_mgr_launch_update_failed', this._handleUpdateFailed, this);
  18. if (G.RemoteUpdateInfoMgr.isSmallHotUpdate) {
  19. if (G.HotUpdateMgr.isDownloadFinished()) {
  20. G.HotUpdateMgr.restartApp();
  21. } else if (G.HotUpdateMgr.isDownloadFailed()) {
  22. let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo || {};
  23. let newResForce = remoteUpdateInfo.newResForce;
  24. if (newResForce) {
  25. this.hotupdateProgressNode.active = false;
  26. cc.game.emit('e_launch_hot_update_show_alert');
  27. } else {
  28. this._loadScene('scene_login');
  29. }
  30. } else {
  31. this.hotupdateProgressNode.active = true;
  32. }
  33. } else if (G.RemoteUpdateInfoMgr.isBigHotUpdate) {
  34. this.hotupdateProgressNode.active = false;
  35. cc.game.emit('e_launch_hot_update_show_alert');
  36. } else {
  37. // 容错:不是热更新直接跳过
  38. G.LogUtils.error('热更新类型错误,跳过热更新');
  39. this._loadScene('scene_login');
  40. }
  41. },
  42. // 调整到下一个场景
  43. _loadScene (sceneName) {
  44. if (this._endScene) { // 避免重复跳转
  45. return;
  46. }
  47. this._endScene = true;
  48. G.AppUtils.loadScene(sceneName);
  49. },
  50. _handleEnterScene () {
  51. this._loadScene('scene_login');
  52. },
  53. // 热更新 更新完成
  54. _handleUpdateFinished () {
  55. let needRestart = G.HotUpdateMgr.needRestart;
  56. if (needRestart) {
  57. G.HotUpdateMgr.restartApp();
  58. }
  59. },
  60. // 热更新 更新失败
  61. _handleUpdateFailed () {
  62. let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo || {};
  63. let newResForce = remoteUpdateInfo.newResForce;
  64. if (newResForce) {
  65. this.hotupdateProgressNode.active = false;
  66. cc.game.emit('e_launch_hot_update_show_alert');
  67. } else {
  68. this._loadScene('scene_login');
  69. }
  70. }
  71. });