using UnityEngine;
using XGame.Framework.Json;
namespace XGame.Framework.Persistence
{
///
/// 数据持久化
///
public static class Persistence
{
public static bool Write(string key, object val)
{
PlayerPrefs.SetString(key, XJson.ToJson(val));
return true;
}
public static T Read(string key, T defaultValue)
{
if (!PlayerPrefs.HasKey(key))
{
return defaultValue;
}
string str = PlayerPrefs.GetString(key);
var val = XJson.ToObject(str);
return val;
}
public static void Delete(string key)
{
PlayerPrefs.DeleteKey(key);
}
public static void Clear()
{
PlayerPrefs.DeleteAll();
}
public static void Save()
{
PlayerPrefs.Save();
}
}
}