132 lines
3.5 KiB
C#
132 lines
3.5 KiB
C#
using UnityEngine;
|
|
|
|
|
|
public static class PlayerPrefsKit
|
|
{
|
|
public static void WriteInt(string key, int data)
|
|
{
|
|
PlayerPrefs.SetInt(key, data);
|
|
}
|
|
|
|
// public static void WriteBool(string key, bool data)
|
|
// {
|
|
// PlayerPrefs.SetInt(key, data ? PrefsConst.IntTrue : PrefsConst.IntFalse);
|
|
// }
|
|
|
|
public static void WriteString(string key, string data)
|
|
{
|
|
PlayerPrefs.SetString(key, data);
|
|
}
|
|
|
|
// public static void WriteObject(string key, object data)
|
|
// {
|
|
// string dataStr = SerializeUtil.ToJson(data);
|
|
// PlayerPrefs.SetString(key, dataStr);
|
|
// }
|
|
|
|
// public static int ReadInt(string key, int defalutValue = PrefsConst.IntDefault)
|
|
// {
|
|
// int data = PlayerPrefs.GetInt(key, defalutValue);
|
|
// return data;
|
|
// }
|
|
|
|
// public static bool ReadBool(string key, bool defalutValue = PrefsConst.BoolDefault)
|
|
// {
|
|
// if (!HasKey(key))
|
|
// {
|
|
// return defalutValue;
|
|
// }
|
|
|
|
// bool data = PlayerPrefs.GetInt(key) == PrefsConst.IntTrue ? true : false;
|
|
// return data;
|
|
// }
|
|
|
|
public static string ReadString(string key)
|
|
{
|
|
string data = PlayerPrefs.GetString(key, string.Empty);
|
|
return data;
|
|
}
|
|
|
|
// public static object ReadObject<T>(string key)
|
|
// {
|
|
// if (!HasKey(key))
|
|
// {
|
|
// return null;
|
|
// }
|
|
|
|
// string dataStr = PlayerPrefs.GetString(key);
|
|
// if (string.IsNullOrEmpty(dataStr))
|
|
// {
|
|
// return null;
|
|
// }
|
|
|
|
// T data = SerializeUtil.ToObject<T>(dataStr);
|
|
// return data;
|
|
// }
|
|
|
|
// public static T ReadTObject<T>(string key)
|
|
// {
|
|
// if (!HasKey(key))
|
|
// {
|
|
// return default(T);
|
|
// }
|
|
|
|
// string dataStr = PlayerPrefs.GetString(key);
|
|
// if (string.IsNullOrEmpty(dataStr))
|
|
// {
|
|
// return default(T);
|
|
// }
|
|
|
|
// T data = SerializeUtil.ToObject<T>(dataStr);
|
|
// return data;
|
|
// }
|
|
|
|
public static bool HasKey(string key)
|
|
{
|
|
return PlayerPrefs.HasKey(key);
|
|
}
|
|
|
|
public static void DeleteKey(string key)
|
|
{
|
|
if (HasKey(key))
|
|
{
|
|
PlayerPrefs.DeleteKey(key);
|
|
}
|
|
}
|
|
|
|
public static void DeleteAll()
|
|
{
|
|
PlayerPrefs.DeleteAll();
|
|
}
|
|
|
|
#region Float Double
|
|
|
|
public static float ReadFloat(string key, float defaultValue = 0)
|
|
{
|
|
return PlayerPrefs.GetFloat(key, defaultValue);
|
|
}
|
|
|
|
public static void WriteFloat(string key, float data)
|
|
{
|
|
PlayerPrefs.SetFloat(key, data);
|
|
}
|
|
|
|
public static double ReadDouble(string key, double defaultValue = 0)
|
|
{
|
|
string strValue = PlayerPrefs.GetString(key, string.Empty);
|
|
if (string.IsNullOrEmpty(strValue))
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
return System.Convert.ToDouble(strValue, System.Globalization.CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
public static void WriteDouble(string key, double data)
|
|
{
|
|
PlayerPrefs.SetString(key, data.ToString());
|
|
}
|
|
|
|
#endregion
|
|
}
|