修改web平台对接逻辑

This commit is contained in:
shenjianxing 2025-04-09 15:46:56 +08:00
parent c7d31c23f2
commit 2ae75e1664
7 changed files with 71 additions and 17 deletions

View File

@ -1,5 +1,6 @@
fileFormatVersion: 2
guid: 72fe0ae24cde45946914fa10b54896b0
guid: d0622dae4bc2b2a4d937ad88a765e87a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fa05fa85bd33f6c4ca626c1e0317d53d
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -121,7 +121,7 @@ namespace QFramework.Example
sum += float.Parse(item.Value.sum);
score += item.Value.value;
stepNames.Add(item.Value.step + item.Value.name);
maxScore.Add(int.Parse(item.Value.sum));
maxScore.Add((int)float.Parse(item.Value.sum));
scores.Add((int)item.Value.value);
}
}

View File

@ -11,21 +11,22 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
{
private LYTWebGLHelper() { }
public class LabData
{
public string GUID;
public string ExpID;
public string HOST;
public string HOST = string.Empty;
public string PARA1;
public string PARA;
public string PARA2;
}
#if UNITY_WEBGL
[DllImport("__Internal")]
private static extern string GetURLParameter(string name);
#endif
string token = string.Empty;
LabData labData = new LabData();
@ -35,10 +36,18 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
public string uploadUrl;
private void Awake()
{
Init();
}
public void Init()
{
#if UNITY_WEBGL&&!UNITY_EDITOR
token = GetURLParameter("token").Replace("%2B", "+");
RSA = Resources.Load<TextAsset>("RSA");
#endif
RSA = Resources.Load<TextAsset>("LYTWebGL/RSA");
if (string.IsNullOrEmpty(token) == false)
{
string urlData = Decrypt(token);
var datas = urlData.Split("&");
labData.GUID = datas[0];
@ -47,7 +56,7 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
labData.PARA1 = datas[3];
labData.PARA = datas[4];
labData.PARA2 = datas[5];
}
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
}
/// <summary>
@ -87,7 +96,9 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
{
var data = new UploadData();
data.GUID = labData.GUID;
data.ExpID = int.Parse(labData.ExpID);
int expId = 0;
int.TryParse(labData.ExpID, out expId);
data.ExpID = expId;
data.score = totalScore;
data.flag = true;
@ -101,7 +112,7 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
}
data.ExpStepVTwoList = list.ToArray();
SendScore(JsonConvert.SerializeObject(data));
StartCoroutine(SendScore(JsonConvert.SerializeObject(data)));
}
IEnumerator SendScore(string json, UnityAction<string> action = null)
@ -122,6 +133,7 @@ public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
if (request.result == UnityWebRequest.Result.ConnectionError ||
request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError($"Upload failed: {request.uri}");
Debug.LogError($"Upload failed: {request.error}");
Debug.LogError($"Response Code: {request.responseCode}");
}

View File

@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WebTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
List<string> stepNames = new List<string>() { "µÚÒ»²½", "µÚ¶þ²½", "µÚÈý²½" };
List<int> maxScore = new List<int>() { 10, 20, 30 };
List<int> score = new List<int>() { 5, 10, 15 };
LYTWebGLHelper.Instance.UpLoadData(60, stepNames, maxScore, score);
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08f51ad357b70604492d4c3e95ce1e27
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: