Merge branch 'NewMaster' into LouDi_Pig

This commit is contained in:
shenjianxing 2025-04-21 10:01:55 +08:00
commit 62c02bdaa3
27 changed files with 4612 additions and 111 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3e4645aaac3d48d4896ad6e7b2a1f1cc
PrefabImporter:
externalObjects: {}
userData:
assetBundleName: uiknowledge_prefab
assetBundleVariant:

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: b8dbba4c57255fc4495c422b41445cbe guid: d0622dae4bc2b2a4d937ad88a765e87a
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 72fe0ae24cde45946914fa10b54896b0 guid: 13457db631332b149901c3d79f802d84
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
userData: userData:

View File

@ -27,6 +27,7 @@ public class ActionHelper
{ "UI3DObjSelect", typeof(QFramework.Example.UI3DObjSelect) }, { "UI3DObjSelect", typeof(QFramework.Example.UI3DObjSelect) },
{ "UITextTip", typeof(QFramework.Example.UITextTip) }, { "UITextTip", typeof(QFramework.Example.UITextTip) },
{ "UITextWindow", typeof(QFramework.Example.UITextWindow) }, { "UITextWindow", typeof(QFramework.Example.UITextWindow) },
{ "UIKnowledge", typeof(QFramework.Example.UIKnowledge) },
}; };

View File

@ -1,7 +1,9 @@
using Newtonsoft.Json;
using QFramework; using QFramework;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.SocialPlatforms.Impl; using UnityEngine.SocialPlatforms.Impl;
@ -48,6 +50,29 @@ public class ScoreController : MonoSingleton<ScoreController>
} }
public string GetModuleDictJson(string name = "")
{
var resultDict = new Dictionary<string, object>();
resultDict.Add("name", name);
foreach (var dataPair in moduleDict)
{
var data = dataPair.Value;
if (data.scoreDict != null)
{
foreach (var scoreStepPair in data.scoreDict)
{
var scoreStep = scoreStepPair.Value;
string key = $"{scoreStep.step}{scoreStep.name}";
resultDict[key] = scoreStep.value;
resultDict.Add(key + "Time", string.IsNullOrEmpty(scoreStep.time) == true ? "" : scoreStep.time);
}
}
}
return JsonConvert.SerializeObject(resultDict);
}
private void OnStart(OnModuleStart start) private void OnStart(OnModuleStart start)
{ {
@ -84,6 +109,8 @@ public class ScoreController : MonoSingleton<ScoreController>
{ {
scoreDict[key].value = 0; scoreDict[key].value = 0;
} }
DateTime currentTime = DateTime.Now;
scoreDict[key].time = currentTime.ToString(scoreDict[key].timeFormat);
} }
else else
{ {

View File

@ -9,33 +9,76 @@ public class AsposeHelper : MonoBehaviour
{ {
//public static void Writer(string json, Action callback = null)
//{
// // 加载Word文档
// Document doc = new Document(Global.reportDemoPath);
// JObject jObject = JObject.Parse(json);
// foreach (JProperty property in jObject.Properties())
// {
// string key = property.Name;
// string value = property.Value.ToString();
// doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions());
// }
// string filePath = ChinarFileController.SaveProject(Path.GetFileName(Global.reportDemoPath).Split('.')[1]);
// if (string.IsNullOrEmpty(filePath) == false)
// {
// doc.Save(filePath);
// }
// callback?.Invoke();
// // 替换文本
// //SaveWithDialog(doc, callback);
// //Debug.Log("文档处理完成,新文档已保存到: " + outputFilePath);
//}
public static void Writer(string json, Action callback = null) public static void Writer(string json, Action callback = null)
{ {
// ¼ÓÔØWordÎĵµ // ¼ÓÔØWordÎĵµ
Document doc = new Document(Global.reportDemoPath); Document doc = new Document(Global.reportDemoPath);
JObject jObject = JObject.Parse(json); JToken jToken = JToken.Parse(json);
TraverseAndReplace(jToken, doc);
foreach (JProperty property in jObject.Properties()) string filePath = ChinarFileController.SaveProject(Path.GetFileName(Global.reportDemoPath).Split('.')[1]);
if (!string.IsNullOrEmpty(filePath))
{
doc.Save(filePath);
}
callback?.Invoke();
}
private static void TraverseAndReplace(JToken jToken, Document doc)
{
if (jToken.Type == JTokenType.Object)
{
foreach (JProperty property in ((JObject)jToken).Properties())
{
if (property.Value.Type == JTokenType.Object || property.Value.Type == JTokenType.Array)
{
TraverseAndReplace(property.Value, doc);
}
else
{ {
string key = property.Name; string key = property.Name;
string value = property.Value.ToString(); string value = property.Value.ToString();
doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions()); doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions());
} }
}
string filePath = ChinarFileController.SaveProject(Path.GetFileName(Global.reportDemoPath).Split('.')[1]); }
if (string.IsNullOrEmpty(filePath) == false) else if (jToken.Type == JTokenType.Array)
{ {
doc.Save(filePath); foreach (JToken item in jToken)
{
TraverseAndReplace(item, doc);
} }
callback?.Invoke();
// 替换文本
//SaveWithDialog(doc, callback);
//Debug.Log("文档处理完成,新文档已保存到: " + outputFilePath);
} }
}
//private static void SaveWithDialog(Document doc, Action<DialogResult> callback) //private static void SaveWithDialog(Document doc, Action<DialogResult> callback)
//{ //{

View File

@ -35,7 +35,6 @@ namespace QFramework.Example
{ {
Point.anchoredPosition = Utility.GetScreenPosByObj(transform as RectTransform); Point.anchoredPosition = Utility.GetScreenPosByObj(transform as RectTransform);
} }
} }
#endif #endif

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
@ -57,11 +58,7 @@ namespace QFramework.Example
public string GetScoreDataJson() public string GetScoreDataJson()
{ {
var data = new LabReprotData(); return ScoreController.Instance.GetModuleDictJson(InputName.text);
data.realname = InputName.text;
data.biaobencaiji_1_buzhou_1 = "[1111]";
string json = JsonConvert.SerializeObject(data);
return json;
} }
@ -87,7 +84,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 +98,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 +116,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)float.Parse(item.Value.sum));
scores.Add((int)item.Value.value);
} }
} }
} }
@ -122,6 +127,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

@ -135,11 +135,18 @@ namespace QFramework.Example
VideoContent.rectTransform.sizeDelta = mData.size; VideoContent.rectTransform.sizeDelta = mData.size;
} }
VideoContent.transform.localPosition = mData.offset; VideoContent.transform.localPosition = mData.offset;
string path = Global.videoPath + mData.url;
player.url = Global.videoPath + mData.url; if (string.IsNullOrEmpty(path) == false)
{
player.url = path;
player.Play(); player.Play();
SetImg(); SetImg();
} }
else
{
Debug.LogError("没有找到视频:" + path);
}
}
private void VideoPlayer_loopPointReached(UnityEngine.Video.VideoPlayer source) private void VideoPlayer_loopPointReached(UnityEngine.Video.VideoPlayer source)
{ {

View File

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

View File

@ -0,0 +1,67 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using QFramework;
namespace QFramework.Example
{
// Generate Id:d21887cc-bea5-4c87-8eae-a1d693d6555a
public partial class UIKnowledge
{
public const string Name = "UIKnowledge";
[SerializeField]
public UnityEngine.UI.Button CloseBtn;
[SerializeField]
public RectTransform LeftContent;
[SerializeField]
public UnityEngine.UI.ScrollRect Right;
[SerializeField]
public UnityEngine.UI.Image RightContent;
[SerializeField]
public RectTransform GlobalComs;
[SerializeField]
public RectTransform ItemComs;
[SerializeField]
public RectTransform LeftItem;
[SerializeField]
public UnityEngine.UI.Button BtnPrefab;
private UIKnowledgeData mPrivateData = null;
protected override void ClearUIComponents()
{
CloseBtn = null;
LeftContent = null;
Right = null;
RightContent = null;
GlobalComs = null;
ItemComs = null;
LeftItem = null;
BtnPrefab = null;
mData = null;
}
public UIKnowledgeData Data
{
get
{
return mData;
}
}
UIKnowledgeData mData
{
get
{
return mPrivateData ?? (mPrivateData = new UIKnowledgeData());
}
set
{
mUIData = value;
mPrivateData = value;
}
}
}
}

View File

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

View File

@ -0,0 +1,198 @@
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using TMPro;
using System.Collections.Generic;
using System;
namespace QFramework.Example
{
public class UIKnowledgeData : UIPanelData
{
public XMLTool.Knowledge knowledge;
}
public partial class UIKnowledge : UIPanel
{
ResLoader loader;
Dictionary<string, Sprite> sprites = new Dictionary<string, Sprite>();
IAction curAction;
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIKnowledgeData ?? new UIKnowledgeData();
// please add init code here
loader = ResLoader.Allocate();
CloseBtn.onClick.AddListener(() =>
{
Hide();
});
}
protected override void OnOpen(IUIData uiData = null)
{
if (Global.Instance.curModule.knowledge != null && Global.Instance.curModule.knowledge.items != null)
{
LeftContent.RemoveAllChildren();
string bg = Global.Instance.curModule.knowledge.bgImage;
LoadBgImage(bg, () =>
{
SetRightContentPos("");
RefreshComponents(Global.Instance.curModule.knowledge.components, GlobalComs);
});
foreach (var item in Global.Instance.curModule.knowledge.items)
{
ItemFactory(item);
}
}
}
public void ItemFactory(XMLTool.Knowledge.Item itemData, Transform parent = null)
{
Transform content = parent == null ? LeftContent : parent;
GameObject leftObj = GameObject.Instantiate(LeftItem.gameObject, content);
Transform subContent = leftObj.transform.Find("SubContent");
Toggle toggle = leftObj.transform.Find("Toggle").GetComponent<Toggle>();
TextMeshProUGUI label = toggle.transform.Find("Name").GetComponent<TextMeshProUGUI>();
label.text = itemData.title;
toggle.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
LoadBgImage(itemData.bgImage, () =>
{
SetRightContentPos(itemData.setPos);
});
ItemComs.RemoveAllChildren();
RefreshComponents(itemData.components, ItemComs);
}
if (subContent.childCount > 0)
{
subContent.gameObject.SetActive(isOn);
if (isOn)
{
subContent.GetChild(0).GetComponentInChildren<Toggle>().isOn = true;
}
}
else
{
label.color = isOn == true ? Color.blue : Color.black;
}
});
if (itemData.subs != null && itemData.subs.Count > 0)
{
foreach (var sub in itemData.subs)
{
ItemFactory(sub, subContent);
}
}
else
{
toggle.group = LeftContent.GetComponent<ToggleGroup>();
}
}
/// <summary>
/// ˢе±Ç°Ò³ÃæµÄ¹Ò¼þ
/// </summary>
public void RefreshComponents(List<XMLTool.Knowledge.Item.Component> coms, Transform content)
{
if (coms != null && coms.Count > 0)
{
foreach (var ComData in coms)
{
switch (ComData.type)
{
case "Button":
GameObject btn = GameObject.Instantiate(BtnPrefab.gameObject, content);
btn.GetComponent<RectTransform>().sizeDelta = Utility.GetVector2FromStrArray(ComData.size);
btn.transform.localPosition = Utility.GetVector2FromStrArray(ComData.pos);
btn.GetComponent<Button>().onClick.AddListener(() =>
{
if (curAction != null)
{
curAction.Deinit();
curAction = null;
}
curAction = ActionHelper.GetActionAndSub(ComData.action);
curAction.StartGlobal(() =>
{
curAction = null;
});
});
break;
}
}
}
}
public void LoadBgImage(string bg, Action callback = null)
{
if (string.IsNullOrEmpty(bg) == false)
{
if (sprites.ContainsKey(bg))
{
RightContent.sprite = sprites[bg];
RightContent.SetNativeSize();
callback?.Invoke();
}
else
{
var localImageUrl = Global.imagePath + bg;
loader.Add2Load(localImageUrl.ToNetImageResName(), (success, res) =>
{
if (success)
{
Sprite sprite = Utility.GetSprite(res.Asset.As<Texture2D>());
if (sprites.ContainsKey(bg) == false)
{
sprites.Add(bg, sprite);
}
}
});
TypeEventSystem.Global.Send<OnLoadingShow>();
loader.LoadAsync(() =>
{
callback?.Invoke();
RightContent.sprite = sprites[bg];
RightContent.SetNativeSize();
TypeEventSystem.Global.Send<OnLoadingHide>();
});
}
}
else
{
callback?.Invoke();
}
}
public void SetRightContentPos(string setPos)
{
Vector2 pos = default;
if (string.IsNullOrEmpty(setPos) == false)
{
pos = Utility.GetVector2FromStrArray(setPos);
}
RightContent.rectTransform.anchoredPosition = pos;
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
sprites.Clear();
loader.ReleaseAllRes();
}
}
}

View File

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

View File

@ -1,7 +1,12 @@
using QFramework;
using QFramework.Example; using QFramework.Example;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.Serialization;
using UnityEngine; using UnityEngine;
using static XMLTool.Body3D; using static XMLTool.Body3D;
namespace XMLTool namespace XMLTool
@ -38,6 +43,8 @@ namespace XMLTool
public Score score; public Score score;
public Body3D body3d; public Body3D body3d;
public Knowledge knowledge;
} }
public class Device public class Device
@ -67,6 +74,8 @@ namespace XMLTool
public string sum; public string sum;
public string bind; public string bind;
public float value; public float value;
public string time;
public string timeFormat = "yyyy-MM-dd HH:mm:ss";
} }
@ -207,6 +216,32 @@ namespace XMLTool
public string isOff; public string isOff;
} }
public class Knowledge
{
public class Item
{
public class Component
{
public string type;
public string size;
public string pos;
public Action action;
}
public string title;
public string bgImage;
public string setPos;
public List<Item> subs;
public List<Component> components;
}
public string bgImage;
public List<Item> items;
public List<Item.Component> components;
}
public class XmlParser public class XmlParser
{ {
public static AppData ParseXml(string xmlString) public static AppData ParseXml(string xmlString)
@ -382,6 +417,7 @@ namespace XMLTool
module.body3d.parts.Add(part.Name, part); module.body3d.parts.Add(part.Name, part);
} }
} }
// 解析评分
XElement scoreNode = moduleElement.Element("Score"); XElement scoreNode = moduleElement.Element("Score");
if (scoreNode != null) if (scoreNode != null)
{ {
@ -398,11 +434,70 @@ namespace XMLTool
name = item.Attribute("name")?.Value, name = item.Attribute("name")?.Value,
sum = item.Attribute("sum")?.Value, sum = item.Attribute("sum")?.Value,
bind = item.Attribute("bind")?.Value, bind = item.Attribute("bind")?.Value,
timeFormat = item.Attribute("timeFormat")?.Value,
}); });
} }
} }
// 解析知识点
var knowledge = moduleElement.Element("Knowledge");
if (knowledge != null)
{
module.knowledge = new Knowledge();
module.knowledge.bgImage = knowledge.Attribute("bgImage")?.Value;
foreach (var itemXml in knowledge.Elements("Item"))
{
Knowledge.Item item = ParserKnowledgeItem(itemXml);
if (module.knowledge.items == null)
{
module.knowledge.items = new List<Knowledge.Item>();
}
module.knowledge.items.Add(item);
}
module.knowledge.components = ParserKnowledgeComponet(knowledge);
} }
} }
}
private static Knowledge.Item ParserKnowledgeItem(XElement itemXml)
{
Knowledge.Item item = new Knowledge.Item();
item.title = itemXml.Attribute("title")?.Value;
item.bgImage = itemXml.Attribute("bgImage")?.Value;
item.setPos = itemXml.Attribute("setPos")?.Value;
item.components = ParserKnowledgeComponet(itemXml);
foreach (var subXml in itemXml.Elements("Item"))
{
if (item.subs == null)
{
item.subs = new List<Knowledge.Item>();
}
// 增加子物体
item.subs.Add(ParserKnowledgeItem(subXml));
}
return item;
}
private static List<Knowledge.Item.Component> ParserKnowledgeComponet(XElement xmlData)
{
List<Knowledge.Item.Component> list = null;
foreach (var componentXml in xmlData.Elements("Component"))
{
if (list == null)
{
list = new List<Knowledge.Item.Component>();
}
Knowledge.Item.Component component = new Knowledge.Item.Component();
component.type = componentXml.Attribute("type")?.Value;
component.pos = componentXml.Attribute("pos")?.Value;
component.size = componentXml.Attribute("size")?.Value;
component.action = ParseAction(componentXml.Element("Action"));
list.Add(component);
}
return list;
}
private static Body3D.Body ParseBody(XElement bodyElement, Body parent = null) private static Body3D.Body ParseBody(XElement bodyElement, Body parent = null)
{ {
Body3D.Body body = new Body3D.Body Body3D.Body body = new Body3D.Body

View File

@ -11,21 +11,22 @@ using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.Networking; using UnityEngine.Networking;
public class WebGLHelper : Singleton<WebGLHelper> public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
{ {
private WebGLHelper() { } private LYTWebGLHelper() { }
public class LabData public class LabData
{ {
public string GUID; public string GUID;
public string ExpID; public string ExpID;
public string HOST; public string HOST = string.Empty;
public string PARA1; public string PARA1;
public string PARA; public string PARA;
public string PARA2; public string PARA2;
} }
#if UNITY_WEBGL
[DllImport("__Internal")] [DllImport("__Internal")]
private static extern string GetURLParameter(string name); private static extern IntPtr GetURLParameter(string name);
#endif
string token = string.Empty; string token = string.Empty;
LabData labData = new LabData(); LabData labData = new LabData();
@ -35,10 +36,30 @@ public class WebGLHelper : Singleton<WebGLHelper>
public string uploadUrl; public string uploadUrl;
private void Awake()
{
Init();
}
public void Init() public void Init()
{ {
token = GetURLParameter("token").Replace("%2B", "+"); #if UNITY_WEBGL && !UNITY_EDITOR
RSA = Resources.Load<TextAsset>("RSA");
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<TextAsset>("LYTWebGL/RSA");
if (string.IsNullOrEmpty(token) == false)
{
string urlData = Decrypt(token); string urlData = Decrypt(token);
var datas = urlData.Split("&"); var datas = urlData.Split("&");
labData.GUID = datas[0]; labData.GUID = datas[0];
@ -47,7 +68,7 @@ public class WebGLHelper : Singleton<WebGLHelper>
labData.PARA1 = datas[3]; labData.PARA1 = datas[3];
labData.PARA = datas[4]; labData.PARA = datas[4];
labData.PARA2 = datas[5]; labData.PARA2 = datas[5];
}
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/"); uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
} }
/// <summary> /// <summary>
@ -87,7 +108,9 @@ public class WebGLHelper : Singleton<WebGLHelper>
{ {
var data = new UploadData(); var data = new UploadData();
data.GUID = labData.GUID; 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.score = totalScore;
data.flag = true; data.flag = true;
@ -98,20 +121,21 @@ public class WebGLHelper : Singleton<WebGLHelper>
step.ExpStepName = stepNames[i]; step.ExpStepName = stepNames[i];
step.maxScore = maxScore[i]; step.maxScore = maxScore[i];
step.score = score[i]; step.score = score[i];
list.Add(step);
} }
data.ExpStepVTwoList = list.ToArray(); data.ExpStepVTwoList = list.ToArray();
StartCoroutine(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))
{ {
Debug.LogError("上传接口地址错误:" + uploadUrl); Debug.LogError("上传接口地址错误:" + uploadUrl);
yield break; yield break;
} }
Debug.LogError("上传的数据:" + json);
using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST")) using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST"))
{ {
request.SetRequestHeader("Content-Type", "application/json"); request.SetRequestHeader("Content-Type", "application/json");
@ -122,6 +146,7 @@ public class WebGLHelper : Singleton<WebGLHelper>
if (request.result == UnityWebRequest.Result.ConnectionError || if (request.result == UnityWebRequest.Result.ConnectionError ||
request.result == UnityWebRequest.Result.ProtocolError) request.result == UnityWebRequest.Result.ProtocolError)
{ {
Debug.LogError($"Upload failed: {request.uri}");
Debug.LogError($"Upload failed: {request.error}"); Debug.LogError($"Upload failed: {request.error}");
Debug.LogError($"Response Code: {request.responseCode}"); Debug.LogError($"Response Code: {request.responseCode}");
} }
@ -132,17 +157,14 @@ 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 class UploadData
{
public string GUID { get; set; } public string GUID { get; set; }
// 实验 ID // 实验 ID
public int ExpID { get; set; } public int ExpID { get; set; }
@ -152,10 +174,10 @@ public class UploadData
public bool flag { get; set; } public bool flag { get; set; }
// 实验步骤列表 // 实验步骤列表
public Expstepvtwolist[] ExpStepVTwoList { get; set; } public Expstepvtwolist[] ExpStepVTwoList { get; set; }
} }
public class Expstepvtwolist public class Expstepvtwolist
{ {
// 实验步骤序号 // 实验步骤序号
public int seq { get; set; } public int seq { get; set; }
// 实验步骤名称 // 实验步骤名称
@ -180,10 +202,15 @@ public class Expstepvtwolist
public string scoringModel = ""; public string scoringModel = "";
// 备注 // 备注
public string remarks { get; set; } public string remarks { get; set; }
} }
public class Response public class Response
{ {
public string msg; public string msg;
public bool success; public bool success;
}
} }

View File

@ -1,9 +1,17 @@
// 名为 "URLParameters.jslib" 的插件文件
mergeInto(LibraryManager.library, { mergeInto(LibraryManager.library, {
GetURLParameter: function (name) { GetURLParameter: function (name) {
var search = window.location.search.substring(1); const paramName = UTF8ToString(name);
var params = new URLSearchParams(search); const search = window.location.search.substring(1);
var value = params.get(name); const params = new URLSearchParams(search);
return value ? Pointer_stringify(value) : null; 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;
}
} }
}); });

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:

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 MiB

View File

@ -337,6 +337,45 @@
</Step> </Step>
</Operation> </Operation>
<!--知识点
title对应左侧树状图的名字
bgImage是右侧的长图
Component是长图上挂在的组件 目前仅支持Type=Button的按钮类型
Action是动作组 点击按钮后的动作
Component标签与bgImage属性 可以在根节点Knowledge上也可以在子节点Item上
位于根节点时 是全局的 位于Item节点时是切换Item后展示的针对与Item的
-->
<Knowledge bgImage="Knowledge/ChangTu.png">
<Item title="第一步" setPos="0,0">
<Item title="第一步_第一个子步骤" bgImage="" setPos="0,100">
<Component type="Button" size="200,200" pos="200,-200">
<Action type="Log" value="第二步_第二个子步骤"></Action>
</Component>
<Component type="Button" size="200,200" pos="400,-200">
<Action type="Log" value="第二步_第二个子步骤"></Action>
</Component>
</Item>
</Item>
<Item title="第二步" setPos="0,400">
<Item title="第二步_第一个子步骤" bgImage="" setPos="0,500">
<Component type="Button" size="200,200" pos="200,-400">
<Action type="Log" value="第二步_第二个子步骤"></Action>
</Component>
<Component type="Button" size="200,200" pos="400,-400">
<Action type="Log" value="第二步_第二个子步骤"></Action>
</Component>
</Item>
<Item title="第二步_第二个子步骤" bgImage="" setPos="0,600"></Item>
</Item>
<Component type="Button" size="932,526" pos="20,-9653">
<Action type="Sequence">
<Action type="Log" value="第一步_第一个子步骤"></Action>
<Action type="Video" value="test.mp4" size="500,500" offset="10,10" finishedEvent="finished" closeEvent="close"></Action>
</Action>
</Component>
</Knowledge>
<!--动作组--> <!--动作组-->
<Action name="初始化" type="Sequence"> <Action name="初始化" type="Sequence">
@ -385,9 +424,9 @@
<Action type="Log" value="ddd"></Action> <Action type="Log" value="ddd"></Action>
</Action> </Action>
</Exit> </Exit>
</State>--> </State>
<Transision from="any" to="状态1"> <Transision from="any" to="状态1">
<Condition type="ObjClick" value="Cube"></Condition> <Condition type="UIClick" value="Cube"></Condition>
</Transision> </Transision>
<Transision from="初始状态" to="状态2"> <Transision from="初始状态" to="状态2">
<Condition type="ObjClick" value="Cube (1)"></Condition> <Condition type="ObjClick" value="Cube (1)"></Condition>

View File

@ -971,4 +971,4 @@ PlayerSettings:
hmiLoadingImage: {fileID: 0} hmiLoadingImage: {fileID: 0}
platformRequiresReadableAssets: 0 platformRequiresReadableAssets: 0
virtualTexturingSupportEnabled: 0 virtualTexturingSupportEnabled: 0
insecureHttpOption: 0 insecureHttpOption: 2