From f6d3e5b55bc83f5c4dac20a75ba1949a59912a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=94=E6=9D=A1=E6=82=9F?= <1838407198@qq.com> Date: Wed, 13 Nov 2024 10:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B3=A8=E5=86=8C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TheStrongestSnail/Assets/Scenes/logo.unity | 10 +++-- .../Assets/Scripts/Login/UI/logoPanel.cs | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/TheStrongestSnail/Assets/Scenes/logo.unity b/TheStrongestSnail/Assets/Scenes/logo.unity index 7e5704a..2f714e2 100644 --- a/TheStrongestSnail/Assets/Scenes/logo.unity +++ b/TheStrongestSnail/Assets/Scenes/logo.unity @@ -1131,7 +1131,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 503.5, y: -1938.7665} + m_AnchoredPosition: {x: 503.5, y: -1061.7666} m_SizeDelta: {x: 911, y: 289.4} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &376604315 @@ -3538,7 +3538,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 686, y: -1387.5} + m_AnchoredPosition: {x: 686, y: -1389.0555} m_SizeDelta: {x: 1018, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1071890038 @@ -4627,7 +4627,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1789203778} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 8ee1a43c8ad7f8c41bad48013bf5af49, type: 3} m_Name: @@ -5765,6 +5765,9 @@ MonoBehaviour: userNameField: {fileID: 2007997901} passwordField: {fileID: 2068924169} verifyCodeField: {fileID: 345431930} + mmField: {fileID: 2068924169} + qrmmField: {fileID: 259615312} + yqmField: {fileID: 951076517} pwdBtn: {fileID: 1969202727} yzmBtn: {fileID: 622588872} regImg: {fileID: 382632865} @@ -5776,3 +5779,4 @@ MonoBehaviour: loginBtn: {fileID: 2003261318} regbtn: {fileID: 376604313} rigistBtn: {fileID: 855157915} + rigBtn: {fileID: 528990237} diff --git a/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs b/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs index 0f830f6..29e5aa5 100644 --- a/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs +++ b/TheStrongestSnail/Assets/Scripts/Login/UI/logoPanel.cs @@ -13,6 +13,9 @@ public class logoPanel : MonoBehaviour public InputField userNameField; public InputField passwordField; public InputField verifyCodeField; + public InputField mmField; + public InputField qrmmField; + public InputField yqmField; public Button pwdBtn; public Button yzmBtn; @@ -29,6 +32,10 @@ public class logoPanel : MonoBehaviour public GameObject regbtn; public Button rigistBtn; + public Button rigBtn; + + + public delegate void TokenReceivedDelegate(string token); public static event TokenReceivedDelegate OnTokenReceived; @@ -39,8 +46,44 @@ public class logoPanel : MonoBehaviour pwdBtn.onClick.AddListener(OnClickPwdBtn); loginBtn.onClick.AddListener(() => StartCoroutine(OnClickLoginBtn())); 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); + // 可在此处解析注册响应并进行后续处理 + // 比如解析返回的token并触发事件 + } + else + { + Debug.LogError("注册失败! " + webRequest.error); + } + } + } + private void OnClickRigistBtn() { yzm.gameObject.SetActive(true); @@ -54,6 +97,8 @@ public class logoPanel : MonoBehaviour yzmBtn.gameObject.SetActive(false); } + + //点击登录按钮 private IEnumerator OnClickLoginBtn() {