using Newtonsoft.Json; using TMPro; using UnityEngine; namespace QFramework.Example { public class UIScoreData : UIPanelData { } public partial class UIScore : UIPanel { protected override void OnInit(IUIData uiData = null) { mData = uiData as UIScoreData ?? new UIScoreData(); TypeEventSystem.Global.Register((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject); DownLoad.onClick.AddListener(() => { if (string.IsNullOrEmpty(InputName.text) || string.IsNullOrEmpty(InputId.text)) { Debug.LogError("姓名或者学号为空"); return; } #if UNITY_WEBGL ResLoader loader = ResLoader.Allocate(); loader.Add2Load(Global.reportDemoPath.ToLocalBytesResName(), (success, res) => { if (success) { byte[] bytes = res.As().bytes; WebGLDownLoadFile.Instance.DownloadDocx(bytes, GetScoreDataJson()); } }); loader.LoadAsync(); #elif UNITY_STANDALONE_WIN AsposeHelper.Writer(GetScoreDataJson()); #endif }); Confirm.onClick.AddListener(Hide); } public string GetScoreDataJson() { var data = new LabReprotData(); data.realname = InputName.text; data.biaobencaiji_1_buzhou_1 = "[1111]"; string json = JsonConvert.SerializeObject(data); return json; } protected override void OnOpen(IUIData uiData = null) { Content.RemoveAllChildren(); float sum = 0; float score = 0; foreach (var moduleDict in ScoreController.Instance.moduleDict) { foreach (var item in moduleDict.Value.scoreDict) { GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content); obj.transform.Find("Step").GetComponent().text = item.Value.step; obj.transform.Find("Name").GetComponent().text = item.Value.name; obj.transform.Find("Sum").GetComponent().text = item.Value.sum; obj.transform.Find("Score").GetComponent().text = item.Value.value.ToString(); sum += float.Parse(item.Value.sum); score += item.Value.value; } } this.Score.text = score.ToString(); this.Sum.text = sum.ToString(); } protected override void OnShow() { } protected override void OnHide() { } protected override void OnClose() { } } }