我目前正尝试移植一款我从XNA开始使用Monogame的游戏,但我在获得内容管道合作方面遇到了一些麻烦。我的游戏使用许多XML文件作为XNB资产来表示游戏中的对象,我按照here的说明创建了这些对象。然而,尝试这种跨字对字移动到Monogame产生以下错误:通过Monogame内容管道加载XML文件?
An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in MonoGame.Framework.dll
Additional information: Could not load Parts\Window.xnb asset as a non-content file!
这是我一直在使用来定义XML文件的内容类:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace FileTypes
{
public class PartFile
{
public struct State
{
public Rectangle[] frames;
public int[] collision;
}
public Vector2 size;
public string image;
public string defaultState = "default";
public bool fillBG;
public int ticksPerFrame;
public Dictionary<string, State> states;
public string[] modules;
}
}
下面是该项目的XML文件中的一个:
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="FileTypes.PartFile">
<size>2 3</size>
<image>Computer</image>
<defaultState>default</defaultState>
<fillBG>false</fillBG>
<ticksPerFrame>7</ticksPerFrame>
<states>
<Item>
<Key>default</Key>
<Value>
<frames>
0 0 40 60
40 0 40 60
</frames>
<collision>
0 0
0 0
0 0
</collision>
</Value>
</Item>
<Item>
<Key>active</Key>
<Value>
<frames>
80 0 40 60
120 0 40 60
</frames>
<collision>
0 0
0 0
0 0
</collision>
</Value>
</Item>
</states>
<modules>
<Item>testModule</Item>
</modules>
</Asset>
</XnaContent>
最后这里是代码的示例中,我用它来加载文件:
FileTypes.PartFile srcPart = content.Load<FileTypes.PartFile>("Parts\\" + name);
有人知道我需要做什么才能让我的代码在Monogame中工作吗?我一直在网上浏览一段时间,但到目前为止,我还没有找到解决我的问题的方法。另外,如果我一直在讨论整个系统的错误,并且处理我想要做的事情有一个更简单的方法,我很乐意听到它。
在此先感谢!
我已经做到了这一点,但它仍然无法正常工作。 –
oops,只是看看你发布的链接(我从来没有使用xml的内容管道数据),我怀疑你可以在monogame中做到这一点,因为它没有内容管道,所以它不能将xml转换为xnb文件,您最好在xna中构建文件,然后将xnb文件复制到您的monogame项目中,然后对其执行上述^操作 – Nico