You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
951 B
33 lines
951 B
using System;
|
|
using System.Xml.Serialization;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
namespace WriteReadXML
|
|
{
|
|
public class WriteRead_XML
|
|
{
|
|
public static void write<T>(string file_name, T t)
|
|
{
|
|
StreamWriter file = new StreamWriter(file_name);
|
|
XmlSerializer _serializer = new XmlSerializer(typeof(T));
|
|
_serializer.Serialize(file, t);
|
|
file.Close();
|
|
}
|
|
public static T read<T>(string file_name)
|
|
{
|
|
T result = default(T);
|
|
try
|
|
{
|
|
StreamReader file = new StreamReader(file_name);
|
|
XmlSerializer _serializer = new XmlSerializer(typeof(T));
|
|
result = (T)_serializer.Deserialize(file);
|
|
file.Close();
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
Debug.LogWarning(err.StackTrace);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
|