[英]android apk not reading xml file (apk build from unity editor)
我正在使用unity引擎开发多语言游戏,我为每种语言编写了xml文件,但是android apk似乎无法读取xml文件,因为PC平台构建的语言适用于所有语言。
这是我的代码:
void Awake()
{
languagePath = Application.dataPath + "/Languages/";
CollectLanguages();
}
private void CollectLanguages()
{
try
{
DirectoryInfo langDir = new DirectoryInfo(languagePath);
FileInfo[] files = langDir.GetFiles("*.xml");
languageFiles = new string[files.Length];
int i = 0;
foreach (FileInfo fileGo in files)
{
languageFiles[i] = fileGo.FullName;
i++;
}
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
}
private string GetLanguageFile(string language)
{
foreach (string langGo in languageFiles)
{
if (langGo.EndsWith(language + ".xml"))
{
return langGo;
}
}
return string.Empty;
}
public void LoadLanguage(string language)
{
try
{
string filepath = Application.persistentDataPath + "/" + language+".xml";
if (Application.platform == RuntimePlatform.Android)
{
WWW path = new WWW("jar:file://" + Application.dataPath + "!/assets/"+"Languages/"+language+".xml");
while(!path.isDone)
{
Debug.Log("Loading File");
}
File.WriteAllBytes(filepath, path.bytes);
}
mainDoc = new XmlDocument();
StreamReader streamReader = new StreamReader (filepath);
mainDoc.Load(streamReader);
root = mainDoc.DocumentElement;
streamReader.Close();
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
}
将读写目录更改为
Application.streamingAssetsPath
在Assets中添加一个新文件夹并将其命名为StreamingAssets StreamingAssets下的每个文件都可以在所有平台上进行修改,读取和写入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.