50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace BallKingdomCrush
|
|
{
|
|
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 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 bool HasKey(string key)
|
|
{
|
|
return PlayerPrefs.HasKey(key);
|
|
}
|
|
}
|
|
} |