使用Application.persistentDataPath将Assetbundle缓存到本地
2017-08-07 09:21
309 查看
IEnumerator loadAndSaveAsset(string url) //下载网络模型并缓存到本地 { WWW w = new WWW(url); yield return w; if (w.isDone) { byte[] model = w.bytes; int length = model.Length; //文件流信息 //StreamWriter sw; Stream sw; FileInfo t = new FileInfo(Application.persistentDataPath + "//" + "Model.assetbundle"); if (!t.Exists) { //如果此文件不存在则创建 sw = t.Create(); } else { //如果此文件存在则打开 sw = t.OpenWrite(); } sw.Write(model, 0, length); //关闭流 sw.Close(); //销毁流 sw.Dispose(); } }
从本地读取模型文件:
//读取本地的模型文件 IEnumerator LoadModelFromLocal() { string s = null; #if UNITY_ANDROID s = "jar:file://" + Application.persistentDataPath + "/" + "Model.assetbundle"; #elif UNITY_IPHONE s = path+"/"+name; #elif UNITY_STANDALONE_WIN || UNITY_EDITOR s = "file://"+path+"/"+name; #endif WWW w = new WWW(s); yield return w; if (w.isDone) { Instantiate(w.assetBundle.mainAsset); } }
删除文件
void DeleteFile(string path, string name) { File.Delete(path + "//" + name); }
FR:海涛高软(hunk Xu)
相关文章推荐
- Unity3D研究院之手游开发中所有特殊的文件夹(assetbundle与Application.persistentDataPath)
- unity 安卓 如何读取 Application.persistentDataPath这个路径下面的assetbundle文件
- « AFNetworking 图片的本地缓存问题 Get application bundle seed ID in iOS » AFNetworking 使用总结 (用法+JSON解析)
- (转)Unity3D研究院之手游开发中所有特殊的文件夹(assetbundle与Application.persistentDataPath)
- Unity 如何删除本地指定的AssetBundle缓存?
- Application.persistentDataPath保存字符串到本地
- Unity 对Application.streamingAssetsPath和Application.persistentDataPath路径的理解
- 使用ngx_slowfs_cache模块构建本地缓存
- 你在使用assetbundle时可能遇到的坑【转】
- xutils 使用BitmapUtils进行图片本地缓存
- Unity 5:使用 Asset Bundle 和 Asset Bundle Manager (2)
- 关于使用SharedObject来缓存游戏图片或者swf文件资源到客户端本地的研究
- Application.persistentDataPath
- [unity3d]Assetbundle使用示例2(支持多平台)
- Unity3D-使用AssetBundle打包后Load资源时编辑器直接崩溃总结
- XListView的使用以及本地缓存
- 《Gradle实战》如何配置利用Maven本地仓库 由于从Maven转过来使用Gradle,所以想利用原来已经缓存好的Maven本地仓库。所以下面一起来配置一下Gradle仓库的请求。 Gradl
- 强制浏览器使用本地缓存(cache-control/expires),不要和服务器通信?
- [2]项目创建-使用C#.NET开发基于本地数据缓存的PC客户端
- Unity5 Assetbundle简单使用 及 打包Material文件超大的问题