In this article you will learn how to use the Content Compiler, shown by a little demo app. (The following Code is based on an empty Consoleapp Template in Visual STudio 2010):


using System; using System.Diagnostics; using System.Windows.Forms; using EES.ContentCompiler.Core.Providers; using EES.ContentCompiler.Xna; namespace ConsoleApplication1 { class Program { [STAThread] static void Main(string[] args) { //Create a new OpenFileDialog, set its initial Selection to My Computer and enable multi selection var openFile = new OpenFileDialog { Multiselect = true, InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) }; //Display the Dialog to the User and in case of a chosen file compile it. if (openFile.ShowDialog() == DialogResult.OK) { //Create a new instance of the XnaContentCompiler from namespace EES.ContentCompiler.Xna //and set its Output to a location (for example a temporary location) var xnaCompiler = new XnaContentCompiler(Application.UserAppDataPath) { //Set the platform we want to compiler for Platform = XnaPlatform.Windows, //Xna Version you want to use XnaVersion = XnaVersion.FourZero, //If you want to use XNA 4 you also have to set the XnaProfile. Default is Reach. XnaProfile = XnaProfile.Reach }; //Add the files to the Compiler foreach (var fileName in openFile.FileNames) { //Some Sample Compiler Options for a Texture. Options are the same like in VS but without spaces. var compilerOptions = new SerializableDictionary<string, object> { {"GenerateMipmaps", false}, {"ResizeToPowerOfTwo", true}, {"TextureFormat", "DxtCompressed"} }; //Create a new FileObject and add it to the compiler var file = new File(fileName, compilerOptions); xnaCompiler.Files.Add(file); } //Now its time for some Compiler Magic! //Compile and Write Errors to output Console.WriteLine(xnaCompiler.Build("test.ccbuild")); Console.WriteLine("Done. Waiting for Input..."); //Wait for Keyboard Input to close App and open Explorer. Console.ReadKey(); Process.Start(Application.UserAppDataPath); } } } }

Last edited Nov 19, 2011 at 8:49 PM by eagleeyestudios, version 4

Comments

No comments yet.