- Creator 版本:2.4.1
如题 cc.assetManager.loadBundle 查询相关api只有bundle对象的load\preload\loadDir等方法有onProgress回调,cc.assetManager.loadBundle这个没查到加载进度的回调
如题 cc.assetManager.loadBundle 查询相关api只有bundle对象的load\preload\loadDir等方法有onProgress回调,cc.assetManager.loadBundle这个没查到加载进度的回调
同问
loadBundle 好像是只加载了一个config.json文件, 并不是把包的所有都加载好。
一般很快完成,用不用进度无所谓。 主要还是在bundle.load加载具体资源的时候可能是耗时操作。
但是当这个bundle是一个zip类型时,它就会去下载并解压整个bundle,这个就很慢了
cc.assetManager.loadBundle(loadUrl, {
onFileProgress: function (e) {
if (progressCallback) {
progressCallback(Math.floor(e.progress));
}
}
}, function (err) {
if (err) {
} else {
}
});
preload(bundle: cc.AssetManager.Bundle) {
if (!CC_JSB) return;
return new Promise<void>((resolve, reject) => {
let resMap = bundle.getDirWithPath('/');
let resPathes: string[] = resMap.filter(res => res.ctor != cc._TypeScript).map(res => res.path);
resPathes = utilsTool.uniqueArray(resPathes);
resPathes = resPathes.filter(res => { //判断是否已经缓存
let uuid: string = bundle.getInfoWithPath(res)['uuid'];
let nativeUrl = cc.assetManager.utils.getUrlWithUuid(uuid);
return cc.assetManager.cacheManager.getCache(nativeUrl) == '';
});
if (resPathes.length <= 0) {
resolve();
return;
};
//存在更新 则更新
this.finished = 0;
this.total = resPathes.length;
resPathes.forEach(path => {
((path) => {
bundle.preload(path, (err, items) => {
this.finished++;
if (this.finished >= this.total) {
resolve();
}
});
})(path);
});
});
}
cc.assetManager.loadBundle好像只会下载一个资源配置文件,其他资源都是调用bundle.load的时候才会下载的,但是有一个preload函数可以提前下载,下载过的文件会放在 cc.assetManager.cacheManager 里面 用getCahce判断是否已经缓存,未缓存的就preload。就可以实现提前下载所有资源。
您好, 我现在需要对asset bundle做预下载相关工作 , 在调研 使用 bundle的config.json配置来preload下载资源 和 构建的时候生成一份资源列表直接使用jsb.AssetsManager来下载资源, 您可以给我一些建议吗 ?
我目前的做法是只生成一个 bundle的版本信息文件,其他的工作全都交给引擎。
感谢回复,引擎提供的能力暂时确实是满足需求的,也是觉得把预下载包括热更新可以交给引擎。
交给引擎是啥意思