先使用assetManager.loadBundle 加载bundle
然后在loadBundle 的 onComplete 使用 bundle.load 加载具体的文件
assetManager.loadBundle(value.name, (err, bundle) => {
let func = (err: Error, data: any[]) => onComplete(err, data, config.paths,config.type)
bundle.load(config.paths, AudioClip, func)
});
在bundle.load的 onComplete 方法中有计数的逻辑, 当计数为 0 时表示所需要的资源加载完成,
const onComplete = (err:Error,acs:any[],type?:string)=> {
if (err) {
console.error(err.stack);
return;
}
resCount -= acs.length;
if (resCount === 0) {
console.info(**************** 初始资源记载完成: [${ this.totalCount}] ********************
,);
setTimeout(() => {
oops.sem.publish(EventEnum.initLoaded);
}, 2000);
}
}
然后会发布事件让各个组件使用AssetManager.Bundle .get同步获取所需要的资源, 但是获取资源有大概率不成功的情况,这是怎么回事呢?
assetManager.getBundle(bundleName).get(path, type).get(path, type)