Moritz Schöfl
Moritz Schöfl

Reputation: 763

C# Load Resource from DLL (ResourceManager)

I need to load some .Xnb files from a DLL in a Xna Game. For this, there is a "ResourceContentManager" which takes a "ResourceManager" in the Constructor. So how to add the files as Embedded Resources to the DLL and initialize a ResourceManager? The Following Code didnt worked (namespace is "Mox")

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

I added the Resource "Shader.fx" with "Add->Existing" and then set the Build to Embedded Resource and "copy always" ... this throws an Exception so I know it didnt loaded correctly... any suggestions?

Upvotes: 2

Views: 2020

Answers (1)

Neil Knight
Neil Knight

Reputation: 48547

I asked a similar question over at gamedev.stackexchange.com. The answer may help you as well, see below:

I have another solution in addition to Russell's which allows you to use the content manager and allows you to embed all of the types of content XNA supports.

XNA supports the ContentManager though a resource instead of a content project. To use it do the below. Of course you will need to pass a reference of your game's services at some point.

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

Use this to compile the shader or anything to a xnb.

Add any and all of the XNB to your resources. Them simply load your content as usual.

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

Upvotes: 2

Related Questions