1.Resources 文件夹 少用
//资源卸载
/*
* Resources.UnloadAsset(obj):卸载非 GameObject类型的资源,会将内存中已加载资源及其克隆体卸载。
Destroy(obj):仅用于卸载GameObject类型的资源的克隆体。
DestroyImmediately(obj):卸载GameObject类型的资源,会将内存中已加载资源及其克隆体卸载,但该方法只能用在非编辑模式下,否则会报错提示改为DestroyImmediately(obj, true),然而编辑模式下使用该函数会连文件夹里的原始Asset一并删除。
*/
2:StreamingAssets 在移动端也是只可读的不能写入数据 主要用来存放二进制文件。
//安卓下这两个文件夹路径相同
//Application.streamingAssetsPath = jar:file:///data/app/com.xxx.xxx-1.apk!/assets/ == "jar:file://"+Application.dataPath+"!assets/"
//Application.dataPath+"!assets/" = /data/app/com.xxx.xxx-1.apk!assets/
//Ios下
//Application.dataPath + "/Raw/" == @"file:///" + Application.streamingAssetsPath + "/"
//Editor WIN
//@"file:///" + Application.streamingAssetsPath + "/"
//"file:///" + Application.dataPath + "/StreamingAssets" + "/"
private string path = string.Empty;
public string GetSAPath()
{
//安卓平台 加文件名
#if UNITY_ANDROID && !UNITY_EDITOR
path = Application.streamingAssetsPath + "/"
#elif UNITY_IPHONE && !UNITY_EDITOR
path = @"file:///" + Application.streamingAssetsPath + "/";
#elif UNITY_STANDLONE_WIN||UNITY_EDITOR
path = @"file:///" + Application.streamingAssetsPath + "/";
#endif
return path;
}
3:Application.persistentDataPath 这个目录可读可写 一般存本地关卡等
用于存档 直接使用 打包之前是没有这个目录的,直到应用程序在手机上安装完毕才有这个目录。
该文件存在手机沙盒中,因为不能直接存放文件,
1.通过服务器直接下载保存到该位置,也可以通过Md5码比对下载更新新的资源
2.没有服务器的,只有间接通过文件流的方式从本地读取并写入Application.persistentDataPath文件下,然后再通过 Application.persistentDataPath来读取操作。
注:在Pc/Mac电脑 以及Android跟Ipad、ipone都可对文件进行任意操作,另外在IOS上该目录下的东西可以被iCloud自动备份。 Application.persistentDataPath + "/tempDic", "testXml"
对应存储路径
Windows应用商店应用程序:application.persistentdatapath指向%userprofile%\appdata\local\packages\<productName>\localstate。
ios:application.persistentdatapath指向/var/mobile/containers/data/application/<guid>/documents。
android:application.persistentdatapath指向大多数设备上的/storage/emulated/0/android/data/<packagename>/文件(有些旧手机可能指向SD卡上的位置,如果存在),该路径使用android.content.context.getexternalfilesdir解析
4:Application.temporaryCachePath来操作文件 同上但是 此属性用于返回一个临时数据的缓存目录(不会备份并且清空缓存会清掉)
untiy 学习讨论群 184386599