- Home /
Question by
TheShadyColombian · Feb 09, 2017 at 04:19 AM ·
c#runtimexmlxmlserializerwrite data
Read AND Write to XML at runtime
I want to create a custom file save with XML (I don't like the way PlayerPrefs does it) but from what I've read, the way I'm doing it right now won't allow me to write/modify the file at runtime, which defeats the whole purpose of it. I don't really care if the file is human-readable like the PlayerPrefs xml file is, as long as it's read and write.
Here's the script I'm using for accessing the file and whatnot, but there's no write-to method yet (as that's when I hit a hitch on the road):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml.Serialization;
using System.IO;
[XmlRoot("LevelCollection")]
public class XML_LevelCollection {
[XmlArray("Levels")]
[XmlArrayItem ("Level")]
public List <XML_Level> Levels = new List <XML_Level>();
public static XML_LevelCollection Load (string path) {
TextAsset LevelContainerXML = Resources.Load <TextAsset> (path);
XmlSerializer Serializer = new XmlSerializer (typeof (XML_LevelCollection));
StringReader Reader = new StringReader (LevelContainerXML.text);
XML_LevelCollection levels = Serializer.Deserialize (Reader) as XML_LevelCollection;
Reader.Close ();
return levels;
}
}
Comment
Your answer
Follow this Question
Related Questions
Xml Serialization? (how to read/write?) 1 Answer
Something should I know about how to load XML on runtime game? 1 Answer
c# to compile xml string as code during runtime 1 Answer
XML parsing c# in unity 1 Answer
Multiple Cars not working 1 Answer