Hi everyone!
I’m trying to make an xml file to save some data on my game, on Unity Editor i didnt had any trouble, and i was able to generate the file, load it and re save it, but it doesnt seem to be working on Android and i dont know why.
I’m Usint System.xml.serialization.
This is my Saving Method:
public void SaveXml(string filename)
{
//string path = Path.Combine(Application.dataPath, filename);
string path = Application.dataPath + filename;
XmlSerializer serializer = new XmlSerializer(typeof(DataSerializer));
// TODO: Check Diferent Filemodes (Append, Check if file exists)
using (FileStream stream = new FileStream(path, FileMode.Create))
{
serializer.Serialize(stream, this);
}
}
And the Loading:
public static DataSerializer LoadXml(string path)
{
var serializer = new XmlSerializer(typeof(DataSerializer));
using (FileStream stream = new FileStream(path, FileMode.Open))
{
return serializer.Deserialize(stream) as DataSerializer;
}
}
I’ve modified the loading and made a new method to get a string and deserialize it from a text, but it doesnt work on android also.
and i dont know how make the “Save” of the xml pointing to the resources folder
public static DataSerializer LoadXmlFromFile(string filename)
{
XmlSerializer serializer = new XmlSerializer(typeof(DataSerializer));
TextAsset text = Resources.Load(filename) as TextAsset;
if (text != null)
{
using (Stream s = new MemoryStream(text.bytes))
{
return serializer.Deserialize(s) as DataSerializer;
}
}
else
{
Debug.LogWarning(string.Format("Unable to load resource {0}", filename));
}
return null;
}
does anyone have some info, or link to some tutorial on how to achieve this???
I need to read/write a file with data about the game like, purchased cars, personalization made to each one etc.
Any hints on this would be really appreciated!
Thanks in advance!