1

我有一个类,我想用它来将数据导入到我用 XNA 创建的游戏中。它的基础是,我环顾四周并尝试了一些东西,但我无法正确编译:

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="MyGameData.LevelXMLData">
  <LevelID>1</LevelID>
  <Path>
    <Item>1379 541</Item>
    <Item>1370 445</Item>
    <Item>1340 348</Item>
    <Item>1294 253</Item>
    <Item>1217 148</Item>
    <Item>1139 106</Item>
    <Item>1077 148</Item>
    <Item>1046 201</Item>
    <Item>1004 479</Item>
    <Item>999 633</Item>
    <Item>961 816</Item>
    <Item>917 918</Item>
    <Item>850 964</Item>
    <Item>824 939</Item>
    <Item>770 837</Item>
    <Item>738 673</Item>
    <Item>725 526</Item>
    <Item>549 520</Item>
  </Path>
  <WaveIDs>
    <Item>Wave1</Item>
    <Item>Wave2</Item>
    <Item>Wave3</Item>
  </WaveIDs>
  <WaveInterval>120000</WaveInterval>
  <TowerBuildSpots>
    <Item>1277 417 50 50</Item>
    <Item>1094 232 50 50</Item>
    <Item>956 207 50 50</Item>
    <Item>931 326 50 50</Item>
    <Item>1069 442 50 50</Item>
    <Item>906 566 50 50</Item>
    <Item>1056 589 50 50</Item>
    <Item>1031 722 50 50</Item>
    <Item>981 867 50 50</Item>
    <Item>824 854 50 50</Item>
    <Item>641 747 50 50</Item>
    <Item>774 639 50 50</Item>
    <Item>641 566 50 50</Item>
    <Item>691 442 50 50</Item>
  </TowerBuildSpots>
  </Asset>
</XnaContent>

“Path”是一个 Vector2s 数组,“TowerBuildSpots”是一个 Rectangles 数组

Public Vector2[] Path;
Public Rectangle[] TowerBuildSpots;

我遵循了我在集合中看到的其他人的代码示例,并在我的 Path 标签中使用了标签,但是每当我尝试编译我的代码时,我都会收到以下错误

Error   1   There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 6, position 6.

此行是文件中的第一行。

任何人都可以请添加任何对此问题的见解吗?这会有很大帮助。谢谢!

阿拉斯代尔

编辑:我的反序列化代码在这里:

    public static LevelInfo Load(LevelXMLData data, ContentManager content)
    {
        int levelID = data.LevelID;

        string levelLocation = "Levels\\Level" + levelID + "\\";

        Waypoint[] path = new Waypoint[data.Path.Count()];
        WaveOfEnemies[] waves = new WaveOfEnemies[data.WaveIDs.Count()];

        TextureManager[] images = LevelImageInfo.Load(content.Load<LevelImageXMLData[]>(levelLocation + "ImageData"), content);

        // load waypoints
        for (int i = 0; i <= data.Path.Count() - 1; i++)
        {
            path[i] = new Waypoint(data.Path[i]);
        }

        for (int i = 0; i <= data.WaveIDs.Count() - 1; i++)
        {
            waves[i] = LoadWave(content.Load<WaveXMLData>(levelLocation + "Waves\\" + data.WaveIDs[i]));
        }

        return new LevelInfo(levelID, images, path, waves, data.WaveInterval, data.TowerBuildSpots);
    }

我的 LevelXMLData 结构在这里:

public struct LevelXMLData
{
    [ContentSerializer]
    public int LevelID;
    [ContentSerializer]
    public Vector2[] Path; 
    [ContentSerializer]
    public string[] WaveIDs;
    [ContentSerializer]
    public int WaveInterval;
    [ContentSerializer]
    public Rectangle[] TowerBuildSpots;
}
4

0 回答 0