- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
using UnityEngine;
using System.Xml.Serialization;
using System.IO;
public class StateStorage{
public static T LoadData<T>( string key ){
if ( PlayerPrefs.HasKey( key ) ) {
XmlSerializer serializer = new XmlSerializer( typeof( T ) );
StringReader sr = new StringReader( PlayerPrefs.GetString( key ) );
return ( T )serializer.Deserialize( sr );
}else{
return default(T);
}
}
public static void SaveData<T>( string key, T source ){
XmlSerializer serializer = new XmlSerializer( typeof( T ) );
StringWriter sw = new StringWriter();
serializer.Serialize( sw, source );
PlayerPrefs.SetString( key, sw.ToString() );
}
public static void ClearData( string key ){
PlayerPrefs.DeleteKey( key );
}
} |
|