XNA:将对象序列化到隔离存储
我有一门课程来定义我的水平。我的内容项目中有一个 XML 文件,用于存储关卡的详细信息。
我可以使用 LoadContent() 从内容项目加载 XML 文件的详细信息。这将创建一个包含 XML 文件中所有详细信息的对象。
现在,我想将该游戏关卡保存到独立存储中。
我见过的所有示例都表明我需要使用 XMLWriter 和 XMLSerializer。这是为什么?我可以不使用 XNA 框架从内容管道加载的机制吗?
I have a class that defines my level. I have an XML file in my Content Project that stores the details of the level.
I can load the details of the XML file from the Content Project with LoadContent(). This creates an object with all the details from the XML file.
Now, I want to save that game level into isolated storage.
All the examples that I've seen, indicate that I need to use XMLWriter and XMLSerializer. Why is that? Can I not use the mechanism that the XNA framework uses to load from the Content Pipeline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要 XMLWriter 或 XMLSerializer,但确实需要序列化程序。
下面是我的通用隔离存储实用程序的示例。
当您将 XML 引用为 XNA 内容时,它会通过 ContentPipeline 进行编译。因此,当您加载内容时,您是通过 ContentManager 来完成的。引用的此 XML 文件不应该位于 ContentPipeline 中,因为这样就无法对其进行修改。您应该保留通过 ContentPipline 引用的静态文件,并将所有动态文件保存在isolatedStorage 中。文件一旦编译就无法更改,这就是它无法保存到 ContentPipeline 的原因。
You don't need an XMLWriter or XMLSerializer, but you do need a serializer.
Below is an example of a my Generic IsolatedStorage Utilty
When YOU reference the XML as an XNA content it is compiled throught the ContentPipeline. So when you load the Content you do it through the ContentManager. This XML file referenced should NOT be in the ContentPipeline because then it cannot be modified. You should leave Static files referenced through the ContentPipline and leave all Dynamic files saved in IsolatedStorage. Once files are comiled they cannot be changed thats why it cant be saved to the ContentPipeline.