我正在开发一款从XML文件中获取数据的Unity游戏。构建在Windows平台上运行良好,而当我尝试将其移植到Mac时,我收到以下错误。 XmlTextReader.Reader.Read()元素没有出现。(参见截图) 奇怪的是,它适用于Unity Editor for Mac,但不适用于Mac版本。
有没有办法让这个XmlTextReader在Mac上运行?或建议更好的替代方案?
Xml数据:
<?xml version="1.0" encoding="UTF-8"?>
<PickStructure>
<Picks>
<Pick id = "0" name = "name" weight = "6" strength = "9" defense = "7" display = "5" description = "description"> </Head>
<Pick id = "1" name = "name" weight = "7" strength = "8" defense = "7" display = "6" description = "description"> </Head>
<Pick id = "2" name = "name" weight = "2" strength = "2" defense = "2" display = "3" description = "description"> </Head>
<Pick id = "3" name = "name" weight = "6" strength = "3" defense = "7" display = "1" description = "description"> </Head>
<Pick id = "4" name = "name" weight = "3" strength = "5" defense = "3" display = "2" description = "description"> </Head>
<Pick id = "5" name = "name" weight = "6" strength = "4" defense = "7" display = "4" description = "description"> </Head>
<Pick id = "6" name = "name" weight = "2" strength = "4" defense = "7" display = "8" description = "description"> </Head>
</Picks>
</PickStructure>
PicksReader代码:
namespace PicksXML
{
public interface IPicks
{
float GetWeight();
float GetStrength();
float GetDisplay();
float GetDefense();
string GetDescription();
}
//[System.Serializable]
public class Picks : IPicks
{
[XmlAttribute("id")]
public uint _id;
[XmlAttribute("name")]
public string _name;
[XmlAttribute("weight")]
public int _weight;
[XmlAttribute("strength")]
public int _strength;
[XmlAttribute("display")]
public int _display;
[XmlAttribute("defense")]
public int _defense;
[XmlAttribute("description")]
public string _description;
public float GetWeight() { return _weight; }
public float GetStrength() { return _strength; }
public float GetDisplay() { return _display; }
public float GetDefense() { return _defense; }
public string GetDescription() { return _description; }
}
[XmlRoot("PickStructure")]
public class PicksReader
{
[XmlArray("Picks")]
[XmlArrayItem("Pick")]
public Picks[] _picks;
public void Save(string path)
{
var serializer = new XmlSerializer(typeof(PicksReader));
using(var stream = new FileStream(path, FileMode.Create))
{
serializer.Serialize(stream, this);
}
}
public static PicksReader Load(string path)
{
var serializer = new XmlSerializer(typeof(PicksReader));
using(var stream = new FileStream(path, FileMode.Open))
{
return serializer.Deserialize(stream) as PicksReader;
}
}
//Loads the xml directly from the given string. Useful in combination with www.text.
public static PicksReader LoadFromText(string text)
{
var serializer = new XmlSerializer(typeof(PicksReader));
return serializer.Deserialize(new StringReader(text)) as PicksReader;
}
}
}//namespace PicksXMl