完善平台对接代码

This commit is contained in:
shenjianxing 2025-04-09 13:59:32 +08:00
parent b8abfa3c44
commit c7d31c23f2
4 changed files with 65 additions and 59 deletions

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
@ -87,7 +88,9 @@ namespace QFramework.Example
onlyCur = mData.onlyCurModule; onlyCur = mData.onlyCurModule;
} }
List<string> stepNames = new List<string>();
List<int> maxScore = new List<int>();
List<int> scores = new List<int>();
if (onlyCur) if (onlyCur)
{ {
foreach (var item in ScoreController.Instance.GetCurScoreData()) foreach (var item in ScoreController.Instance.GetCurScoreData())
@ -99,6 +102,9 @@ namespace QFramework.Example
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString(); obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
sum += float.Parse(item.Value.sum); sum += float.Parse(item.Value.sum);
score += item.Value.value; score += item.Value.value;
stepNames.Add(item.Value.step + item.Value.name);
maxScore.Add(int.Parse(item.Value.sum));
scores.Add((int)item.Value.value);
} }
} }
else else
@ -114,6 +120,9 @@ namespace QFramework.Example
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString(); obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
sum += float.Parse(item.Value.sum); sum += float.Parse(item.Value.sum);
score += item.Value.value; score += item.Value.value;
stepNames.Add(item.Value.step + item.Value.name);
maxScore.Add(int.Parse(item.Value.sum));
scores.Add((int)item.Value.value);
} }
} }
} }
@ -122,6 +131,9 @@ namespace QFramework.Example
this.Score.text = score.ToString(); this.Score.text = score.ToString();
this.Sum.text = sum.ToString(); this.Sum.text = sum.ToString();
//#if UNITY_WEBGL
// LYTWebGLHelper.Instance.UpLoadData((int)score, stepNames, maxScore, scores);
//#endif
} }
protected override void OnShow() protected override void OnShow()

View File

@ -11,9 +11,9 @@ using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.Networking; using UnityEngine.Networking;
public class WebGLHelper : Singleton<WebGLHelper> public class LYTWebGLHelper : Singleton<LYTWebGLHelper>
{ {
private WebGLHelper() { } private LYTWebGLHelper() { }
public class LabData public class LabData
{ {
public string GUID; public string GUID;
@ -101,10 +101,10 @@ public class WebGLHelper : Singleton<WebGLHelper>
} }
data.ExpStepVTwoList = list.ToArray(); data.ExpStepVTwoList = list.ToArray();
SendScore(JsonConvert.SerializeObject(data));
} }
IEnumerator SendScore(string json, UnityAction<string> action) IEnumerator SendScore(string json, UnityAction<string> action = null)
{ {
if (string.IsNullOrEmpty(uploadUrl)) if (string.IsNullOrEmpty(uploadUrl))
{ {
@ -132,58 +132,60 @@ public class WebGLHelper : Singleton<WebGLHelper>
Debug.Log($"Server Response: {request.downloadHandler.text}"); Debug.Log($"Server Response: {request.downloadHandler.text}");
Response response = JsonConvert.DeserializeObject<Response>(request.downloadHandler.text); Response response = JsonConvert.DeserializeObject<Response>(request.downloadHandler.text);
Debug.LogError(response.msg); Debug.LogError(response.msg);
action?.Invoke(response.msg);
} }
} }
} }
public class UploadData
{
public string GUID { get; set; }
// 实验 ID
public int ExpID { get; set; }
// 成绩
public int score { get; set; }
// 标志位:默认值 true
public bool flag { get; set; }
// 实验步骤列表
public Expstepvtwolist[] ExpStepVTwoList { get; set; }
}
public class Expstepvtwolist
{
// 实验步骤序号
public int seq { get; set; }
// 实验步骤名称
public string ExpStepName = "";
// 实验步骤状态
public string StepState = "";
// 实验步骤开始时间
public DateTime startTime = default;
// 实验步骤结束时间
public DateTime endTime = default;
// 实验步骤合理用时:单位秒
public int expectTime = 0;
// 实验步骤满分0 ~100百分制
public int maxScore = 100;
// 实验步骤得分0 ~100百分制
public int score = 0;
// 实验步骤操作次数
public int repeatCount = 1;
// 步骤评价200 字以内
public string evaluation = "";
// 赋分模型200 字以内
public string scoringModel = "";
// 备注
public string remarks { get; set; }
}
public class Response
{
public string msg;
public bool success;
}
} }
public class UploadData
{
public string GUID { get; set; }
// 实验 ID
public int ExpID { get; set; }
// 成绩
public int score { get; set; }
// 标志位:默认值 true
public bool flag { get; set; }
// 实验步骤列表
public Expstepvtwolist[] ExpStepVTwoList { get; set; }
}
public class Expstepvtwolist
{
// 实验步骤序号
public int seq { get; set; }
// 实验步骤名称
public string ExpStepName = "";
// 实验步骤状态
public string StepState = "";
// 实验步骤开始时间
public DateTime startTime = default;
// 实验步骤结束时间
public DateTime endTime = default;
// 实验步骤合理用时:单位秒
public int expectTime = 0;
// 实验步骤满分0 ~100百分制
public int maxScore = 100;
// 实验步骤得分0 ~100百分制
public int score = 0;
// 实验步骤操作次数
public int repeatCount = 1;
// 步骤评价200 字以内
public string evaluation = "";
// 赋分模型200 字以内
public string scoringModel = "";
// 备注
public string remarks { get; set; }
}
public class Response
{
public string msg;
public bool success;
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b8dbba4c57255fc4495c422b41445cbe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: