登录保留上次登录的账号
This commit is contained in:
parent
d4b6a1c663
commit
c3f56cb8ca
@ -12,12 +12,12 @@ public class AccountManager : MonoBehaviour
|
|||||||
public static void SaveLastLoggedAccount(string accountName)
|
public static void SaveLastLoggedAccount(string accountName)
|
||||||
{
|
{
|
||||||
PlayerPrefs.SetString(AccountKey, accountName);
|
PlayerPrefs.SetString(AccountKey, accountName);
|
||||||
PlayerPrefs.Save();
|
//PlayerPrefs.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取上次登录的账号名
|
// 获取上次登录的账号名
|
||||||
public static string GetLastLoggedAccount()
|
public static string GetLastLoggedAccount()
|
||||||
{
|
{
|
||||||
return PlayerPrefs.GetString(AccountKey, null); // 默认值为 null,如果没有保存过的账号名
|
return PlayerPrefs.GetString(AccountKey,string.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,13 @@ public class LoginPanel : Base
|
|||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
string lastAccount = AccountManager.GetLastLoggedAccount();
|
string lastAccount = AccountManager.GetLastLoggedAccount();
|
||||||
|
|
||||||
|
id.text = lastAccount;
|
||||||
|
Debug.Log("存储数据"+lastAccount);
|
||||||
if (lastAccount != null)
|
if (lastAccount != null)
|
||||||
{
|
{
|
||||||
Debug.Log($"上次登录的账号是: {lastAccount}");
|
Debug.Log($"上次登录的账号是: {lastAccount}");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -60,6 +64,9 @@ public class LoginPanel : Base
|
|||||||
password = pwd.text//"YYL5371!"
|
password = pwd.text//"YYL5371!"
|
||||||
};
|
};
|
||||||
image.gameObject.SetActive (true);
|
image.gameObject.SetActive (true);
|
||||||
|
//保存登录的账号
|
||||||
|
AccountManager.SaveLastLoggedAccount(id.text);
|
||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
Debug.Log("登陆入参"+ JsonUtility.ToJson(loginBody));
|
Debug.Log("登陆入参"+ JsonUtility.ToJson(loginBody));
|
||||||
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody));
|
string response = await web.SendRequest(web.URL + "/auth/login", "POST", JsonUtility.ToJson(loginBody));
|
||||||
@ -68,7 +75,7 @@ public class LoginPanel : Base
|
|||||||
// 解析服务器返回的数据
|
// 解析服务器返回的数据
|
||||||
loginResponse serverData = JsonConvert.DeserializeObject<loginResponse>(response);
|
loginResponse serverData = JsonConvert.DeserializeObject<loginResponse>(response);
|
||||||
|
|
||||||
AccountManager.SaveLastLoggedAccount(loginBody.username);
|
|
||||||
|
|
||||||
// 将登录响应数据保存到静态变量中
|
// 将登录响应数据保存到静态变量中
|
||||||
GlobalData.ServerData = serverData;
|
GlobalData.ServerData = serverData;
|
||||||
|
Loading…
Reference in New Issue
Block a user