public static void LoadXML(string file_name) { float test = 50; Debug.Log(Application.persistentDataPath); // Stream the file with a File Stream. (Note that File.Create() 'Creates' or 'Overwrites' a file.) //FileStream file = File.Open(Application.persistentDataPath + "/" + file_name + ".dat", FileMode.Open); // Create a new Player_Data. PatrolData data = new PatrolData(5); //Serialize to xml DataContractSerializer bf = new DataContractSerializer(data.GetType()); MemoryStream streamer = new MemoryStream(); //file_name = Path.Combine(this.path, Application.persistentDataPath, file_name + ".dat"); //DataContractSerializer dcs = new DataContractSerializer(typeof(Games)); FileStream fs = new FileStream(Application.persistentDataPath + "/" + file_name + ".xml", FileMode.Open); XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas()); data = (PatrolData)bf.ReadObject(reader); reader.Close(); fs.Close(); ////Serialize the file //data = (PatrolData)bf.ReadObject(streamer); //Debug.Log(data.is_synchronized); //Debug.Log(data.synchronized_Rhandor); //Debug.Log(data.give_permission_pos); //Debug.Log(data.path[0]); //bf.WriteObject(streamer, data); //streamer.Seek(0, SeekOrigin.Begin); //Save to disk //file.Write(streamer.GetBuffer(), 0, streamer.GetBuffer().Length); // Close the file to prevent any corruptions //file.Close(); //string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString(); //Debug.Log("Serialized Result: " + result); }
public static void SaveXML(string file_name) { float test = 50; Debug.Log(Application.persistentDataPath); // Stream the file with a File Stream. (Note that File.Create() 'Creates' or 'Overwrites' a file.) FileStream file = File.Create(Application.persistentDataPath + "/" + file_name + ".xml"); // Create a new Player_Data. PatrolData data = ScriptableObject.CreateInstance <PatrolData>(); //Save the data. data.is_synchronized = true; data.path_attached = GameObject.Find("Neutral_trigger"); data.give_permission_pos = 15; data.path[0] = Vector3.forward; //Serialize to xml DataContractSerializer bf = new DataContractSerializer(data.GetType()); MemoryStream streamer = new MemoryStream(); //Serialize the file bf.WriteObject(streamer, data); streamer.Seek(0, SeekOrigin.Begin); //Save to disk file.Write(streamer.GetBuffer(), 0, streamer.GetBuffer().Length); // Close the file to prevent any corruptions file.Close(); //string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString(); string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer())).ToString(); Debug.Log("Serialized Result: " + result); }