I was using a simple serializer to load an xml file to my game (I'm implementing mod support). The way I had it first (it's not my own serializer) was like this:
public static EnemyList Load(string path)
{
TextAsset _xml = Resources.Load<TextAsset>(path);
XmlSerializer serializer = new XmlSerializer(typeof(EnemyList));
StringReader reader = new StringReader(_xml.text);
EnemyList enemies = serializer.Deserialize(reader) as EnemyList;
reader.Close();
return enemies;
}
The problem with that is that "Resources.Load" is being used. Since I want the players to write/install mods the Resources folder can't be used here (because as far as I know they can't access the Resources folder). Therefore I created a "Mods" folder in the build folder and in that Mods folder other peoples folders (for example if I would make a mod I would have a folder like "MyMod" and that folder would have other folders like "entities" with an "entities.xml" file) are located. To get all the files from a folder I used DirectoryInfo. And here is my problem: I'm trying to change the serializer to work with DirectoryInfo. This is the code so far:
public static EnemyList LoadXml(string path)
{
DirectoryInfo direcInfo = new DirectoryInfo(path);
FileInfo[] fileInfo = direcInfo.GetFiles();
XmlSerializer serializer = new XmlSerializer(typeof(EnemyList));
StringReader reader = new StringReader(fileInfo[0].ToString());
EnemyList enemies = serializer.Deserialize(reader) as EnemyList;
reader.Close();
return enemies;
}
but when I start the game I'm getting the Error: XmlException: Data at the root level is invalid. Line 1, position 1. I've also tried things like File.ReadAllText(path) but I'm getting an "unauthorizedaccessexception". When I googled that problem I found out that I need to specify a file in the path and not the directory (not just Mods/entities but Mods/entities/entities.xml) but I don't want to just read one single file. I want to ready every xml file that is in there. And even if I change it to entities.xml I'm still getting an Error IOException: Error 267 (couldn't find any answers to fix that)
I hope someone can help me with that. I've already googled but the people on the forum did completely different things, I couldn't apply that to my case.
Thank you in advance!
In case the xml is needed: