Xna 内容管道扩展 - 在自定义处理器中加载其他内容

发布于 2024-11-25 16:10:54 字数 814 浏览 0 评论 0原文

我目前正在尝试 Xna Content Pipeline 扩展。在该实验中,我尝试加载一个包含另一个需要加载的“内容项”的文件。例如:

public class CustomItem
{
    public string Name;
    public Texture2D Texture;
}

现在,在我的内容处理器中,我可以创建“CustomItem”的新实例并初始化“名称”字段,因为它只是一个字符串。但是,我无法在内容编译期间加载纹理文件(注意:纹理只是一个示例,理想情况下我希望能够加载任何其他内容类型)。

我正在寻找的是这样的东西:

// ... start class ...

public override CustomItem Process(SomeInputFormat input, ContentProcessorContext context)
{
    return new CustomItem()
    {
        Name = input.ItemName,
        Texture = context.LoadAsset<Texture2D>(input.ItemTexturePath)   // I realise LoadAsset<T>() does not exist - it's an example of what would be ideal
    };
}

// ... end class ...

有谁知道这是否真的可能,如果是的话,如何去做?如果可能的话,我不想走后期加载其他内容项的路线,或者使用二进制读取器和写入器创建我自己的自定义内容加载。

I'm currently experimenting with Xna Content Pipeline extensions. Within that experimentation, I'm trying to load a file that contains another 'content item' that is in need of loading. For example:

public class CustomItem
{
    public string Name;
    public Texture2D Texture;
}

Now, in my content processor, I can create a new instance of 'CustomItem' and initialize the Name field, since it's simply a string. However, I can't load the texture file during content compilation (NOTE: The texture is just an example, ideally I'd like to be able to load any other content type).

What I'm looking for is something like:

// ... start class ...

public override CustomItem Process(SomeInputFormat input, ContentProcessorContext context)
{
    return new CustomItem()
    {
        Name = input.ItemName,
        Texture = context.LoadAsset<Texture2D>(input.ItemTexturePath)   // I realise LoadAsset<T>() does not exist - it's an example of what would be ideal
    };
}

// ... end class ...

Does anyone know if this is actually possible, and if so, how to go about it? I'd rather not go down the route of late loading the other content items if possible, or creating my own, custom content loading using binary readers and writers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒七 2024-12-02 16:10:54

您不能在内容管道中使用 Texture2D。您必须使用Texture2DContent,它是前者的代理类型。反过来,您的类型中必须有一种机制,允许成员在内容构建时为 Texture2DContent,但在运行时为 Texture2D本文< /a> 为您提供了三种执行此操作的方法。

您可以使用 ContentProcessorContext.BuildAndLoadAsset 来获取您的 Texture2DContent 对象。此纹理数据将嵌入到该资源的 .xnb 文件中。

如果您实际上不需要在管道中使用纹理数据,特别是如果您打算在多个资源之间共享相同的纹理,则可以使用 ContentProcessorContext.BuildAsset 来获取 纹理的外部引用,该纹理内置于其自己的 .xnb 文件中,位于资源的 .xnb 文件(以及 ContentManager)外部将处理加载 你)。

You can't use Texture2D in the content pipeline. You have to use Texture2DContent, which is a proxy-type for the former. In turn, you must have a mechanism in your type for allowing the member to be Texture2DContent at content build time, but Texture2D at run-time. This article gives you three ways of doing this.

You can use ContentProcessorContext.BuildAndLoadAsset to get your Texture2DContent object. This texture data will be embedded into your .xnb file for that asset.

If you don't actually need to use the texture data in the pipeline, and in particular if you intend to share the same texture between multiple assets, you can use ContentProcessorContext.BuildAsset to get an ExternalReference to the texture, which is built into its own .xnb file, external to your asset's .xnb file (and ContentManager will handle the loading for you).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文