Merge branch 'NewMaster' into LouDi_Pig
This commit is contained in:
commit
62c02bdaa3
2465
Assets/Art/UIPrefab/UIKnowledge.prefab
Normal file
2465
Assets/Art/UIPrefab/UIKnowledge.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Art/UIPrefab/UIKnowledge.prefab.meta
Normal file
7
Assets/Art/UIPrefab/UIKnowledge.prefab.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e4645aaac3d48d4896ad6e7b2a1f1cc
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName: uiknowledge_prefab
|
||||
assetBundleVariant:
|
||||
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8dbba4c57255fc4495c422b41445cbe
|
||||
guid: d0622dae4bc2b2a4d937ad88a765e87a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
7
Assets/Resources/LYTWebGL/RSA.txt.meta
Normal file
7
Assets/Resources/LYTWebGL/RSA.txt.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa05fa85bd33f6c4ca626c1e0317d53d
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1439
Assets/Scenes/TestUIPanels/TestUIKnowledge.unity
Normal file
1439
Assets/Scenes/TestUIPanels/TestUIKnowledge.unity
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72fe0ae24cde45946914fa10b54896b0
|
||||
guid: 13457db631332b149901c3d79f802d84
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
@ -27,6 +27,7 @@ public class ActionHelper
|
||||
{ "UI3DObjSelect", typeof(QFramework.Example.UI3DObjSelect) },
|
||||
{ "UITextTip", typeof(QFramework.Example.UITextTip) },
|
||||
{ "UITextWindow", typeof(QFramework.Example.UITextWindow) },
|
||||
{ "UIKnowledge", typeof(QFramework.Example.UIKnowledge) },
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using QFramework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
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)
|
||||
{
|
||||
@ -84,6 +109,8 @@ public class ScoreController : MonoSingleton<ScoreController>
|
||||
{
|
||||
scoreDict[key].value = 0;
|
||||
}
|
||||
DateTime currentTime = DateTime.Now;
|
||||
scoreDict[key].time = currentTime.ToString(scoreDict[key].timeFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -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)
|
||||
{
|
||||
// ¼ÓÔØWordÎĵµ
|
||||
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 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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
//{
|
||||
|
||||
@ -35,7 +35,6 @@ namespace QFramework.Example
|
||||
{
|
||||
Point.anchoredPosition = Utility.GetScreenPosByObj(transform as RectTransform);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@ -57,11 +58,7 @@ namespace QFramework.Example
|
||||
|
||||
public string GetScoreDataJson()
|
||||
{
|
||||
var data = new LabReprotData();
|
||||
data.realname = InputName.text;
|
||||
data.biaobencaiji_1_buzhou_1 = "[1111]";
|
||||
string json = JsonConvert.SerializeObject(data);
|
||||
return json;
|
||||
return ScoreController.Instance.GetModuleDictJson(InputName.text);
|
||||
}
|
||||
|
||||
|
||||
@ -87,7 +84,9 @@ namespace QFramework.Example
|
||||
onlyCur = mData.onlyCurModule;
|
||||
}
|
||||
|
||||
|
||||
List<string> stepNames = new List<string>();
|
||||
List<int> maxScore = new List<int>();
|
||||
List<int> scores = new List<int>();
|
||||
if (onlyCur)
|
||||
{
|
||||
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();
|
||||
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));
|
||||
scores.Add((int)item.Value.value);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -114,6 +116,9 @@ namespace QFramework.Example
|
||||
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
||||
sum += float.Parse(item.Value.sum);
|
||||
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.Sum.text = sum.ToString();
|
||||
|
||||
//#if UNITY_WEBGL
|
||||
// LYTWebGLHelper.Instance.UpLoadData((int)score, stepNames, maxScore, scores);
|
||||
//#endif
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
|
||||
@ -135,11 +135,18 @@ namespace QFramework.Example
|
||||
VideoContent.rectTransform.sizeDelta = mData.size;
|
||||
}
|
||||
VideoContent.transform.localPosition = mData.offset;
|
||||
|
||||
player.url = Global.videoPath + mData.url;
|
||||
string path = Global.videoPath + mData.url;
|
||||
if (string.IsNullOrEmpty(path) == false)
|
||||
{
|
||||
player.url = path;
|
||||
player.Play();
|
||||
SetImg();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("没有找到视频:" + path);
|
||||
}
|
||||
}
|
||||
|
||||
private void VideoPlayer_loopPointReached(UnityEngine.Video.VideoPlayer source)
|
||||
{
|
||||
|
||||
8
Assets/Scripts/UILongPicture.meta
Normal file
8
Assets/Scripts/UILongPicture.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 762d12b9d2c220c46afe6eb3eda2e85c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/Scripts/UILongPicture/UIKnowledge.Designer.cs
generated
Normal file
67
Assets/Scripts/UILongPicture/UIKnowledge.Designer.cs
generated
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UILongPicture/UIKnowledge.Designer.cs.meta
Normal file
11
Assets/Scripts/UILongPicture/UIKnowledge.Designer.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a5d5c0eba3097b48b9c67e7e229ccee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
198
Assets/Scripts/UILongPicture/UIKnowledge.cs
Normal file
198
Assets/Scripts/UILongPicture/UIKnowledge.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UILongPicture/UIKnowledge.cs.meta
Normal file
11
Assets/Scripts/UILongPicture/UIKnowledge.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd25ee86b2071da4aa68360bc13232e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,7 +1,12 @@
|
||||
using QFramework;
|
||||
using QFramework.Example;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
using static XMLTool.Body3D;
|
||||
namespace XMLTool
|
||||
@ -38,6 +43,8 @@ namespace XMLTool
|
||||
public Score score;
|
||||
|
||||
public Body3D body3d;
|
||||
|
||||
public Knowledge knowledge;
|
||||
}
|
||||
|
||||
public class Device
|
||||
@ -67,6 +74,8 @@ namespace XMLTool
|
||||
public string sum;
|
||||
public string bind;
|
||||
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 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 static AppData ParseXml(string xmlString)
|
||||
@ -382,6 +417,7 @@ namespace XMLTool
|
||||
module.body3d.parts.Add(part.Name, part);
|
||||
}
|
||||
}
|
||||
// 解析评分
|
||||
XElement scoreNode = moduleElement.Element("Score");
|
||||
if (scoreNode != null)
|
||||
{
|
||||
@ -398,11 +434,70 @@ namespace XMLTool
|
||||
name = item.Attribute("name")?.Value,
|
||||
sum = item.Attribute("sum")?.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)
|
||||
{
|
||||
Body3D.Body body = new Body3D.Body
|
||||
|
||||
@ -11,21 +11,22 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class WebGLHelper : Singleton<WebGLHelper>
|
||||
public class LYTWebGLHelper : MonoSingleton<LYTWebGLHelper>
|
||||
{
|
||||
private WebGLHelper() { }
|
||||
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);
|
||||
|
||||
private static extern IntPtr GetURLParameter(string name);
|
||||
#endif
|
||||
string token = string.Empty;
|
||||
|
||||
LabData labData = new LabData();
|
||||
@ -35,10 +36,30 @@ public class WebGLHelper : Singleton<WebGLHelper>
|
||||
|
||||
public string uploadUrl;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
token = GetURLParameter("token").Replace("%2B", "+");
|
||||
RSA = Resources.Load<TextAsset>("RSA");
|
||||
#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<TextAsset>("LYTWebGL/RSA");
|
||||
if (string.IsNullOrEmpty(token) == false)
|
||||
{
|
||||
string urlData = Decrypt(token);
|
||||
var datas = urlData.Split("&");
|
||||
labData.GUID = datas[0];
|
||||
@ -47,7 +68,7 @@ public class WebGLHelper : Singleton<WebGLHelper>
|
||||
labData.PARA1 = datas[3];
|
||||
labData.PARA = datas[4];
|
||||
labData.PARA2 = datas[5];
|
||||
|
||||
}
|
||||
uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/");
|
||||
}
|
||||
/// <summary>
|
||||
@ -87,7 +108,9 @@ public class WebGLHelper : Singleton<WebGLHelper>
|
||||
{
|
||||
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;
|
||||
|
||||
@ -98,20 +121,21 @@ public class WebGLHelper : Singleton<WebGLHelper>
|
||||
step.ExpStepName = stepNames[i];
|
||||
step.maxScore = maxScore[i];
|
||||
step.score = score[i];
|
||||
list.Add(step);
|
||||
}
|
||||
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))
|
||||
{
|
||||
Debug.LogError("ÉÏ´«½Ó¿ÚµØÖ·´íÎó:" + uploadUrl);
|
||||
yield break;
|
||||
}
|
||||
|
||||
Debug.LogError("上传的数据:" + json);
|
||||
using (UnityWebRequest request = new UnityWebRequest(uploadUrl, "POST"))
|
||||
{
|
||||
request.SetRequestHeader("Content-Type", "application/json");
|
||||
@ -122,6 +146,7 @@ public class WebGLHelper : Singleton<WebGLHelper>
|
||||
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}");
|
||||
}
|
||||
@ -132,14 +157,11 @@ public class WebGLHelper : Singleton<WebGLHelper>
|
||||
Debug.Log($"Server Response: {request.downloadHandler.text}");
|
||||
Response response = JsonConvert.DeserializeObject<Response>(request.downloadHandler.text);
|
||||
Debug.LogError(response.msg);
|
||||
action?.Invoke(response.msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class UploadData
|
||||
{
|
||||
@ -187,3 +209,8 @@ public class Response
|
||||
public string msg;
|
||||
public bool success;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
||||
23
Assets/WebPlatform/WebTest.cs
Normal file
23
Assets/WebPlatform/WebTest.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/WebPlatform/WebTest.cs.meta
Normal file
11
Assets/WebPlatform/WebTest.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08f51ad357b70604492d4c3e95ce1e27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Data/Image/Knowledge/ChangTu.png
Normal file
BIN
Data/Image/Knowledge/ChangTu.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.3 MiB |
@ -337,6 +337,45 @@
|
||||
</Step>
|
||||
</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">
|
||||
@ -385,9 +424,9 @@
|
||||
<Action type="Log" value="ddd"></Action>
|
||||
</Action>
|
||||
</Exit>
|
||||
</State>-->
|
||||
</State>
|
||||
<Transision from="any" to="状态1">
|
||||
<Condition type="ObjClick" value="Cube"></Condition>
|
||||
<Condition type="UIClick" value="Cube"></Condition>
|
||||
</Transision>
|
||||
<Transision from="初始状态" to="状态2">
|
||||
<Condition type="ObjClick" value="Cube (1)"></Condition>
|
||||
|
||||
@ -971,4 +971,4 @@ PlayerSettings:
|
||||
hmiLoadingImage: {fileID: 0}
|
||||
platformRequiresReadableAssets: 0
|
||||
virtualTexturingSupportEnabled: 0
|
||||
insecureHttpOption: 0
|
||||
insecureHttpOption: 2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user