LoadResBundle() {
console.log('加载res_bundle');
cc.assetManager.loadBundle('res_bundle', (err, bundle) => {
if (err != null) {
console.log(err.message);
return;
}
EventManagerInstance.GetInstance().Notify(window.GameMsgType.GameResLoadEnd, 1);
for (let i = 0; i < this.Paths.length; i++) {
bundle.load(this.Paths[i], this.AsssetsMain[i], function(err, assets) {
if (err != null) {
console.log(err.message);
return;
} else {
console.log("====assets===" + assets);
switch (i) {
case 0:
GameResInstance.instance.FruitAtlas = assets;
break;
case 1:
GameResInstance.instance.EffectsAtlas = assets;
break;
case 2:
GameResInstance.instance.FruitPrefab = assets;
break;
case 3:
GameResInstance.instance.JuicePrefab = assets;
break;
case 4:
GameResInstance.instance.ScorePrefab = assets;
break;
case 5:
GameResInstance.instance.FollowPrefab = assets;
break;
default:
break;
}
console.log('加载assets 成功');
}
});
}
for (let j = 0; j < this.DirPaths.length; j++) {
bundle.loadDir(this.DirPaths[j], cc.AudioClip, function(err, assets) {
if (err != null) {
console.log(err.message);
return;
} else {
GameResInstance.instance.ClipAssets = assets;
}
console.log('加载DirPaths 成功');
});
}
});
},
LoadUIBundle() {
console.log('加载ui_bundle');
cc.assetManager.loadBundle('ui_bundle', (err, bundle) => {
if (err != null) {
console.log(err.message);
return;
}
GameResInstance.instance.UIBundle = bundle;
console.log('加载ui_bundle 成功');
EventManagerInstance.GetInstance().Notify(window.GameMsgType.GameResLoadEnd, 1);
});
},
调用
//其他资源包加载
this.LoadResBundle();
//UI包加载
this.LoadUIBundle();
后在字节小游戏中输出为
加载res_bundle
加载ui_bundle
加载ui_bundle 成功
然后一直卡在这里res_bundle cc.assetManager.loadBundle的回调一直没有来
但是如果改成先cc.assetManager.loadBundle(‘res_bundle’,…) 等加载完成后再cc.assetManager.loadBundle(‘ui_bundle’,…)就没有问题。
另外以上代码在微信小游戏平台 和 编辑器上没有问题
-
Creator 版本:2.4.5
-
目标平台:字节小游戏
-
出现概率:必出现