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

112 lines
3.3 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;
using static LoginAndGetToken;
public class logoPanel : MonoBehaviour
{
public InputField userNameField;
public InputField passwordField;
public InputField verifyCodeField;
2024-11-11 19:48:32 +08:00
public Button pwdBtn;
public Button yzmBtn;
public Image regImg;
2024-11-11 19:48:32 +08:00
public GameObject yzm;
public GameObject mm;
public GameObject qrmm;
public GameObject yqm;
public GameObject logBtn;
2024-11-11 19:48:32 +08:00
public Button loginBtn;
public GameObject regbtn;
2024-11-11 19:48:32 +08:00
public Button rigistBtn;
2024-11-11 19:48:32 +08:00
public delegate void TokenReceivedDelegate(string token);
public static event TokenReceivedDelegate OnTokenReceived;
// Start is called before the first frame update
void Start()
{
yzmBtn.onClick.AddListener(OnClickYzmBtn);
pwdBtn.onClick.AddListener(OnClickPwdBtn);
loginBtn.onClick.AddListener(() => StartCoroutine(OnClickLoginBtn()));
rigistBtn.onClick.AddListener(OnClickRigistBtn);
}
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
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ť
private IEnumerator OnClickLoginBtn()
{
loginbody body = new loginbody
{
userName = userNameField.text,
password = passwordField.text,
verifyCode = int.Parse(verifyCodeField.text)
2024-11-11 19:48:32 +08:00
};
string jsonBody = JsonUtility.ToJson(body);
using (UnityWebRequest webRequest = new UnityWebRequest("http://121.40.42.41:8080/snail/user/login", "POST"))
2024-11-11 19:48:32 +08:00
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-11 19:48:32 +08:00
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
webRequest.uploadHandler.contentType = "application/json";
2024-11-11 19:48:32 +08:00
webRequest.downloadHandler = new DownloadHandlerBuffer();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-11 19:48:32 +08:00
yield return webRequest.SendWebRequest();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-11 19:48:32 +08:00
if (webRequest.result == UnityWebRequest.Result.Success)
{
string loginResponse = webRequest.downloadHandler.text;
Debug.Log("LoginAndGetToken<65><6E>¼:" + loginResponse);
string token = getToken(loginResponse);
OnTokenReceived?.Invoke(token);
}
else
{
Debug.LogError("Error: " + webRequest.error);
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ť
2024-11-11 19:48:32 +08:00
private void OnClickYzmBtn()
{
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);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ť
2024-11-11 19:48:32 +08:00
private void OnClickPwdBtn()
{
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);
}
2024-11-11 19:48:32 +08:00
}