using UnityEngine;
using System.Collections;
using System.Xml.Serialization;
using System.IO;

public class XMLManager {
    public void XMLWrite<T>(T obj, string fileName) {
        XmlSerializer writer = new XmlSerializer(obj.GetType());
        StreamWriter file = new StreamWriter(Application.persistentDataPath + "/" + fileName + ".xml");
        writer.Serialize(file, obj);
        file.Close();

        Debug.Log("Created xml file @ " + Application.persistentDataPath + "/" + fileName + ".xml");
    }

    public T XMLRead<T>(T obj, string fileName) {
        XmlSerializer reader = new XmlSerializer(obj.GetType());
        StreamReader file = new StreamReader(Application.persistentDataPath + "/" + fileName + ".xml");
        T result = (T)reader.Deserialize(file);

        return result;
    }
}
