gpt4 book ai didi

c# - 通过 Monogame 内容管道加载 XML 文件?

转载 作者:数据小太阳 更新时间:2023-10-29 01:57:18 39 4
gpt4 key购买 nike

我目前正在尝试将我正在开发的游戏从 XNA 移植到 Monogame,但我在让内容管道合作时遇到了一些麻烦。我的游戏使用许多 XML 文件作为 XNB Assets 来表示游戏中的对象,我按照说明创建了这些文件 here .但是,尝试将其逐字移动到 Monogame 中会产生以下错误:

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 中运行吗?我已经在互联网上搜索了一段时间,但到目前为止我还没有找到解决我的问题的方法。或者,如果我一直在处理整个系统的错误,并且有一种更简单的方法来处理我想做的事情,我很乐意听到它。

提前致谢!

最佳答案

我写了一个相当长的tutorial关于使用 MonoGame 管道加载自定义内容。这是总结

  1. 创建一个新项目来容纳您的内容导入器、处理器和编写器
  2. 创建内容导入器
  3. 创建内容处理器
  4. 创建内容类型编写器
  5. 创建内容类型阅读器
  6. 从管道工具引用 DLL
  7. 将内容读入您的游戏

创建导入器、处理器、读取器和写入器与 XNA 相同。可以引用MSDN documentation为此。

棘手的部分是让您的 DLL 与管道工具一起工作。要将其添加为引用,请查找根树节点的 References 属性。

关于c# - 通过 Monogame 内容管道加载 XML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21888888/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com