Is it possible to pack all the little .xnb files into one big file? Given the level of abstraction of the XNA Framework I though this would come out of the box but I can't find any well integrated solution.
So far the best candidate is XnaZip but in addition to having to compile the resources in a post-build event, and a little trouble porting the game to XBOX I have to rename all the references to resources I have already implemented.
Answer
It's possible, but you either have to:
- Find a library that does it for you, or
- implement it yourself.
XNA lets you do the latter by deriving from the ContentManager
class and replacing the OpenStream
method; in fact, the documentation explicitly says:
protected virtual Stream OpenStream (string assetName)
Opens a stream for reading the specified asset. Derived classes can replace this to implement pack files or asset compression.
In the override version of OpenStream
, one would simply return a compatible Stream
that read the requested asset data from a pack file, rather than opening a FileStream
from disk.
The tricky part is that you have to actually build the pack file yourself, incorporating the xnb
files output via the content build pipeline. You could build a Content Pipeline Extension to do this, or find some other method, depending on what your goals are.
No comments:
Post a Comment