Unity Android xml reading

Unity Android xml reading

Using TextAsset

About TextAsset
.text: What is stored in it is text.bytes
: What is stored in it is binary text.
Both properties are read-only

        TextAsset textAsset = (TextAsset)Resources.Load("xml文件名称但不包含拓展名" + StageNum, typeof(TextAsset));

        //load xml document
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(textAsset.text);

Not only xml, but also txt, json, html and other formats are supported.

Read XML on PC

Define a file path (filePath) of type String and use ==File.Exists(filePath)== to test whether the file exists.

It is strongly recommended to output error information when reading errors, which will help you troubleshoot.

        string filePath = Application.dataPath + "/(你的路径名)" + "/(你的文件名)";

		XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(filePath);

        if (File.Exists(filePath))
        {
    
    
           //doSomething
        }
        else
        {
    
    
            Debug.Log("读取错误!请检查文件是否存在,或者配置信息是否正确!");
        }

Guess you like

Origin blog.csdn.net/weixin_44293055/article/details/109332721
Recommended