Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在XNA框架的XML中包含Vector2列表作为属性_C#_Xml_Arrays_Xna - Fatal编程技术网

C# 如何在XNA框架的XML中包含Vector2列表作为属性

C# 如何在XNA框架的XML中包含Vector2列表作为属性,c#,xml,arrays,xna,C#,Xml,Arrays,Xna,我有一个类,我想用它将数据导入到我用XNA创建的游戏中。它的基础是,我环顾四周,尝试了一些方法,但我无法正确编译: <?xml version="1.0" encoding="utf-8" ?> <XnaContent> <Asset Type="MyGameData.LevelXMLData"> <LevelID>1</LevelID> <Path> <Item>1379 541</I

我有一个类,我想用它将数据导入到我用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标记中使用了这些标记,但是每当我试图编译代码时,就会出现以下错误

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);
    }

您没有显示反序列化代码。我只是使用内容管道加载XML文件。-编辑原始帖子好吧,我终于发现了我的问题。我只需要从向量2[]和矩形[]中的每个元素中删除。
    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);
    }
public struct LevelXMLData
{
    [ContentSerializer]
    public int LevelID;
    [ContentSerializer]
    public Vector2[] Path; 
    [ContentSerializer]
    public string[] WaveIDs;
    [ContentSerializer]
    public int WaveInterval;
    [ContentSerializer]
    public Rectangle[] TowerBuildSpots;
}