首页 > 编程语言 > 详细

Unity3D存储PlayerPrefs 用法

时间:2019-08-20 02:00:35      阅读:149      评论:0      收藏:0      [点我收藏+]
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 用法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!