_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs

201 lines
6.1 KiB
C#
Raw Normal View History

2024-11-11 19:48:32 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
2024-11-13 23:15:46 +08:00
using UnityEngine.SceneManagement;
2024-11-11 19:48:32 +08:00
using static LoginAndGetToken;
2024-11-15 23:31:54 +08:00
using System.Threading.Tasks;
2024-11-11 19:48:32 +08:00
2024-11-25 23:58:19 +08:00
public class logoPanel : Base
2024-11-11 19:48:32 +08:00
{
public InputField userNameField;
public InputField passwordField;
public InputField verifyCodeField;
2024-11-13 10:28:08 +08:00
public InputField mmField;
public InputField qrmmField;
public InputField yqmField;
2024-11-15 23:31:54 +08:00
2024-11-11 19:48:32 +08:00
public Button pwdBtn;
public Button yzmBtn;
public Image regImg;
2024-11-15 23:31:54 +08:00
2024-11-11 19:48:32 +08:00
public GameObject yzm;
public GameObject mm;
public GameObject qrmm;
public GameObject yqm;
public GameObject logBtn;
[Header("<22><>¼<EFBFBD><C2BC>ť")] public Button loginBtn;
public GameObject regbtn;
2024-11-11 19:48:32 +08:00
public Button rigistBtn;
[Header("<22><>֤<EFBFBD>밴ť")] public Button GetVerificationCode;
[Header("ע<>ᰴť")] public Button rigBtn;
2024-11-13 10:28:08 +08:00
2024-11-11 19:48:32 +08:00
public delegate void TokenReceivedDelegate(string token);
public static event TokenReceivedDelegate OnTokenReceived;
private bool isOpenYzm = true;
private bool isOpenPwd = false;
2024-11-11 19:48:32 +08:00
void Start()
{
yzmBtn.onClick.AddListener(OnClickYzmBtn);
pwdBtn.onClick.AddListener(OnClickPwdBtn);
rigistBtn.onClick.AddListener(OnClickRigistBtn);
rigBtn.onClick.AddListener(OnClickRegBtn);
2024-11-15 23:31:54 +08:00
AddingAButtonEvent(GetVerificationCode);
AddingAButtonEvent(loginBtn);
AddingAButtonEvent(rigBtn);
2024-11-13 10:28:08 +08:00
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
/// </summary>
/// <returns></returns>
public async void OnClickRegBtn()
2024-11-15 23:31:54 +08:00
{
loginbody body = new loginbody();
body.userName = userNameField.text;
body.password = passwordField.text;
if (!string.IsNullOrWhiteSpace(verifyCodeField.text))
2024-11-28 07:59:58 +08:00
{
body.verifyCode = int.Parse(verifyCodeField.text);
}
string loginResponse = await web.SendRequest(web.URL + "/snail/user/register", "POST", JsonUtility.ToJson(body));
Debug.Log(loginResponse);
ServerResponse response = JsonUtility.FromJson<ServerResponse>(loginResponse);
if (response.code == 200)
{
SceneManager.LoadScene(1);
}
else
{
addEventPopUp(response.message);
}
}
/// <summary>
/// <20><><EFBFBD>õ<EFBFBD>¼
/// </summary>
public async void OnClickLoginBtnAsync()
{
//loginbody body = new loginbody();
//body.userName = userNameField.text;
//body.password = passwordField.text;
//if (!string.IsNullOrWhiteSpace(verifyCodeField.text))
//{
// body.verifyCode = int.Parse(verifyCodeField.text);
//}
loginbody body = new loginbody
{
userName = "15151658596",
password = "123456",
verifyCode = 111111
};
2024-11-15 23:31:54 +08:00
string loginResponse = await web.SendRequest(web.URL+"/snail/user/login", "POST", JsonUtility.ToJson(body));
ServerResponse response = JsonUtility.FromJson<ServerResponse>(loginResponse);
if (response != null && response.code == 200 && response.data != null)
{
Global.global.serverResponse = response;
SceneManager.LoadScene(1);
return;
}
else
{
addEventPopUp(response.message);
}
2024-11-15 23:31:54 +08:00
}
2024-11-11 19:48:32 +08:00
private void OnClickRigistBtn()
{
yzm.gameObject.SetActive(true);
mm.gameObject.SetActive(true);
qrmm.gameObject.SetActive(true);
yqm.gameObject.SetActive(true);
logBtn.gameObject.SetActive(false);
regbtn.gameObject.SetActive(true);
regImg.gameObject.SetActive(true);
pwdBtn.gameObject.SetActive(false);
yzmBtn.gameObject.SetActive(false);
2024-11-11 19:48:32 +08:00
}
private void OnClickYzmBtn()
{
if(isOpenYzm)
{
return;
}
2024-11-11 19:48:32 +08:00
pwdBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position += new Vector3(0f, 26.4f, 0f);
yzm.gameObject.SetActive(true);
mm.gameObject.SetActive(false);
isOpenYzm = true;
isOpenPwd = false;
2024-11-11 19:48:32 +08:00
}
private void OnClickPwdBtn()
{
if (isOpenPwd)
{
return;
}
2024-11-11 19:48:32 +08:00
pwdBtn.transform.position += new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
yzm.gameObject.SetActive(false);
mm.gameObject.SetActive(true);
isOpenPwd = true;
isOpenYzm = false;
2024-11-11 19:48:32 +08:00
}
2024-11-15 23:31:54 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>ݽṹ
[System.Serializable]
public class ServerResponse
{
public int code;
public string message;
public Data data;
public override string ToString()
{
return $"{nameof(code)}: {code}, {nameof(message)}: {message}, {nameof(data)}: {data}";
}
2024-11-15 23:31:54 +08:00
}
[System.Serializable]
public class Data
{
public int userId;
public string userName;
public string token;
public string nickName;
public string headImg;
public string gender;
public string birthday;
public int? voluteCoin;
public int? beansCoin;
public int? ichorCoin;
public string idCard;
public string inviteCodeMy;
public string inviteCodeBind;
public string bindTime;
public string station;
public string cuteNo;
public string memberTime;
public bool? isMember;
public override string ToString()
{
return
$"{nameof(userId)}: {userId}, {nameof(userName)}: {userName}, {nameof(token)}: {token}, {nameof(nickName)}: {nickName}, {nameof(headImg)}: {headImg}, {nameof(gender)}: {gender}, {nameof(birthday)}: {birthday}, {nameof(voluteCoin)}: {voluteCoin}, {nameof(beansCoin)}: {beansCoin}, {nameof(ichorCoin)}: {ichorCoin}, {nameof(idCard)}: {idCard}, {nameof(inviteCodeMy)}: {inviteCodeMy}, {nameof(inviteCodeBind)}: {inviteCodeBind}, {nameof(bindTime)}: {bindTime}, {nameof(station)}: {station}, {nameof(cuteNo)}: {cuteNo}, {nameof(memberTime)}: {memberTime}, {nameof(isMember)}: {isMember}";
}
2024-11-15 23:31:54 +08:00
}
}