Jump to content
  • Advertisement
Sign in to follow this  
Armigus2

[XNA] Content Pipeline references

This topic is 3040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to read an XML file that contains a reference to another asset, say a texture, load the texture at compile time, and store that asset along with some useful metadata:


public class ImageImport : IContent
{
protected string path;
protected Vector2 origin, thumbGrid;

public string Path
{
get { return path; }
set { path = value; }
}

public Vector2 Origin
{
get { return origin; }
set { origin = value; }
}

public Vector2 ThumbGrid
{
get { return thumbGrid; }
set { thumbGrid = value; }
}

public void ReadContent(ContentReader input)
{
path = input.ReadString();
origin = input.ReadVector2();
thumbGrid = input.ReadVector2();
}

public void WriteContent(ContentWriter output) { }
}

public class ImageContent : IContent
{
protected Texture2D image;
protected Vector2 origin, thumbGrid;

public Texture2D Image
{
get { return image; }
set { image = value; }
}

public Vector2 Origin
{
get { return origin; }
set { origin = value; }
}

public Vector2 ThumbGrid
{
get { return thumbGrid; }
set { thumbGrid = value; }
}

[ContentSerializerIgnore]
public int Width
{
get { return image.Width; }
}

[ContentSerializerIgnore]
public int Height
{
get { return image.Height; }
}

public void ReadContent(ContentReader input)
{
image = input.ReadObject<Texture2D>();
origin = input.ReadVector2();
thumbGrid = input.ReadVector2();
}

public void WriteContent(ContentWriter output)
{
output.WriteObject<Texture2D>(image);
output.Write(origin);
output.Write(thumbGrid);
}
}


I described IContent and its use in an earlier post. Since the input content is basic xml, I shouldn't need an importer. What I need is a content processor:


[ContentProcessor (DisplayName = "TileContent.ImageProcessor")]
public class ImageProcessor : ContentProcessor<ImageImport, ImageContent>
{
public override ImageContent Process(ImageImport input,
ContentProcessorContext context)
{
ImageContent ic = new ImageContent();
ic.Origin = input.Origin;
ic.ThumbGrid = input.ThumbGrid;
var imageref = new ExternalReference<Texture2D>(input.Path);
ic.Image = context.BuildAndLoadAsset<Texture2D,Texture2D>(
imageref,
"TextureProcessor");
}
}


Am I doing this right?

[Edited by - Armigus2 on August 21, 2010 1:16:10 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!