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;