怎么把远程的bundle下载下来存储在本地 不用每次重启都去从远程加载 能贴代码最好
bundle设置里勾上远程包,每次都生成一个唯一版本号的
你理解错了 我是说远程bundle包下载下来以后 怎么存在本地啊
用cc.assetManager.loadBundle()方法下载下来的只在缓存里 重启APP就没了
md5缓存勾一下
这个和MD5缓存有什么关系 我是原生平台 没懂
重启不会没
重启后我用这个API let bundle = cc.assetManager.getBundle(‘fill’); 获取不了 不重启就行
需要先loadBundle进内存
嗯 就是想问怎么存在内存里 是要用原生存文件的那些API吗
cc.assetManager.loadBundle
可能是我没表达清楚 我用 cc.assetManager.loadBundle 加载远程的bundle已经加载进来了 let bundle = cc.assetManager.getBundle(‘xunlu’); 也能获取到 然后重启APP 第二次 let bundle = cc.assetManager.getBundle(‘xunlu’) 获取不了 又要重新加载一次 难道是我用模拟器测试的原因
本地缓存目录里面有文件的,你需要先加载loadBundle到缓存里面才能getBundle得到
不管本地有没有,都要loadBundle 才能使用,区别是本地没有的时候,会从远端下载
楼主理解的内存就是磁盘,我见过很多内存和磁盘分不清的人。
本地有缓存也要loadbundle从本地缓存加载到内存吧,
将远程资源下载到本地文件夹,后续都从本地文件夹获取
试试看行不行:
/**
* @description: 下载文件到本地
* @param {string} url 请求URl
* @param {string} savePath 保存 url
* @param {function} callback 下载回调
*/
//正在下载的
private downloadingList = {};
public downloadFile(url: string, savePath: string, callback: (result: boolean, data: any) => void) {
if (sys.isNative && sys.os == sys.OS.ANDROID) {
if (this.downloadingList[url]) {
this.downloadingList[url].push(callback);
return;
}
if (!this.isValidMD5FileName(url)) {
Logger.log("_fileCacher,downloadFile url不合法", url)
callback(false, null);
return;
}
this.downloadingList[url] = [callback];
const downloader: native.Downloader = new native.Downloader();
downloader.onSuccess = (task: native.DownloadTask) => {
for (let cb of this.downloadingList[url]) {
cb(true, savePath)
}
delete this.downloadingList[url];
}
Logger.log("_fileCacher,downloadFile url", url);
downloader.onError = (task: native.DownloadTask, errorCode: number, errorCodeInternal: number, errorStr: string) => {
Logger.log("_fileCacher,download fail", errorCode, errorCodeInternal, errorStr)
for (let cb of this.downloadingList[url]) {
cb(false, url)
}
delete this.downloadingList[url];
}
//创建下载任务
downloader.createDownloadTask(url, savePath, "imageDownloadTask");
}
}
那后面加载本地的文件 用loadBundle参数该如何填 我直接填bundle名报错了
那后面加载本地的文件 用loadBundle参数该如何填 我直接填bundle名报错了
loadremote有缓存,url不变引擎不会请求网络。你后续load直接loadurl就行了。不需要你额外操作。逻辑都不用变,要更新就加上版本号