Commit 0d95aa07 authored by rockyl's avatar rockyl

修复素材预加载分组

parent 93c3357a
......@@ -111,18 +111,24 @@ export class GameStage extends Node {
*/
async launch(config, onPreloadAssetsProgress?, onPreloadAssetsComplete?, onStart?) {
this._config = config;
const {assets, customs} = config;
let loaded = 0;
let assetsToLoad = assets;
if (!Array.isArray(assets)) { //如果是分组后的配置就加载共用分组,否则加载全部
assetsToLoad = assets['common'];
const {options: {env}, dataMapping, processes, builtinProcesses, customs} = this._config;
Stage.addUpdateObj(Tween);
injectEnv(env);
//registerScripts(scripts);
//registerCustomModuleFromConfig(customs);
registerCustomModules(customs);
if (dataMapping) {
this.dataCenter.registerDataMapping(dataMapping);
}
let total = assetsToLoad.length;
setProcessMetaLibs(processes, builtinProcesses);
await loadAssets(assetsToLoad, p).catch(e => {
console.log(e);
});
await this.loadPreloadAssets(onPreloadAssetsProgress, onPreloadAssetsComplete);
this.start();
......@@ -133,36 +139,14 @@ export class GameStage extends Node {
setTimeout(this.lazyLoadAllAssets,
this._config.options.lazyLoadWait || 1000);
function p() {
loaded++;
onPreloadAssetsProgress && onPreloadAssetsProgress(loaded, total);
if (loaded >= total) {
onPreloadAssetsComplete && onPreloadAssetsComplete();
}
}
}
/**
* 开始游戏
*/
start() {
const {options: {entrySceneView, env}, dataMapping, processes, builtinProcesses, scripts, customs} = this._config;
const {options: {entrySceneView, }, } = this._config;
Stage.addUpdateObj(Tween);
injectEnv(env);
//registerScripts(scripts);
//registerCustomModuleFromConfig(customs);
registerCustomModules(customs);
if (dataMapping) {
this.dataCenter.registerDataMapping(dataMapping);
}
setProcessMetaLibs(processes, builtinProcesses);
setTimeout(async () => {
let sceneEntry = await this.instantiateView(entrySceneView);
......@@ -331,5 +315,41 @@ export class GameStage extends Node {
await loadAssetsGroup(group, custom.id);
}
}
};
async loadPreloadAssets(onPreloadAssetsProgress, onPreloadAssetsComplete){
const {assets, } = this._config;
let loaded = 0;
let assetsToLoad = assets;
let total;
if (!Array.isArray(assets)) { //如果是分组后的配置就加载共用分组,否则加载全部
assetsToLoad = assets['common'];
if(assetsToLoad.length > 0){
await this.showInnerLoadingView();
await loadAssetsGroups({
preload: assetsToLoad,
}, async () => {
}, async () => {
this.hideInnerLoadingView();
});
}
}else{
total = assetsToLoad.length;
await loadAssets(assetsToLoad, p).catch(e => {
console.log(e);
});
}
function p() {
loaded++;
onPreloadAssetsProgress && onPreloadAssetsProgress(loaded, total);
if (loaded >= total) {
onPreloadAssetsComplete && onPreloadAssetsComplete();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment