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() { } //点击登录按钮 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登录:" + 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); } }