Unity3D 移动平台Path对应路径以及文件路径权限

经常会用到一些路径读写文件,但是各个平台上一些路径对读写的支持有可能不同,下面给出不同平台unity提供的地址的具体路径,以及一些读写权限

1.Editor:

dataPathD:/Documents/Xuporter/Assets
persistentDataPathC:/Users/Administrator/AppData/LocalLow/mj/path
streamingAssetsPathD:/Documents/Xuporter/Assets/StreamingAssets
temporaryCachePathC:/Users/ADMINI~1/AppData/Local/Temp/mj/path

2.Android:

方法文件路径读写权限
dataPath/data/app/com.mi.path-1.apk无权限
persistentDataPath/data/data/com.mi.path/files读写,强推荐
streamingAssetsPathjar:file:///data/app/com.mi.path-1.apk!/assets只读
temporaryCachePath/data/data/com.mi.path/cache读写


我的包名是com.mi.path,可以看出android平台的路径和包名的关系,其实persistentDataPath和temporaryCachePath对应的路径就是sd卡或手机存储的Android/data/com.mi.path/files和Android/data/com.mi.path/cache路径

3.Iphone:

/var/mobile/Containers/Data/Application/FFEEF1E0-E15E-4BC0-9E8F-78084A2085A0/Documents

方法文件路径读写权限
dataPath/var/mobile/Containers/Bundle/Application/AFE239B4-2FE5-48B5-8A31-FC23FEDA0189/ad.app/Data 无权限
persistentDataPath/var/mobile/Containers/Data/Application/FFEEF1E0-E15E-4BC0-9E8F-78084A2085A0/Documents
读写,强推荐
streamingAssetsPath/var/mobile/Containers/Bundle/Application/AFE239B4-2FE5-48B5-8A31-FC23FEDA0189/ad.app/Data/Raw只读
temporaryCachePath/var/mobile/Containers/Data/Application/FFEEF1E0-E15E-4BC0-9E8F-78084A2085A0/Library/Caches读写


虽然temporaryCachePath目录下也能读写,但是建议只用于缓存临时文件用,因为在磁盘空间不足的情况下,ios会优先删除此处文件

官方描述:

  • Cached data should be stored in the <Application_Data>/Library/Caches directory. Examples of files you should put in the Caches directory include (but are not limited to) database cache files and downloadable content, such as that used by magazine, newspaper, and map apps. Your app should be able to gracefully handle situations where cached data is deleted by the system to free up disk space.

StreamingAssets在各个平台上的文本支持读取方式

string path = System.IO.Path.Combine(Application.streamingAssetsPath,"version.txt");

 c#WWW
Editor支持支持
Android不支持支持
Ios支持支持

Editor:

1::System.IO.File.ReadAllText (path);

2:path = "file://"+path;或者 path = "file:/"+path;或者 path = "file:\\"+path或者 path = "file:\\\\"+path;在win7上都可以 在mac上path = "file:/"+path不可以外,别的都可以

然后WWW www = new WWW (path);

Android:

1:WWW www = new WWW (path);

 iphone:

1:System.IO.File.ReadAllText (path);

2:path = "file://"+path;System.IO.File.ReadAllText (path);

还有一点就是在读取 streamingAssets目录下的文本文件时android平台必须要用www来读取哦,因为android平台是被压缩在apk中,所以不能直接用c#去读,ios可以直接用System.IO.File.ReadAllText(filePath)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值