_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs
2024-11-25 23:58:19 +08:00

187 lines
5.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using static LoginAndGetToken;
using System.Threading.Tasks;
public class logoPanel : Base
{
public InputField userNameField;
public InputField passwordField;
public InputField verifyCodeField;
public InputField mmField;
public InputField qrmmField;
public InputField yqmField;
public Button pwdBtn;
public Button yzmBtn;
public Image regImg;
public GameObject yzm;
public GameObject mm;
public GameObject qrmm;
public GameObject yqm;
public GameObject logBtn;
public Button loginBtn;
public GameObject regbtn;
public Button rigistBtn;
public Button rigBtn;
public delegate void TokenReceivedDelegate(string token);
public static event TokenReceivedDelegate OnTokenReceived;
private bool isOpenYzm = true;
private bool isOpenPwd = false;
void Start()
{
yzmBtn.onClick.AddListener(OnClickYzmBtn);
pwdBtn.onClick.AddListener(OnClickPwdBtn);
rigistBtn.onClick.AddListener(OnClickRigistBtn);
rigBtn.onClick.AddListener(() => StartCoroutine(OnClickRegBtn()));
}
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"))
{
webRequest.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonBody));
webRequest.uploadHandler.contentType = "application/json";
webRequest.downloadHandler = new DownloadHandlerBuffer();
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.Success)
{
string registerResponse = webRequest.downloadHandler.text;
Debug.Log("Register Response: " + registerResponse);
SceneManager.LoadScene(1);
// <20><><EFBFBD><EFBFBD><EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else
{
Debug.LogError(<><D7A2>ʧ<EFBFBD>ܣ<EFBFBD> " + webRequest.error);
}
}
}
public async void OnClickLoginBtnAsync()
{
loginbody body = new loginbody
{
userName = userNameField.text,
password = passwordField.text,
verifyCode = int.Parse(verifyCodeField.text)
};
//loginbody body = new loginbody
//{
// userName = "15151658596",
// password = "123456",
// verifyCode = 111111
//};
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;
}
Debug.Log(response.code);
}
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);
}
private void OnClickYzmBtn()
{
if(isOpenYzm)
{
return;
}
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;
}
private void OnClickPwdBtn()
{
if (isOpenPwd)
{
return;
}
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;
}
// <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;
}
[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;
}
}