【Unity 系统知识】 各种路径

一.Assets下的Resources(Unity系统文件夹)

  :路径 Application.dataPath/Resources

可以使用Resources.Load("文件名字,注:不包括文件后缀名");把文件夹中的对象加载出来。

GameObject go = Resources.Load("xxxx") as GameObject

该文件夹在编辑器下可以增删操作,打包之后不可以。

 

二.Assets文件夹  

  :路径 Application.dataPath

该文件夹在编辑器下可以增删操作,打包之后不可以。

 

三.Assets下的StreamingAssets(Unity系统文件夹)

扫描二维码关注公众号,回复: 2957135 查看本文章

  :路径 Application.dataPath/StreamingAssets

  :路径 Application.streamingAssetsPath

  这个属性用于返回流数据的缓存目录,返回路径为相对路径,适合设置一些外部数据文件的路径。

这个文件夹中的资源在打包时会原封不动的打包进去,不会压缩,一般放置一些资源数据。

该文件夹在编辑器下可以增删操作,打包之后不可以。

 

四. 持久化数据存储目录 (推荐使用)

  :路径 Application.persistentDataPath

  这个路径可读、可写,但是只能在程序运行时才能读写操作,不能提前将数据放入这个路径。

在IOS上是应用程序的沙盒,可以被iCloud自动备份,可以通过同步推送一类的助手直接取出文件;

在Android上的位置是根据Project Setting里设置的Write Access路径,可以设置是程序沙盒还是sdcard,

注意:如果在Android设置保存在沙盒中,那么就必须root以后才能用电脑取出文件,因此建议写入sdcard里。

一般情况下,建议将获得的文件保存在这个路径下,例如可以从StreamingAsset中读取的二进制文件或者

从AssetBundle读取的文件写入PersistentDatapath。

 

以上各路径中的资源加载方式都可以用WWW类加载,但要注意各个平台路径需要加的访问名称,例如Android平台的路径前要加"jar:file://",其他平台使用"file://"。以下是各路径在各平台中的具体位置信息

Andorid平台
  Application.dataPath :  /data/app/xxx.xxx.xxx.apk
  Application.streamingAssetsPath :  jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
  Application.persistentDataPath :  /data/data/xxx.xxx.xxx/files
  Application.temporaryCachePath :  /data/data/xxx.xxx.xxx/cache
IOS平台
  Application.dataPath :                    Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data
  Application.streamingAssetsPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw
  Application.persistentDataPath :    Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
  Application.temporaryCachePath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches
 

 



猜你喜欢

转载自www.cnblogs.com/nanwei/p/9558317.html