读取配置文件的代码如下
string path = Application.dataPath + @"/Resources/config.xml";
if (File.Exists ( path )) {
XmlDocument doc = new XmlDocument ( );
lock (doc) {
doc.Load ( path );
}
XmlNodeList node = doc.SelectSingleNode ( "root" ).ChildNodes;
foreach (XmlNode x in node) {
//这儿写个switch去取x.Name判断子节点
XmlNodeList child = x.ChildNodes;
int count = 0;
foreach (XmlElement server in child) {
//当我们取到子节点的时候,子节点有属性就需要用XmlElement 去寻找
}
}
XML配置文件在Asset/Resourse目录下
<?xml version="1.0" encoding="UTF-8"?>
<root>
<version value="1.0.0"/>
<channel value="AAA"/>
<servers>
<server ip="127.0.0.1" port="8090"/>
<server ip="127.0.0.1" port="8102"/>
</servers>
<login lastlogin_account="" lastlogin_password="" autologin="1"/>
<accounts/>
<effect_volume value="50"/>
<bgmusic_volume value="50"/>
</root>