using System; using System.IO; using System.Text; using System.Xml.Serialization; using UnityEngine; namespace BayatGames.SaveGameFree.Serializers { /// /// Save Game Xml Serializer. /// public class SaveGameXmlSerializer : ISaveGameSerializer { /// /// Serialize the specified object to stream with encoding. /// /// Object. /// Stream. /// Encoding. /// The 1st type parameter. public void Serialize ( T obj, Stream stream, Encoding encoding ) { try { XmlSerializer serializer = new XmlSerializer ( typeof ( T ) ); serializer.Serialize ( stream, obj ); } catch ( Exception ex ) { Debug.LogException ( ex ); } } /// /// Deserialize the specified object from stream using the encoding. /// /// Stream. /// Encoding. /// The 1st type parameter. public T Deserialize ( Stream stream, Encoding encoding ) { T result = default(T); try { XmlSerializer serializer = new XmlSerializer ( typeof ( T ) ); result = ( T )serializer.Deserialize ( stream ); } catch ( Exception ex ) { Debug.LogException ( ex ); } return result; } } }