我正在使用统一引擎开发一个多语言游戏,我有为每种语言编写的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);
}
}
答案 0 :(得分:0)
将读写目录更改为
Application.streamingAssetsPath
在资产中添加新文件夹 并将其命名为 StreamingAssets StreamingAssets下的每个文件都可以在所有平台上进行修改,读取和写入