From bb0925b8730dd91593197b7b6fb6770652883467 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Thu, 10 Apr 2025 09:31:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=8E=B1=E5=8C=BB=E7=89=B9?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=AF=B9=E6=8E=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs | 21 +++++++++++++++---- .../Plugins/WebGL/GetParameters.jslib | 18 +++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs b/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs index 3f82b5fd..1607d79a 100644 --- a/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs +++ b/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs @@ -25,7 +25,7 @@ public class LYTWebGLHelper : MonoSingleton } #if UNITY_WEBGL [DllImport("__Internal")] - private static extern string GetURLParameter(string name); + private static extern IntPtr GetURLParameter(string name); #endif string token = string.Empty; @@ -42,9 +42,21 @@ public class LYTWebGLHelper : MonoSingleton } public void Init() { -#if UNITY_WEBGL&&!UNITY_EDITOR - token = GetURLParameter("token").Replace("%2B", "+"); +#if UNITY_WEBGL && !UNITY_EDITOR + + var paramPtr = GetURLParameter("token"); + if (paramPtr != IntPtr.Zero) + { + string value = Marshal.PtrToStringUTF8(paramPtr); + //token = value.Replace("%2B", "+"); + token = value.Replace(" ", "+"); + Marshal.FreeHGlobal(paramPtr); // ͷŷڴ + } + Debug.LogError("ȡģ" + token); #endif + + + RSA = Resources.Load("LYTWebGL/RSA"); if (string.IsNullOrEmpty(token) == false) { @@ -109,6 +121,7 @@ public class LYTWebGLHelper : MonoSingleton step.ExpStepName = stepNames[i]; step.maxScore = maxScore[i]; step.score = score[i]; + list.Add(step); } data.ExpStepVTwoList = list.ToArray(); @@ -122,7 +135,7 @@ public class LYTWebGLHelper : MonoSingleton Debug.LogError("ϴӿڵַ:" + uploadUrl); yield break; } - + Debug.LogError("ϴ:" + json); using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST")) { request.SetRequestHeader("Content-Type", "application/json"); diff --git a/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib index a460273f..5a076284 100644 --- a/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib +++ b/Assets/WebPlatform/Plugins/WebGL/GetParameters.jslib @@ -1,9 +1,17 @@ -// 名为 "URLParameters.jslib" 的插件文件 mergeInto(LibraryManager.library, { GetURLParameter: function (name) { - var search = window.location.search.substring(1); - var params = new URLSearchParams(search); - var value = params.get(name); - return value ? Pointer_stringify(value) : null; + const paramName = UTF8ToString(name); + const search = window.location.search.substring(1); + const params = new URLSearchParams(search); + const value = params.get(paramName); + console.log('GetURLParameter:', value); + + if (value) { + var buffer = _malloc((value.length + 1) * 2); + stringToUTF8(value, buffer, (value.length + 1) * 2); + return buffer; + } else { + return 0; + } } }); \ No newline at end of file