【问题标题】:C# Load Resource from DLL (ResourceManager)C# 从 DLL 加载资源 (ResourceManager)
【发布时间】:2011-12-15 16:32:38
【问题描述】:

我需要从 Xna 游戏中的 DLL 加载一些 .Xnb 文件。为此,有一个“ResourceContentManager”,它在构造函数中采用“ResourceManager”。那么如何将文件作为嵌入式资源添加到 DLL 并初始化 ResourceManager?以下代码不起作用(命名空间为“Mox”)

ResourceManager resourceManager = new ResourceManager("Mox", Assembly.GetExecutingAssembly());
Stream s = resourceManager.GetStream("Shader");
if(s == 0)
    throw new Exception();

我使用“Add->Existing”添加了资源“Shader.fx”,然后将“构建”设置为嵌入式资源并“始终复制”...这会引发异常,所以我知道它没有正确加载...任何建议?

【问题讨论】:

  • 您有什么不想使用内容管道的原因吗?
  • 嵌入的时候会抛出什么异常?

标签: c# resources xna


【解决方案1】:

我在gamedev.stackexchange.com 上问了一个类似的问题。答案也可能对您有所帮助,见下文:

除了 Russell 的解决方案之外,我还有另一个解决方案,它允许您使用内容管理器并允许您嵌入 XNA 支持的所有类型的内容。

XNA 通过资源而不是内容项目支持 ContentManager。要使用它,请执行以下操作。当然,您有时需要传递游戏服务的引用。

ResourceContentManager Content = new ResourceContentManager(game.Services, Resource1.ResourceManager);

使用this 将着色器或任何东西编译成xnb。

将所有 XNB 添加到您的资源中。他们只是像往常一样加载您的内容。

Content.Load<Texture2D>(".\\assetName")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多