1.android 平台下 StreamingAssets 文件夹是只读的 没有写入权限
2. android平台StreamingAssets 文件路径 注意前面"jar:file://"
#elif UNITY_ANDROID
path= "jar:file://" + Application.dataPath + "!/assets/;
#else
3.这个路径不是绝对路径所以不能用System.IO.File/Directory 来操作 ,比如File.Exist 会一直返回False 即使文件存在,同理 File.Read也不能使用
4.需要使用 WWW(Unity弃用)或者UnityWebRequest(Unity推荐) 来访问这个文件夹下的资源
5.WWW 返回 404 Not Found 问题 ,首先查看文件是否存在,再看路径前是否加了 “file://” ,然后要看后缀名,一定要区分大小写,区分大小写,因为这个坑浪费了 我两个小时,貌似只有在Android 平台需要区分后缀名大小写,其他平台不用。
6.建议使用Application.persistentDataPath 这个目录 ,这个目录是可读可写的,可以使用File/Directory来操作。
加载xml文件
利用Application.platform == RuntimePlatform.Android判断是否处于安卓环境,因为Pc端和安卓端的路径写法是不一样的
if (Application.platform == RuntimePlatform.Android)
{
//安卓端写法
filePath = Application.streamingAssetsPath + "/SpeakData/EnemySpeak.xml";
filePath2 = "file:///" + Application.persistentDataPath +"/SpeakData/EnemySpeak.xml";
}
else
{
//PC端写法
filePath="file://"+Application.streamingAssetsPath+"/SpeakData/EnemySpeak.xml";
filePath2 = "file:///" + Application.persistentDataPath +"/SpeakData/EnemySpeak.xml";
}
读取StreamAssets文件夹下xml文件
private IEnumerator LoadXmlData()
{