码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D存储PlayerPrefs 用法

时间:2019-08-20 01:30:16      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:using   engine   ref   pre   EDA   data   unit   iter   oid   

using UnityEngine;
using System.Xml.Serialization;
using System.IO;
public class StateStorage{
public static T LoadData( 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( 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 );
}
}

 

Unity3D存储PlayerPrefs 用法

标签:using   engine   ref   pre   EDA   data   unit   iter   oid   

原文地址:https://www.cnblogs.com/allyh/p/11380464.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!