mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 19:42:39 +08:00
Merge pull request #865 from jareguo/v1.1
preload scene in runtime platform
This commit is contained in:
@@ -10,3 +10,4 @@ node_modules
|
||||
/package
|
||||
/tools/jsdoc_toolkit/jsdoc_toolkit-2.4.0
|
||||
/.project
|
||||
npm-debug.log
|
||||
|
||||
@@ -691,13 +691,13 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
for (var i = 0; i < scenes.length; i++) {
|
||||
var info = scenes[i];
|
||||
if (info.url.endsWith(key)) {
|
||||
return info.uuid;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof key === 'number') {
|
||||
if (0 <= key && key < scenes.length) {
|
||||
return scenes[key].uuid;
|
||||
return scenes[key];
|
||||
}
|
||||
else {
|
||||
cc.error('loadScene: The scene index to load (%s) is out of range.', key);
|
||||
@@ -723,11 +723,20 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
cc.error('loadScene: Failed to load scene "%s" because "%s" is already loading', sceneName, this._loadingScene);
|
||||
return false;
|
||||
}
|
||||
var uuid = this._getSceneUuid(sceneName);
|
||||
if (uuid) {
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
if (info) {
|
||||
var uuid = info.uuid;
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
this._loadingScene = sceneName;
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
if (CC_JSB && cc.runtime) {
|
||||
var self = this;
|
||||
cc.LoaderLayer.preload([cc.path.basename(info.url) + '_' + info.uuid], function () {
|
||||
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
});
|
||||
}
|
||||
else {
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@@ -752,10 +761,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
|
||||
* @param {Error} onLoaded.error - null or the error object.
|
||||
*/
|
||||
preloadScene: function (sceneName, onLoaded) {
|
||||
var uuid = this._getSceneUuid(sceneName);
|
||||
if (uuid) {
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
if (info) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
cc.loader.load({ id: uuid, type: 'uuid' }, function (error, asset) {
|
||||
cc.loader.load({ id: info.uuid, type: 'uuid' }, function (error, asset) {
|
||||
if (error) {
|
||||
cc.error('Failed to preload "%s", %s', sceneName, error.message);
|
||||
}
|
||||
|
||||
+17
-8
@@ -223,13 +223,13 @@ cc.js.mixin(cc.director, {
|
||||
for (var i = 0; i < scenes.length; i++) {
|
||||
var info = scenes[i];
|
||||
if (info.url.endsWith(key)) {
|
||||
return info.uuid;
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof key === 'number') {
|
||||
if (0 <= key && key < scenes.length) {
|
||||
return scenes[key].uuid;
|
||||
return scenes[key];
|
||||
}
|
||||
else {
|
||||
cc.error('loadScene: The scene index to load (%s) is out of range.', key);
|
||||
@@ -254,11 +254,20 @@ cc.js.mixin(cc.director, {
|
||||
cc.error('loadScene: Failed to load scene "%s" because "%s" is already loading', sceneName, this._loadingScene);
|
||||
return false;
|
||||
}
|
||||
var uuid = this._getSceneUuid(sceneName);
|
||||
if (uuid) {
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
if (info) {
|
||||
var uuid = info.uuid;
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
this._loadingScene = sceneName;
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
if (CC_JSB && cc.runtime) {
|
||||
var self = this;
|
||||
cc.LoaderLayer.preload([cc.path.basename(info.url) + '_' + info.uuid], function () {
|
||||
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
});
|
||||
}
|
||||
else {
|
||||
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
@@ -268,10 +277,10 @@ cc.js.mixin(cc.director, {
|
||||
},
|
||||
|
||||
preloadScene: function (sceneName, onLoaded) {
|
||||
var uuid = this._getSceneUuid(sceneName);
|
||||
if (uuid) {
|
||||
var info = this._getSceneUuid(sceneName);
|
||||
if (info) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
|
||||
cc.loader.load({ id: uuid, type: 'uuid' }, function (error, asset) {
|
||||
cc.loader.load({ id: info.uuid, type: 'uuid' }, function (error, asset) {
|
||||
if (error) {
|
||||
cc.error('Failed to preload "%s", %s', sceneName, error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user