From da5ec55c30d8cd6faecb89d2719d4eeb8a87e9f6 Mon Sep 17 00:00:00 2001 From: leo <907600065@qq.com> Date: Fri, 28 Dec 2018 17:06:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=83=AD=E6=9B=B4=E6=96=B0de?= =?UTF-8?q?mo=E4=B8=AD=EF=BC=8C=E8=BF=9B=E5=BA=A6=E5=87=BA=E9=94=99?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HotUpdateDemo/assets/Script/HotUpdate.js | 35 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/HotUpdateDemo/assets/Script/HotUpdate.js b/HotUpdateDemo/assets/Script/HotUpdate.js index c37c090..8a7b5f3 100644 --- a/HotUpdateDemo/assets/Script/HotUpdate.js +++ b/HotUpdateDemo/assets/Script/HotUpdate.js @@ -7,7 +7,8 @@ cc.Class({ properties: { manifestUrl: cc.RawAsset, - _hotUpdateName: 'game-remote-asset' + _hotUpdateName: 'game-remote-asset', + _nowVersion: '' }, /** @@ -18,15 +19,19 @@ cc.Class({ this.nextFn = nextFn; this.progressFn = progressFn; this.failedFn = failedFn; - if ((cc.sys.os != cc.sys.OS_ANDROID) || (cc.sys.os != cc.sys.OS_IOS)) { + // this.loadManifest(); + // console.log('os=', cc.sys.os); + if (cc.sys.isBrowser) { console.log('is not OS_ANDROID or OS_IOS'); - nextFn(); + this.nextFn && nextFn(this._nowVersion); return; } + let self = this; this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + this._hotUpdateName); cc.log('Storage path for remote asset : ' + this._storagePath); this.versionCompareHandle = function (versionA, versionB) { console.log('versionLocal=' + versionA + ' versionRemote=' + versionB); + self._nowVersion = versionA; var vA = versionA.split('.'); var vB = versionB.split('.'); for (var i = 0; i < vA.length; ++i) { @@ -66,9 +71,27 @@ cc.Class({ this.checkUpdate(); }, + /** + * 用于当检查热更新回调过慢时 + */ + clearAllCallFunc() { + console.log('清除回调'); + this.nextFn = null; + this.progressFn = null; + this.failedFn = null; + }, + + loadManifest() { + // console.log('this.manifestUrl=', this.manifestUrl); + // 手动设置路径 + this.manifestUrl = 'res/raw-assets/project.manifest'; + }, + //热更新完成 or 不需要热更新 进入游戏 onEnterGame: function () { - this.nextFn(); + console.log('热更新完成,', this._nowVersion); + this.nextFn && this.nextFn(this._nowVersion); + }, /** @@ -234,4 +257,8 @@ cc.Class({ }, // update (dt) {}, + + onDestroy() { + this.clearAllCallFunc(); + } }); \ No newline at end of file