1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- const JMLoadProgressBar = require('JMLoadProgressBar');
- // 热更新进度条
- cc.Class({
- editor: {
- menu: 'Launch/HotUpdateProgress'
- },
- extends: cc.Component,
- properties: {
- loadProgressBar: JMLoadProgressBar
- },
- onLoad () {
- this.status = JMC.UPDATE_STATUS.UNSTART;
- let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo || {};
- this.isForceUpdate = remoteUpdateInfo.newResForce;
- },
- onEnable () {
- cc.game.on('e_mgr_launch_update_progression', this._handleUpdateProgression, this);
- cc.game.on('e_mgr_launch_update_finished', this._handleUpdateFinished, this);
- cc.game.on('e_mgr_launch_update_failed', this._handleUpdateFailed, this);
- this.reloadView();
- },
- onDisable () {
- cc.game.targetOff(this);
- },
- // 刷新进度
- reloadView () {
- let status = G.HotUpdateMgr.status;
- if (this.status != status) {
- this.status = status;
- }
- if (status == JMC.UPDATE_STATUS.DOWNLOAD_FINISHED) {
- this._setProgress(1);
- } else if (status == JMC.UPDATE_STATUS.DOWNLOAD_FAILED) {
- this._setProgress(1);
- } else {
- let realTotalBytes = G.HotUpdateMgr.realTotalBytes;
- let downloadedBytes = G.HotUpdateMgr.downloadedBytes;
- let progress = downloadedBytes / realTotalBytes;
- this._setProgress(progress);
- }
- },
- // 进度
- _setProgress (progress) {
- this.loadProgressBar.setProgress(0.1, progress);
- },
- // 调整到下一个场景
- _loadScene (sceneName) {
- if (this._endScene) { // 避免重复跳转
- return;
- }
- this._endScene = true;
- G.AppUtils.loadScene(sceneName);
- },
- // 热更新 进度更新
- _handleUpdateProgression () {
- this.reloadView();
- },
- // 热更新 更新完成
- _handleUpdateFinished () {
- this.reloadView();
- },
- // 热更新 更新失败
- _handleUpdateFailed () {
- this.reloadView();
- }
- });
|