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;
}