无法将monoccube资源作为非内容文件加载

本文关键字:文件 加载 monoccube 资源 | 更新日期: 2023-09-27 18:16:15

最近我已经采取了一夫一妻制,并开始学习3D游戏编程,以下一些在线教程如何添加3D模型,我得到了以下代码,应该显示一个3D立方体和一个相机,我控制平移它:

public class Game1 : Game
{
    GraphicsDeviceManager graphics;
    Vector3 camTarget;
    Vector3 camPosition;
    Matrix projectionMatrix;
    Matrix viewMatrix;
    Matrix worldMatrix;
    Model model;

    // orbit
    bool orbit;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }
    protected override void Initialize()
    {
        base.Initialize();

        camTarget = new Vector3(0f, 0f, 0f);
        camPosition = new Vector3(0f, 0f, -100f);
        projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), GraphicsDevice.DisplayMode.AspectRatio, 1f, 1000f);
        viewMatrix = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);
        worldMatrix = Matrix.CreateWorld(camTarget, Vector3.Forward, Vector3.Up);
    }
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        model = Content.Load<Model>("MonoCube"); 
        // TODO: use this.Content to load your game content here
    }
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }
    protected override void Update(GameTime gameTime)
    {
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            Exit();
        // TODO: Add your update logic here
        if (Keyboard.GetState().IsKeyDown(Keys.Left))
        {
            camPosition.X -= 1f;
            // remove this to create a rotation
            camTarget.X -= 1f;
        }
        if (Keyboard.GetState().IsKeyDown(Keys.Right))
        {
            camPosition.X += 1f;
            // remove this to create a rotation
            camTarget.X += 1f;
        }
        if (Keyboard.GetState().IsKeyDown(Keys.Up))
        {
            camPosition.Y -= 1f;
            // remove this to create a rotation
            camTarget.Y -= 1f;
        }
        if (Keyboard.GetState().IsKeyDown(Keys.Down))
        {
            camPosition.Y += 1f;
            // remove this to create a rotation
            camTarget.Y += 1f;
        }
        if (Keyboard.GetState().IsKeyDown(Keys.OemPlus))
        {
            camPosition.X += 1f;
            // remove this to create a rotation
        }
        if (Keyboard.GetState().IsKeyDown(Keys.OemMinus))
        {
            camPosition.X -= 1f;
            // remove this to create a rotation
        }
        if (Keyboard.GetState().IsKeyDown(Keys.Space))
        {
            orbit = !orbit;
        }
        if (orbit)
        {
            Matrix rotationMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(1f));
            camPosition = Vector3.Transform(camPosition, rotationMatrix);
        }
        viewMatrix = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);

        base.Update(gameTime);
    }
    protected override void Draw(GameTime gameTime)
    {

        GraphicsDevice.Clear(Color.CornflowerBlue);
        // TODO: Add your drawing code here
        foreach(ModelMesh mesh in model.Meshes)
        {
            foreach(BasicEffect effect in mesh.Effects)
            {
                effect.View = viewMatrix;
                effect.World = worldMatrix;
                effect.Projection = projectionMatrix;
                //mesh.Draw();
            }
            mesh.Draw();
        }
        base.Draw(gameTime);
    }
}

问题是,当我尝试启动游戏时,我得到以下错误:

类型为"Microsoft.Xna.Framework.Content"的未处理异常。在MonoGame.Framework.dll中发生ContentLoadException'附加信息:无法将monoccube资产作为非内容文件加载!

我无法弄清楚问题是什么,管道有。dae文件和模型的png和构建很好,内容管道。mgcb文件在内容文件夹内,所以这不是我所知道的问题,我真的很感激任何和所有的帮助,因为我现在在这个损失。

无法将monoccube资源作为非内容文件加载

您可以尝试使用XNB文件来确保加载没有问题。微软有几个例子,这是我想到的第一个:http://xbox.create.msdn.com/en-US/education/catalog/lab/marble_maze

可能是一个愚蠢的建议,但要确保编译的内容文件位于主项目的content文件夹中,而不是content项目。

你的目标平台是什么?我有一段时间没有使用一夫一妻制了,但以前你不能在ios上使用Spritefont的windows编译,反之亦然。查看内容项目中.dae文件的选项。