From a94c1499ccf83778d50ffc3c17d4d1b21b6ca06c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 22 Dec 2016 10:36:20 +0800 Subject: [PATCH 1/2] Fix getReferenceKey issue and fix loadResDir no result issue --- cocos2d/core/load-pipeline/CCLoader.js | 23 ++++++++++++++--------- cocos2d/core/platform/CCAssetLibrary.js | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index ce05aa4c6b..8d94adb818 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -194,9 +194,9 @@ JS.mixin(CCLoader.prototype, { } var self = this; - var singleRes = null; + var singleRes = false; if (!(resources instanceof Array)) { - singleRes = resources; + singleRes = true; resources = resources ? [resources] : []; } @@ -223,7 +223,7 @@ JS.mixin(CCLoader.prototype, { return; if (singleRes) { - var id = singleRes.url || singleRes.uuid || singleRes; + var id = res.url; completeCallback.call(self, items.getError(id), items.getContent(id)); } else { @@ -311,16 +311,20 @@ JS.mixin(CCLoader.prototype, { // Find the asset's reference id in loader, asset could be asset object, asset uuid or asset url _getReferenceKey: function (assetOrUrlOrUuid) { var key; - if (typeof assetOrUrlOrUuid === 'string') { - key = this._getResUuid(assetOrUrlOrUuid) || assetOrUrlOrUuid; - } - else if (typeof assetOrUrlOrUuid === 'object') { + if (typeof assetOrUrlOrUuid === 'object') { key = assetOrUrlOrUuid._uuid || null; } + else if (typeof assetOrUrlOrUuid === 'string') { + key = this._getResUuid(assetOrUrlOrUuid) || assetOrUrlOrUuid; + } else if (CC_DEV) { cc.warnID(4800, assetOrUrlOrUuid); } - key = cc.AssetLibrary._getAssetUrl(key) || key; + var isUuid = cc.AssetLibrary._getAssetUrl(key); + if (isUuid) { + cc.AssetLibrary._getAssetInfoInRuntime(key, _info); + key = _info.url; + } return key; }, @@ -453,7 +457,8 @@ JS.mixin(CCLoader.prototype, { var results = []; for (var i = 0; i < res.length; ++i) { var uuid = res[i].uuid; - var item = items.getContent(uuid); + var id = this._getReferenceKey(uuid); + var item = items.getContent(id); if (item) { // should not release these assets, even if they are static referenced in the scene. self.setAutoReleaseRecursively(uuid, false); diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index 8ae00291aa..a27c22e999 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -136,7 +136,7 @@ var AssetLibrary = { result.url = _rawAssetsBase + info.url; result.raw = true; } - else { + else if (uuid) { result.url = this.getImportedDir(uuid) + '/' + uuid + '.json'; } return result; From 2040a82eb1393cb7e75bc61e15744526c86c028f Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 22 Dec 2016 11:03:35 +0800 Subject: [PATCH 2/2] Revert changes to CCAssetLibrary --- cocos2d/core/platform/CCAssetLibrary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index a27c22e999..8ae00291aa 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -136,7 +136,7 @@ var AssetLibrary = { result.url = _rawAssetsBase + info.url; result.raw = true; } - else if (uuid) { + else { result.url = this.getImportedDir(uuid) + '/' + uuid + '.json'; } return result;