_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs
五条悟 ed7788d6fb Merge branch 'main' of http://sheziwanglo.cn:3000/hyskai/_TheStrongestSnail
# Conflicts:
#	TheStrongestSnail/Assets/Scenes/logo.unity
2024-11-11 21:03:06 +08:00

94 lines
2.9 KiB
C#

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;
public Button pwdBtn;
public Button yzmBtn;
public GameObject sjh;
public GameObject yzm;
public GameObject mm;
public GameObject zh;
public Button loginBtn;
public Button rigistBtn;
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);
}
private void OnClickRigistBtn()
{
}
//µã»÷µÇ¼°´Å¥
private IEnumerator OnClickLoginBtn()
{
loginbody body = new loginbody
{
userName = userNameField.text,
password = passwordField.text,
verifyCode = int.Parse(verifyCodeField.text)
};
string jsonBody = JsonUtility.ToJson(body);
using (UnityWebRequest webRequest = UnityWebRequest.Post("http://121.40.42.41:8080/snail/user/login", jsonBody))
{
webRequest.SetRequestHeader("Content-Type", "application/json");
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
webRequest.downloadHandler = new DownloadHandlerBuffer();
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
string loginResponse = webRequest.downloadHandler.text;
Debug.Log("LoginAndGetToken怬:" + loginResponse);
string token = getToken(loginResponse);
OnTokenReceived?.Invoke(token);
}
else
{
Debug.LogError("Error: " + webRequest.error);
}
}
}
//µã»÷ÑéÖ¤Âë°´Å¥
private void OnClickYzmBtn()
{
pwdBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position += new Vector3(0f, 26.4f, 0f);
sjh.gameObject.SetActive(true);
yzm.gameObject.SetActive(true);
mm.gameObject.SetActive(false);
zh.gameObject.SetActive(false);
}
//µã»÷ÃÜÂë°´Å¥
private void OnClickPwdBtn()
{
pwdBtn.transform.position += new Vector3(0f, 26.4f, 0f);
yzmBtn.transform.position -= new Vector3(0f, 26.4f, 0f);
sjh.gameObject.SetActive(false);
yzm.gameObject.SetActive(false);
mm.gameObject.SetActive(true);
zh.gameObject.SetActive(true);
}
}