Unity3d在Android环境下读取XML的注意事项
PC环境下读取一般可以直接用
url = "file://" + Application.streamingAssetsPath + "/hp.xml";//在Windows中实例化WWW必须要在路径前面加"file://"
WWW wWA = new WWW("file://" + url);
yield return wWA;
line1 = wWA.text;
Debug.Log(line1);
注意:必须要文件路径前面加上"file://"
Android环境下加载XML
1:安卓环境下不支持下面的用法
public static IEnumerator load()
{
string path = string.Empty;
string line1 = string.Empty;
if (Application.platform == RuntimePlatform.Android)
{
path = Application.streamingAssetsPath + "/Config.xml"; //在Android中实例化WWW不能在路径前面加"file://"
//path = "jar:file://" + Application.dataPath + "!/assets/"+Config.xml;//第二种写法:此时直接访问安卓环境下的文件夹地址。
WWW wWA = new WWW(path );///WWW读取在各个平台上都可使用
yield return wWA;
line1 = wWA.text;
Debug.Log(line1);
}
else
{
path = "file://" + Application.streamingAssetsPath + "/Config.xml";//在Windows中实例化WWW必须要在路径前面加"file://"
WWW wWA = new WWW("file://" + path );
yield return wWA;
line1 = wWA.text;
Debug.Log(line1);
}
yield return null;
}