Hey guys!
This is my first time using XML and parsing it from my project and was wondering if there was something I was missing here!
Basically I have a video player that will play a video when a level loads IF the first child of the node is a video.
I’m not sure the best way to achieve this. It doesn’t seem like it wants to allow me to do a null check on the specific node since the node doesn’t actually exist for some levels. It did work if I passed the levels with no videos an “Empty” url but I don’t like this solution!
Here is my basic C# for handling the XML:
string filepath = Application.dataPath + @"/Files/GAMEdata.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNodeList levels = xmlDoc.GetElementsByTagName("Level");
foreach(XmlNode level in levels)
{
if(level.Attributes["id"].Value == currentLevel.ToString())
{
print ("the current level ID is: " + level.Attributes["id"].Value);
if(level.FirstChild.Attributes["url"].Value != "EMPTY")
{
vid.playVideo(level.FirstChild.Attributes["url"].Value, true);
}
else
{
print ("there are no videos");
bootLevel();
}
}
}
Here is a snippet from my XML:
<?xml version="1.0"?>
<Levels>
<Level id="0">
<Video url="file://X:/Unity Projects/xmlstuff/files/introcutscene.mp4"></Video>
</Level>
<Level id="1">
<Video url="EMPTY"></Video>
</Level>
</Levels>
So what I have works but I don’t like it!
Thanks guys!