91 lines
2.8 KiB
C#
91 lines
2.8 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 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()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ť
|
|||
|
private IEnumerator OnClickLoginBtn()
|
|||
|
{
|
|||
|
loginbody body = new loginbody
|
|||
|
{
|
|||
|
userName = "15151658596",
|
|||
|
password = "123456",
|
|||
|
verifyCode = 111111
|
|||
|
};
|
|||
|
|
|||
|
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<65><6E>¼:" + loginResponse);
|
|||
|
string token = getToken(loginResponse);
|
|||
|
OnTokenReceived?.Invoke(token);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("Error: " + webRequest.error);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>밴ť
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>밴ť
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|