[游戏开发]Unity沙盒文件夹使用

沙盒文件夹路径有3个

  1.  Application.streamingAssetsPath
  2.  Application.persistentDataPath
  3.  Application.temporaryCachePath

streamingAssetsPath路径介绍

读写权限:只读。

特点:打包时会把StreamingAssets文件夹内的文件原封不动的打进包体里,安装包体启动程序后,可直接使用Application.streamingAssetsPath访问里面的文件。

注意事项:

安卓只能采用WWW的进行读取和判断是否存在。System.IO的方法全部失效,例如File.Exists无法判断文件是否存在,就算存在也返回false。

编辑模式和IOS模式可以用System.IO的方法,例如File.Exists,File.Copy、File.ReadAllLines读取文本文件

何时使用该文件夹:打版本包的时候,需要把AB包资源放到streamingAssetsPath中加载使用,或者把AB包从streamingAssetsPath拷贝到persistentDataPath中使用。

persistentDataPath 持久化数据文件夹

 读写权限:可读写

特点:安装包体后文件夹才创建,可直接使用Application.persistentDataPath访问里面的文件。

注意事项:

安卓也可使用System.IO的方法,所有平台都可以读写该文件夹,没有限制。和streamingAssetsPath有区别

什么样的数据放到persistentDataPath中?由于streamingAssetsPath没有写入权限,因此热更资源只能放到persistentDataPath内。热更资源和版本包资源配合判断是否需要热更。

temporaryCachePath   --临时数据的缓冲目录 (只读)  暂不关心,不使用

安卓打印沙盒路径

streamingAssetsPath:

jar:file:///data/app/包名-1/base.apk!/assets

persistentDataPath:

/storage/emulated/0/Android/data/包名/files

Iphone真机调试打印沙盒路径:

猜你喜欢

转载自blog.csdn.net/liuyongjie1992/article/details/133646620
今日推荐