Esempio n. 1
0
        private static T BuildNLoad <T>(ContentBuilder builder, ContentManager content, string file, string processor, string importer)
        {
            builder.Clear();
            builder.Add(file, Path.GetFileName(file), importer, processor);

            string buildError = builder.Build();

            if (string.IsNullOrEmpty(buildError))
            {
                return(content.Load <T>(Path.GetFileName(file)));
            }
            throw new System.NullReferenceException(buildError);
        }
Esempio n. 2
0
        public static bool TryLoad <T>(this ContentBuilder builder, ContentManager content, string importer, string processor, string file, out T value)
        {
            builder.Clear();
            builder.Add(file, Path.GetFileName(file), importer, processor);

            string buildError = builder.Build();

            if (string.IsNullOrEmpty(buildError))
            {
                value = content.Load <T>(Path.GetFileName(file));
                return(true);
            }
            value = default(T);
            return(false);
        }
Esempio n. 3
0
        public static T Load <T>(this ContentBuilder builder, ContentManager content, string file)
        {
            switch (typeof(T).FullName)
            {
            case "Microsoft.Xna.Framework.Graphics.Texture2D":
                return(BuildNLoad <T>(builder, content, file, "TextureProcessor", "TextureImporter"));

            case "Microsoft.Xna.Framework.Graphics.Model":
                return(BuildNLoad <T>(builder, content, file, null, "ModelProcessor"));   // importer? (FbxImporter, XImporter)

            // TODO: Add more

            default:
                throw new System.ArgumentException("Wat is what? " + typeof(T).Name + " ??");
            }
        }
Esempio n. 4
0
        protected override void LoadContent()
        {
            contentBuilder = new ContentBuilder();
            contentManager = new ContentManager(Services, contentBuilder.OutputDirectory);

            spriteBatch = new SpriteBatch(GraphicsDevice);

            try
            {
                texture = contentBuilder.Load<Texture2D>(contentManager, Environment.CurrentDirectory + "\\XnaLogo.png");
            }
            catch (Exception error)
            {
                System.Windows.MessageBox.Show(error.Message);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Builds and load a model. Supported: .fbx and .x .
 /// </summary>
 public static bool TryLoadModel(this ContentBuilder builder, ContentManager content, string file, out Microsoft.Xna.Framework.Graphics.Model value)
 {
     return(TryLoad <Microsoft.Xna.Framework.Graphics.Model>(builder, content, null, "ModelProcessor", file, out value));
 }
Esempio n. 6
0
 /// <summary>
 /// Builds and load a texture.
 /// </summary>
 public static bool TryLoadTexture2D(this ContentBuilder builder, ContentManager content, string file, out Microsoft.Xna.Framework.Graphics.Texture2D value)
 {
     return(TryLoad <Microsoft.Xna.Framework.Graphics.Texture2D>(builder, content, "TextureImporter", "TextureProcessor", file, out value));
 }