This will probably be the last post in this series, at least for now. In part one I looked at the basics on how to create my own custom writer/reader. If you're unfamiliar with the process, you might want read that to begin with. In the second part I showed how to load lists of classes by referring to other XML files. In the third part I showed how you can easily use this technique to load textures and other classes. In this fourth and final part, I'm going to show how you can make life a little easier for yourself when you are loading derived classes.
My last post talked about how to easily read XML files with lists of other classes in them. Now the neat thing about this is that you can very easily modify the code to read any kind of class, including textures and sounds. One of the things I find slightly annoying is that you can't just include a filename in your XML file and have the content pipeline pick up the texture or sound automatically. However, if you're already writing your own custom writer/reader pair, there's no reason why we can't include that functionality ourself.
In the last post of this series I showed how to write a simple content writer/reader pair. That basic example didn't give you any benefits compared to the automated way of doing it, however it was a simple introduction on how to write a content writer/reader pair. In this post I'm going to take a look at how to create XML files that reference other classes inside of them. This is an alternate way of doing it from my post back in August.
I did a post on automatic xnb serialization of classes within classes a while back. Now while the method works decently enough, I've realized it's probably not the best way of going about doing it. I'm now using a different method. It's a little bit trickier, as it involves using custom content writers and readers, but I think the overall result is neater code. There's a lot of stuff to cover here, so I'm going to try and split the content into four parts. This part will just be about how to setup a simple content writer/read pair, in case you're not familiar with how to do it.
I've uploaded another video of my Tower Defense prototype. I've managed to fix my audio drivers so it includes sound effects and music this time. Not a whole lot of visible changes since last time, since a lot of the stuff I've been working on has been underlying stuff.