什么是“建议”?如何将外部数据加载到 XNA4.0 游戏中?
我目前正在开发一款将提交给 XBLIG 的游戏。
我的问题很简单,我想知道哪种是通过外部 XML 文件加载数据的“建议”方法。
我至少需要这个来进行开发(在 PC 上),以便游戏设计师可以随意处理游戏变量而无需重建。
在xna3.1中我使用了IntermediateSerializer,它在xna4.0中不再存在。
我可能会创建一个用于运输的内容管道扩展,除非有人可以提出一个在 PC 和 Xbox 上都有效的惊人答案! :D
谢谢,
I am currently working on a game destined to be submitted to the XBLIG.
My question is quite simple, I was wondering which is the "advised" way to load data via an external XML file.
I need this at least for develpment (on PC) so that the Game Designer can faff about with the gameplay variables without needing to rebuild.
In xna3.1 I used the IntermediateSerializer which no longer exists for xna4.0.
I'm probably going to create a content pipeline extension for shipping, unless of course someone can propose an amazing answer that works on both PC and XBox! :D
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,首先,
IntermediateSerializer
确实 存在于 XNA 中4.0!但是,XNA 4.0 从针对 .NET 2.0 框架更改为针对 .NET 4.0 框架,它有两种风格。 XNA 运行时程序集以紧凑框架为目标,但内容管道程序集以完整框架为目标。您需要进入项目属性并更改目标框架以允许使用 IntermediateSerializer。
此外,内容管道在 Xbox 360 上不可用,并且如果没有已安装完整的 XNA Game Studio。这意味着在 Xbox 360 上运行时无法使用 InterpediateSerializer,或者在 Windows 上分发时无法使用 InterpediateSerializer(适用于 XNA 3.1 和 4.0)。
因此,如果您想在运行时、开发期间使用它,解决方案是将 Windows 上的开发的特定构建目标添加到您的项目中。为其提供一个用于
#ifdef DEVELOPMENT
的预处理器定义,以将代码包装在其中,将目标定位为(体积更大的)完整 .NET 4.0 Framework,并添加对Microsoft.Xna 的程序集引用。 Framework.Content.Pipeline
(其中IntermediateSerializer
所在)。(我将把确定条件框架目标和程序集引用作为您研究的内容 - 我很确定它需要手动编辑项目文件。或者您可以并行创建和维护一个新的项目文件。
)剩下的问题是在您的发行版本中做什么,您没有有
IntermediateSerializer
?这非常简单:您可以将 XML 文件拖到内容项目中。默认内容管道 XML 导入器获取您的 XML,通过 IntermediateSerializer 为您运行它,创建一个 XNB 文件。然后,您可以通过
ContentManager
在运行时将该文件加载为内容。 (另请参阅)(而不是粘一堆加载代码中的条件,我建议通常使用此方法(在加载时),然后仅使用
IntermediateSerializer
方法来“重新加载XML”代码路径。)Well, first of all,
IntermediateSerializer
does exist in XNA 4.0!However, XNA 4.0 changed from targeting the .NET 2.0 framework to targeting the .NET 4.0 framework, which comes in two flavours. The XNA runtime assemblies target the compact framework, but the Content Pipeline assemblies target the full framework. You will need to go into your project properties and change the target framework to allow you to use
IntermediateSerializer
.In addition, the Content Pipeline is not available on Xbox 360, and neither is it available on Windows without the full XNA Game Studio installed. Which means you can't use
InterpediateSerializer
when running on Xbox 360 or for distribution on Windows (applies to both XNA 3.1 and 4.0).So if you want to use it at runtime, during development, the solution is to add a specific build target for development on Windows to your project. Give it a pre-processor definition for
#ifdef DEVELOPMENT
to wrap your code in, make target the (much bulkier) full .NET 4.0 Framework, and add an assembly reference toMicrosoft.Xna.Framework.Content.Pipeline
(whereIntermediateSerializer
lives).(I will leave figuring out conditional framework targeting and assembly referencing as something for you to research - I'm pretty sure it requires hand-editing the project file. Or you could just create and maintain a new project file in parallel.)
So all that leaves is the question of what to do in your distribution versions, where you don't have
IntermediateSerializer
?That is extremely easy: You can drag your XML file into your content project. The default Content Pipeline XML importer takes your XML, runs it through
IntermediateSerializer
for you, creating anXNB
file. You can then load that file as content at runtime, via theContentManager
. (see also)(Rather than sticking a bunch of conditionals in your loading code, I recommend using this method normally (at load time), and then only using the
IntermediateSerializer
method for your "reload the XML" code path.)