I have a little problem with designing editor in xna. I have Content types like
TilemapContent
and then runtime types like TilemapData
(that are automaticly converted by content pipeline)
but in editor, i think i need to work with TilemapContent
(so that i can save it as such later), but TilemapContent
contains things like ExternalReference<Texture2DContent>
instead of Texture2D
, so there is no way i could render such thing.
One "solution" that i can think of is every time i make a change to TilemapContent
, i need to rebuild it and then reload TilemapData
(and i guess this would be really slow)
Another solution would be to write third class TilemapEditorData
and inside it write method that would convert that class to TilemapContent
. But this would be third class, with almost same data, and it would require me to write something that would convert things like Texture2DContent to Texture2D.
So question is, how is this thing done? Can i have different content type and runtime type and still make an editor?
EDIT: source
ContentPipelineExtension project
[ContentSerializerRuntimeType("Data.TileMapData, Game")]
public class TilemapContent
{
public int Width { get; set; }
public int Height { get; set; }
public ExternalReference<Texture2DContent> Texture { get; set; } // i need this in editor so i can change tileset texture
public int[] Tiles { get; set; }
}
Map.xml
<XnaContent>
<Asset Type="Content.TilemapContent">
<Width>3</Width>
<Height>3</Height>
<Texture>
<Reference>#External1</Reference>
</Texture>
<Tiles>
0 1 0
0 0 1
0 0 0
</Tiles>
</Asset>
<ExternalReferences>
<ExternalReference ID="#External1" TargetType="Microsoft.Xna.Framework.Content.Pipeline.Graphics.Texture2DContent">raytileset.jpg</ExternalReference>
</ExternalReferences>
</XnaContent>
(i have custom ContentProcessor that will build all external references in xml file)
Game project
public class TilemapData
{
public int Width { get; set; }
public int Height { get; set; }
public Texture2D Texture; // and i need this in editor so i can render tilemap
public int[] Tiles { get; set; }
}