I try to get a list of all sound elements in the XML-File.
I got all marker but when i try to get all elements with the tag sound i don't get anything. The list is always 0.
Root Class
[XmlArray("markers")]
[XmlArrayItem("marker")]
public List<WaypointInfo> markers = new List<WaypointInfo>();
[XmlArray("pattern")]
[XmlArrayItem("sound")]
public List<SoundInfo> soundsInfo = new List<SoundInfo> ();
/// <summary>
/// The file extension.
/// </summary>
public static readonly string fileExtensionMp3 = "*.mp3";
public static FileLoader loadInformationXML(string filePath){
//Define the rootclass
XmlSerializer serializer = new XmlSerializer (typeof(FileLoader));
//Create inputstream
FileStream fl = new FileStream (filePath, FileMode.Open);
//Extract the stream and save it into our root class
FileLoader xmlData = serializer.Deserialize (fl) as FileLoader;
//Close the inputstream
fl.Close ();
return xmlData;
}
The markers arraylist is correct but the other list of sounds is always null.
Class WaypointsInfo
using UnityEngine;
using System.Collections.Generic;
using System.Xml.Serialization;
public class WaypointInfo {
[XmlAttribute("name")]
public string markerName;
public Pattern pattern = new Pattern();
}
Class Soundinfo
using UnityEngine;
using System.Xml.Serialization;
using System.Collections;
public class SoundInfo {
/// <summary>
/// The minimum distance that triggers this sound.
/// </summary>
[XmlAttribute("distance")]
public float distance;
/// <summary>
/// When this sound has been played the last time, in runtime milliseconds.
/// </summary>
public float lastPlayed;
/// <summary>
/// If this sound should be looped.
/// </summary>
public bool looped;
}
and the xml file
<soundpackage>
<markers>
<marker name="bird">
<pattern name="aPattern">
<sound distance="10">bird.mp3</sound>
<sound distance="10">bird.mp3</sound>
</pattern>
</marker>
</markers>
</soundpackage>