From c3f56cb8ca87f18d865d572f0ff89c2f304747d3 Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Thu, 2 Jan 2025 16:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=BF=9D=E7=95=99=E4=B8=8A?= =?UTF-8?q?=E6=AC=A1=E7=99=BB=E5=BD=95=E7=9A=84=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaofang/Assets/Script/loginScripts/AccountManager.cs | 4 ++-- xiaofang/Assets/Script/loginScripts/LoginPanel.cs | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/xiaofang/Assets/Script/loginScripts/AccountManager.cs b/xiaofang/Assets/Script/loginScripts/AccountManager.cs index 860f4f35..f851ab55 100644 --- a/xiaofang/Assets/Script/loginScripts/AccountManager.cs +++ b/xiaofang/Assets/Script/loginScripts/AccountManager.cs @@ -12,12 +12,12 @@ public class AccountManager : MonoBehaviour public static void SaveLastLoggedAccount(string accountName) { PlayerPrefs.SetString(AccountKey, accountName); - PlayerPrefs.Save(); + //PlayerPrefs.Save(); } // 获取上次登录的账号名 public static string GetLastLoggedAccount() { - return PlayerPrefs.GetString(AccountKey, null); // 默认值为 null,如果没有保存过的账号名 + return PlayerPrefs.GetString(AccountKey,string.Empty); } } diff --git a/xiaofang/Assets/Script/loginScripts/LoginPanel.cs b/xiaofang/Assets/Script/loginScripts/LoginPanel.cs index ae6e9e8b..386e45d2 100644 --- a/xiaofang/Assets/Script/loginScripts/LoginPanel.cs +++ b/xiaofang/Assets/Script/loginScripts/LoginPanel.cs @@ -22,9 +22,13 @@ public class LoginPanel : Base void Start() { string lastAccount = AccountManager.GetLastLoggedAccount(); + + id.text = lastAccount; + Debug.Log("存储数据"+lastAccount); if (lastAccount != null) { Debug.Log($"上次登录的账号是: {lastAccount}"); + } else { @@ -60,6 +64,9 @@ public class LoginPanel : Base password = pwd.text//"YYL5371!" }; image.gameObject.SetActive (true); + //保存登录的账号 + AccountManager.SaveLastLoggedAccount(id.text); + // 发送请求 Debug.Log("登陆入参"+ 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(response); - AccountManager.SaveLastLoggedAccount(loginBody.username); + // 将登录响应数据保存到静态变量中 GlobalData.ServerData = serverData;