我目前正在尝试将我正在开发的游戏从XNA移植到Monogame,但是在使内容管道合作方面遇到一些麻烦。我的游戏使用许多XML文件作为XNB Assets 来表示游戏中的对象,这些对象是按照here指令创建的。但是,尝试将每个单词逐个移动到Monogame中会产生以下错误:
这是我用来定义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中工作吗?我一直在互联网上逛了一会儿,但是到目前为止,我还没有找到解决我问题的方法。另外,如果我一直都在处理整个系统的错误,并且有一种更轻松的方法来处理我想做的事情,那么我很想听听。提前致谢!
最佳答案
我写了一篇相当长的tutorial关于使用MonoGame Pipeline加载自定义内容。这是摘要
创建导入器,处理器,读取器和写入器与XNA相同。您可以引用MSDN documentation。
棘手的部分是使您的DLL与管道工具一起使用。要将其添加为引用,请查找根树节点的引用属性。