登录保留上次的账号
This commit is contained in:
parent
4e4fe3bfd9
commit
d4b6a1c663
23
xiaofang/Assets/Script/loginScripts/AccountManager.cs
Normal file
23
xiaofang/Assets/Script/loginScripts/AccountManager.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class AccountManager : MonoBehaviour
|
||||
{
|
||||
private const string AccountKey = "LastLoggedAccount";
|
||||
|
||||
// 保存账号名
|
||||
public static void SaveLastLoggedAccount(string accountName)
|
||||
{
|
||||
PlayerPrefs.SetString(AccountKey, accountName);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
// 获取上次登录的账号名
|
||||
public static string GetLastLoggedAccount()
|
||||
{
|
||||
return PlayerPrefs.GetString(AccountKey, null); // 默认值为 null,如果没有保存过的账号名
|
||||
}
|
||||
}
|
11
xiaofang/Assets/Script/loginScripts/AccountManager.cs.meta
Normal file
11
xiaofang/Assets/Script/loginScripts/AccountManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf09cb5642c570843b317a6c507757f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -17,10 +17,19 @@ public class LoginPanel : Base
|
||||
public InputField sjh;
|
||||
public InputField yzm;
|
||||
public Image image;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
string lastAccount = AccountManager.GetLastLoggedAccount();
|
||||
if (lastAccount != null)
|
||||
{
|
||||
Debug.Log($"上次登录的账号是: {lastAccount}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("没有找到上次登录的账号.");
|
||||
}
|
||||
loginBtn.onClick.AddListener(OnClickLoginBtn);
|
||||
getYzmBtn.onClick.AddListener(OnClickGetYzmBtn);
|
||||
image.gameObject.SetActive(false);
|
||||
@ -39,6 +48,7 @@ public class LoginPanel : Base
|
||||
//登录逻辑
|
||||
public async void Login()
|
||||
{
|
||||
|
||||
|
||||
// 创建登录请求的 body
|
||||
auth_login loginBody = new auth_login
|
||||
@ -58,6 +68,8 @@ public class LoginPanel : Base
|
||||
// 解析服务器返回的数据
|
||||
loginResponse serverData = JsonConvert.DeserializeObject<loginResponse>(response);
|
||||
|
||||
AccountManager.SaveLastLoggedAccount(loginBody.username);
|
||||
|
||||
// 将登录响应数据保存到静态变量中
|
||||
GlobalData.ServerData = serverData;
|
||||
ReadRoom.instance.ID = id.text;
|
||||
|
Loading…
Reference in New Issue
Block a user