AkiraPixelWind/Assets/Scripts/Main/LocalStorage/LocalStorage.cs

87 lines
2.3 KiB
C#
Raw Normal View History

2022-12-29 18:20:40 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LocalStorage
{
public static readonly LocalStorage Instance = new LocalStorage();
private string user = string.Empty; // <20>˺<EFBFBD>
private string pid = string.Empty; // <20><><EFBFBD><EFBFBD>ID
// <20><><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD>
public void SetUser(string _user)
{
user = _user;
}
// <20><><EFBFBD>ý<EFBFBD>ɫ
public void SetPid(string _pid)
{
pid = _pid;
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>˺Ž<CBBA>ɫ<EFBFBD><C9AB><EFBFBD>ص<EFBFBD>key, <20>Ա<EFBFBD>֤<EFBFBD><D6A4><EFBFBD>ػ<EFBFBD><D8BB>治ͬ<E6B2BB>˺Ų<CBBA>ͬ<EFBFBD><CDAC>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺źͽ<C5BA>ɫǰ, key<65><79>һ<EFBFBD>µ<EFBFBD>
private string GetRoleKey(string _key)
{
return user + "_" + pid + _key;
}
public bool HasKey(string _key)
{
string key = GetRoleKey(_key);
return PlayerPrefs.HasKey(key);
}
// <20><><EFBFBD><EFBFBD>ֵ
public void SetString(string _key, string _val)
{
if(string.IsNullOrEmpty(_key))
{
Debug.LogError("SetVal. string.IsNullOrEmpty(_key)");
return;
}
string key = GetRoleKey(_key);
PlayerPrefs.SetString(key, _val.Trim());
PlayerPrefs.Save();
}
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ
public int GetInt(string _key)
{
string key = GetRoleKey(_key);
string retStr = PlayerPrefs.GetString(key, "0");
return int.Parse(retStr.Trim());
}
// <20><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ֵ
public string GetString(string _key)
{
string key = GetRoleKey(_key);
string retStr = PlayerPrefs.GetString(key, "");
return retStr;
}
public void DeleteKey(string _key)
{
string key = GetRoleKey(_key);
PlayerPrefs.DeleteKey(key);
}
/// <summary>
/// <20><><EFBFBD>ػ<EFBFBD><D8BB><EFBFBD>Key<65><79><EFBFBD><EFBFBD>
/// </summary>
//public static readonly string KeyLoginUser = "LoginUser"; // <20><>¼<EFBFBD>˺<EFBFBD>
public static readonly string KeyLoginUserPhone = "LoginUserPhone"; // <20><>¼<EFBFBD>˺<EFBFBD>_<EFBFBD>ֻ<EFBFBD><D6BB>˺<EFBFBD>
//public static readonly string KeyLoginPwd = "LoginPwd"; // <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
public static readonly string KeyLoginLastSelectIdx = "KeyLoginLastSelectIdx"; // <20>ϴ<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>Ľ<EFBFBD>ɫ
public static readonly string KeyLoginLastLoginType = "KeyLoginLastLoginType"; // <20>ϴε<CFB4>¼<EFBFBD>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD>
public static readonly string KeyLoginQuickItemIDList = "KeyLoginQuickItemIDList"; // <20><><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>id<69><64>
}