2
\$\begingroup\$

I am wondering if its possible to use the XNA Content Pipeline to load C# files?

I'm working on a game and am currently writing a FSM. I would like to be able to load states from the content pipeline, but the states would be written in C# and must use my interface.

Anyone know how to do this?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ If you're going to have the classes in the content pipeline to be built with the project, why not just include them in the project directly? \$\endgroup\$ Dec 5, 2011 at 16:17

2 Answers 2

4
\$\begingroup\$

It is possible to create a custom importer/processor for C# files. It's also possible to dynamically add content, although it takes a good bit of work.

Unless you really need to load in classes dynamically rather than include them in the project itself, don't do it. Your brain will thank you later.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks guys, I think I will just include them in my project, thanks for the links I will keep them for future use. \$\endgroup\$
    – Iain Brown
    Dec 5, 2011 at 16:47
2
\$\begingroup\$

XNA's standard set of importers and processors does not include anything for processing C# files specifically as content, so off-the-shelf, the content pipeline can't do what you want, unless you leave the files as unprocessed text. You can, however, extend the pipeline should you so choose.

However, doing so would probably be a waste of time. The content pipeline is intended to provide build-time transformation services to non-code assets to prepare and optimize them for use at runtime (dynamically adding content at runtime is possible, though a bit tedious, if I recall).

You're talking about executable code in your C# files, and since the content pipeline's transformation services are a build-time operation there will be no functional difference between abusing the content pipeline to hold your C# files and simply adding those same C# files to your main game project, as Drackir suggested in his comment.

In fact, even if you leave the files as unprocessed source code or write a custom content manipulation step to compile them somehow, you'd be faced with the fact that many of the APIs available to compile code, or execute compiled code, at runtime aren't available on the non-desktop platforms -- so if you intend your XNA project to run on those, you almost certainly can't use the content pipeline.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .