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
|
|
|
|
|
{
|
2024-11-11 21:03:06 +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-12 11:06:38 +08:00
|
|
|
|
|
2024-11-11 19:48:32 +08:00
|
|
|
|
public Button pwdBtn;
|
|
|
|
|
public Button yzmBtn;
|
2024-11-12 11:06:38 +08:00
|
|
|
|
public Image regImg;
|
|
|
|
|
|
2024-11-11 19:48:32 +08:00
|
|
|
|
public GameObject yzm;
|
|
|
|
|
public GameObject mm;
|
2024-11-12 11:06:38 +08:00
|
|
|
|
public GameObject qrmm;
|
|
|
|
|
public GameObject yqm;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject logBtn;
|
2024-11-11 19:48:32 +08:00
|
|
|
|
public Button loginBtn;
|
2024-11-12 11:06:38 +08:00
|
|
|
|
public GameObject regbtn;
|
2024-11-11 19:48:32 +08:00
|
|
|
|
public Button rigistBtn;
|
2024-11-12 11:06:38 +08:00
|
|
|
|
|
2024-11-13 10:28:08 +08:00
|
|
|
|
public Button rigBtn;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-13 10:28:08 +08:00
|
|
|
|
rigBtn.onClick.AddListener(() => StartCoroutine(OnClickRegBtn()));
|
2024-11-11 19:48:32 +08:00
|
|
|
|
}
|
2024-11-12 11:06:38 +08:00
|
|
|
|
|
2024-11-13 10:28:08 +08:00
|
|
|
|
public IEnumerator OnClickRegBtn()
|
|
|
|
|
{
|
|
|
|
|
loginbody body = new loginbody
|
|
|
|
|
{
|
|
|
|
|
userName = userNameField.text,
|
|
|
|
|
password = passwordField.text,
|
|
|
|
|
verifyCode = int.Parse(verifyCodeField.text)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string jsonBody = JsonUtility.ToJson(body);
|
|
|
|
|
using (UnityWebRequest webRequest = new UnityWebRequest("http://121.40.42.41:8080/snail/user/register", "POST"))
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
|
|
|
|
|
webRequest.uploadHandler.contentType = "application/json";
|
|
|
|
|
webRequest.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
yield return webRequest.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (webRequest.result == UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
string registerResponse = webRequest.downloadHandler.text;
|
|
|
|
|
Debug.Log("Register Response: " + registerResponse);
|
|
|
|
|
// <20><><EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>token<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("ע<><D7A2>ʧ<EFBFBD>ܣ<EFBFBD> " + webRequest.error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 19:48:32 +08:00
|
|
|
|
private void OnClickRigistBtn()
|
|
|
|
|
{
|
2024-11-12 11:06:38 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 10:28:08 +08:00
|
|
|
|
|
|
|
|
|
|
2024-11-11 19:48:32 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ť
|
|
|
|
|
private IEnumerator OnClickLoginBtn()
|
|
|
|
|
{
|
|
|
|
|
loginbody body = new loginbody
|
|
|
|
|
{
|
2024-11-11 21:03:06 +08:00
|
|
|
|
userName = userNameField.text,
|
|
|
|
|
password = passwordField.text,
|
|
|
|
|
verifyCode = int.Parse(verifyCodeField.text)
|
2024-11-11 19:48:32 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string jsonBody = JsonUtility.ToJson(body);
|
2024-11-12 11:06:38 +08:00
|
|
|
|
using (UnityWebRequest webRequest = new UnityWebRequest("http://121.40.42.41:8080/snail/user/login", "POST"))
|
2024-11-11 19:48:32 +08:00
|
|
|
|
{
|
2024-11-12 11:06:38 +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));
|
2024-11-12 11:06:38 +08:00
|
|
|
|
webRequest.uploadHandler.contentType = "application/json";
|
2024-11-11 19:48:32 +08:00
|
|
|
|
webRequest.downloadHandler = new DownloadHandlerBuffer();
|
2024-11-12 11:06:38 +08:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-11-11 19:48:32 +08:00
|
|
|
|
yield return webRequest.SendWebRequest();
|
|
|
|
|
|
2024-11-12 11:06:38 +08:00
|
|
|
|
// <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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 11:06:38 +08:00
|
|
|
|
//<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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 11:06:38 +08:00
|
|
|
|
//<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-12 11:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
2024-11-11 19:48:32 +08:00
|
|
|
|
}
|