Hello,
i know this has been discussed several times now on the internet, and I also found most of them and i tried everything but I was still not able to fix that. And it´s really starting to piss me of right now i am looking for the issue for more than 4 days now. I dont get what the hell i am doing wrong, i followed several tutorials now, even video tutorials but always something doesnt work or it ends up in “just” the error: Unable to load asset as a non content file whilst the inner exception says it cannot find the contentreadertype type or something like that.
is my project, it consists of a Shared Project which contains the content file (mgcb) and it gets referenced by the DesktopGL and Android project.
You will see its not much in there yet because i started with adding that Custom Content Reading stuff into my game.
I hope there are some ppl. willing to help me
Simply what i want to do is, creating an importer for an xml file basically but with another file type ending.
The sample in the project attached is a menu importer / reader / writer.
I have a simple class Menu where i store for now basic values.
I dont know what the problem is, maybe you guys can track this down.
Edit: I will explain the structure a little:
I have a DesktopGL project
I have an Android project
I have a Shared Project which gets referenced by the DesktopGL and Android project. It contains the class Menu, which is the class i want to get from Content.Load(…) when loading my menu file. And the MenuReader class.
The SharedProject should btw. also contain all the game logic code later so that i just need to call the game code
in each platform project.
Last project is Content Pipeline Extension project which contains Writer and Importer, and it references the Shared Project to have access to the Menu and the Menu Reader.
Like this everything should be fine because the Desktop and android only references required classes and not also the content pipeline extension library.
Now my classes:
MenuReader (located in the Shared Project):
public class MenuReader : ContentTypeReader<Menu>
{
protected override Menu Read(ContentReader input, Menu existingInstance)
{
return input.ReadObject<Menu>();
}
}
Importer (located in the pipeline library project)
[ContentImporter(".mnu", DisplayName = "Menu Importer - Teraxia.ContentPipeline")]
public class MenuImporter : ContentImporter<Menu>
{
public override Menu Import(string filename, ContentImporterContext context)
{
Menu menu = null;
var serializer = new XmlSerializer(typeof(Menu));
using (var reader = new StreamReader(filename))
menu = serializer.Deserialize(reader) as Menu;
return menu;
}
}
Writer (located in the Pipeline Extension library project)
public class MenuWriter : ContentTypeWriter<Menu>
{
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return typeof(MenuReader).AssemblyQualifiedName;
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return typeof(Menu).AssemblyQualifiedName;
}
protected override void Write(ContentWriter output, Menu value)
{
output.WriteObject(value);
}
}
and the model Menu class (located in the Shared Project as well)
[XmlRoot]
public class Menu
{
[XmlArray]
public MenuItem[] MenuItems { get; set; }
}
public class MenuItem
{
[XmlElement]
public string Label { get; set; }
[XmlElement]
public string Operation { get; set; }
}
Thanks in advance.