const SceneCtrlBase = require('SceneCtrlBase'); // 热更新ctrl // 主要控制显示小资源更新还是大资源更新 cc.Class({ extends: SceneCtrlBase, editor: { menu: 'Launch/HotUpdateCtrl' }, properties: { hotupdateProgressNode: cc.Node, updateCtrNode: cc.Node }, start () { this._super(); cc.game.on('e_launch_enter_scene', this._handleEnterScene, this); cc.game.on('e_mgr_launch_update_finished', this._handleUpdateFinished, this); cc.game.on('e_mgr_launch_update_failed', this._handleUpdateFailed, this); if (G.RemoteUpdateInfoMgr.isSmallHotUpdate) { if (G.HotUpdateMgr.isDownloadFinished()) { G.HotUpdateMgr.restartApp(); } else if (G.HotUpdateMgr.isDownloadFailed()) { let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo || {}; let newResForce = remoteUpdateInfo.newResForce; if (newResForce) { this.hotupdateProgressNode.active = false; cc.game.emit('e_launch_hot_update_show_alert'); } else { this._loadScene('scene_login'); } } else { this.hotupdateProgressNode.active = true; } } else if (G.RemoteUpdateInfoMgr.isBigHotUpdate) { this.hotupdateProgressNode.active = false; cc.game.emit('e_launch_hot_update_show_alert'); } else { // 容错:不是热更新直接跳过 G.LogUtils.error('热更新类型错误,跳过热更新'); this._loadScene('scene_login'); } }, // 调整到下一个场景 _loadScene (sceneName) { if (this._endScene) { // 避免重复跳转 return; } this._endScene = true; G.AppUtils.loadScene(sceneName); }, _handleEnterScene () { this._loadScene('scene_login'); }, // 热更新 更新完成 _handleUpdateFinished () { let needRestart = G.HotUpdateMgr.needRestart; if (needRestart) { G.HotUpdateMgr.restartApp(); } }, // 热更新 更新失败 _handleUpdateFailed () { let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo || {}; let newResForce = remoteUpdateInfo.newResForce; if (newResForce) { this.hotupdateProgressNode.active = false; cc.game.emit('e_launch_hot_update_show_alert'); } else { this._loadScene('scene_login'); } } });