201 lines
6.1 KiB
C#
201 lines
6.1 KiB
C#
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;
|
|
[Header("登录按钮")] public Button loginBtn;
|
|
public GameObject regbtn;
|
|
public Button rigistBtn;
|
|
|
|
[Header("验证码按钮")] public Button GetVerificationCode;
|
|
[Header("注册按钮")] 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(OnClickRegBtn);
|
|
|
|
AddingAButtonEvent(GetVerificationCode);
|
|
AddingAButtonEvent(loginBtn);
|
|
AddingAButtonEvent(rigBtn);
|
|
}
|
|
/// <summary>
|
|
/// 调用注册
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async void OnClickRegBtn()
|
|
{
|
|
loginbody body = new loginbody();
|
|
body.userName = userNameField.text;
|
|
body.password = passwordField.text;
|
|
if (!string.IsNullOrWhiteSpace(verifyCodeField.text))
|
|
{
|
|
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>
|
|
/// 调用登录
|
|
/// </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 = "123698745",
|
|
//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;
|
|
}
|
|
else
|
|
{
|
|
addEventPopUp(response.message);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// 服务器返回的数据结构
|
|
[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}";
|
|
}
|
|
}
|
|
|
|
[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}";
|
|
}
|
|
}
|
|
}
|
|
|