简体   繁体   English

unity3d - android文件读取错误

[英]unity3d - android file reading error

I have a problem with reading files on aandroid after building apk file. 我在构建apk文件后在aandroid上读取文件时遇到问题。 When I try to read data form: 当我尝试读取数据表格时:

*jar:file:///data/app/ appname /base.apk!/assets/Levels/level0.xml,* * jar:file:/// data / app / appname /base.apk!/assets/Levels/level0.xml,*

game will crush with error message: URI scheme must start with a letter and must consist of one of alphabet, digits, '+', '-' or '.' 游戏将粉碎错误消息: URI方案必须以字母开头,并且必须包含字母,数字,'+',' - '或'。'之一。 character . 性格

Here is part of code that throws an exception: 以下是引发异常的代码的一部分:

void start()
{
        //some part of code
        level = Level.loadLevel(Path.Combine(Application.streamingAssetsPath , Path.Combine("Levels", "level0.xml")));
        //some part of code
}
public static Level loadLevel(string filePath)
{
        Level result = new Level();
        XmlDocument doc = new XmlDocument();
        doc.Load(filePath);
        //some part of code
}

Since files are contained inside a compressed .jar file, you have to use Unity WWW class to read them. 由于文件包含在压缩的.jar文件中,因此必须使用Unity WWW类来读取它们。 It should look like this: 它应该如下所示:

public IEnumerator loadLevel(string filePath)
{
    WWW www = new WWW(filePath);
    yield return www;
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(www.text);
    [...]
}

Hope this helps, 希望这可以帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM