Original Post
🔒 Locked
Two XNA content manager questions
Advertisement
The content pipeline is extensible, so you can use it for any file formats you like.
I don't think you can write to it outside of the compilation stage, at least not in a way that's portable (it's meant to be used on the Xbox as well, where you've got less freedom than on the PC). Depending on what you're actually trying to do, though, you can probably do it in other ways.
I don't think you can write to it outside of the compilation stage, at least not in a way that's portable (it's meant to be used on the Xbox as well, where you've got less freedom than on the PC). Depending on what you're actually trying to do, though, you can probably do it in other ways.
The ContentManager class itself only does one thing: it loads compiled .xnb files and converts them into their corresponding managed types. You can do some customization with regards to how these loaded objects are cached and disposed, but that's about it. You can't use it load arbitrary text, XML, or binary files.
Now the Content Pipeline in general can do all sorts of things. It has a class called IntermediateSerializer which is capable of serializing and deserializing objects to and from a special XML format. Fundamentally it's not too different from the XmlSerializer class that comes in the .NET framework. The main difference is that the Content Pipeline comes with a content importer that can use IntermediateSerializer to load files. So the end result is that you can have an instance of some Class, save it to XML with IntermediateSerializer, add the XML file to your Content project, and then your game can load the object with the ContentManager. The only catch is that IntermediateSerializer is only available for use if you have the full XNA Game Studio/Visual Studio install on the PC running the app...so this means that you could use it in a tool like a map editor but your game could not use it to directly save or load XML files. However your game can load the file if it's first compiled into a .xnb file by the Content project.
If you need to save to XML in your game, then the XmlSerializer is very usable. You can even use it to add XML files to your Content project...you just have to create a Content Importer that uses XmlSerializer to deserialize the XML file.
Now the Content Pipeline in general can do all sorts of things. It has a class called IntermediateSerializer which is capable of serializing and deserializing objects to and from a special XML format. Fundamentally it's not too different from the XmlSerializer class that comes in the .NET framework. The main difference is that the Content Pipeline comes with a content importer that can use IntermediateSerializer to load files. So the end result is that you can have an instance of some Class, save it to XML with IntermediateSerializer, add the XML file to your Content project, and then your game can load the object with the ContentManager. The only catch is that IntermediateSerializer is only available for use if you have the full XNA Game Studio/Visual Studio install on the PC running the app...so this means that you could use it in a tool like a map editor but your game could not use it to directly save or load XML files. However your game can load the file if it's first compiled into a .xnb file by the Content project.
If you need to save to XML in your game, then the XmlSerializer is very usable. You can even use it to add XML files to your Content project...you just have to create a Content Importer that uses XmlSerializer to deserialize the XML file.
Personally, the more I tried to figure out the content pipeline, the less it made sense. What really worked out was actually understanding how it's set up. Read this and a whole bunch of these and maybe this and see if that helps.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement