【问题标题】:Disable vs2010 XNA Content Pipeline warning禁用 vs2010 XNA 内容管道警告
【发布时间】:2013-01-16 02:12:27
【问题描述】:

我正在使用 XNA 构建游戏,并且我的游戏关卡具有自定义文件格式。我想自己加载并解析它们,而不使用 XNA 的内容管道。我有这么多工作,通过将文件添加到内容项目中,我什至可以在 Visual Studio 中编辑它们(我也想要)。

问题:我收到一条警告,指出“项目项 'item.lvl' 不是使用 XNA 框架内容管道构建的。将其构建操作属性设置为编译以构建它。”

我不希望 XNA 编译它,因为我正在做自己的解析。如何禁用警告?

【问题讨论】:

    标签: c# xna


    【解决方案1】:

    将文件的构建操作设置为None,然后将其设置为Copy if newer。这将导致文件被写入正确的输出目录,而无需通过内容管道。

    【讨论】:

      【解决方案2】:

      解决方案可以创建一个自定义内容导入器,如下所述:Creating a Custom Importer and Processor。要创建一个简单的内容导入器,您必须从 ContentImporter<T>(抽象类)继承您的类并覆盖 Import() 方法。

      这是一个来自 msdn 的简单示例:

      //...
      using Microsoft.Xna.Framework.Content.Pipeline;
      
      class PSSourceCode
      {
          const string techniqueCode = "{ pass p0 { PixelShader = compile ps_2_0 main(); } }";
      
          public PSSourceCode(string sourceCode, string techniqueName)
          {
              this.sourceCode = sourceCode + "\ntechnique " + techniqueName + techniqueCode;
          }
      
          private string sourceCode;
          public string SourceCode { get { return sourceCode; } }
      }
      
      [ContentImporter(".psh", DefaultProcessor = "PSProcessor", DisplayName = "Pixel Shader Importer")]
      class PSImporter : ContentImporter<PSSourceCode>
      {
          public override PSSourceCode Import(string filename, 
              ContentImporterContext context)
          {
              string sourceCode = System.IO.File.ReadAllText(filename);
              return new PSSourceCode(sourceCode, System.IO.Path.GetFileNameWithoutExtension(filename));
          }
      }
      

      【讨论】:

      • 感谢您的示例,但我已经有了文件的解析系统。只是想要关于不使用管道的警告消失。
      猜你喜欢
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多