diff --git a/Assets/Scripts/Controller/ScoreController.cs b/Assets/Scripts/Controller/ScoreController.cs index 546d008c..32a51452 100644 --- a/Assets/Scripts/Controller/ScoreController.cs +++ b/Assets/Scripts/Controller/ScoreController.cs @@ -1,12 +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; using XMLTool; public class ScoreController : MonoSingleton diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs index f8a93a76..bf304845 100644 --- a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DateManager.cs @@ -1,8 +1,10 @@ using System; +using System.Collections; using System.IO; using TMPro; using UnityEngine; using UnityEngine.Events; +using UnityEngine.Networking; using UnityEngine.UI; public class DateManager : MonoBehaviour @@ -19,10 +21,14 @@ public class DateManager : MonoBehaviour { Application.Quit(); }); - UpdateTime(ShowTip, ShowTip, () => +#if UNITY_WEBGL + StartCoroutine(WebUpdateTime()); +#else + UpdateTime(DecryptFileReader.ReadAndDecryptData("Timer.txt"), ShowTip, ShowTip, () => { gameObject.SetActive(false); }); +#endif } public void ShowTip(string str) @@ -32,14 +38,35 @@ public class DateManager : MonoBehaviour text.text = str; } + public IEnumerator WebUpdateTime() + { + string path = Path.Combine(Application.streamingAssetsPath, "Timer.txt"); + using (UnityWebRequest request = new UnityWebRequest(path)) + { + request.downloadHandler = new DownloadHandlerBuffer(); + yield return request.SendWebRequest(); + if (string.IsNullOrEmpty(request.error)) + { + string datas = DecryptFileReader.ReadAndDecryptData(request.downloadHandler.data); + UpdateTime(datas, ShowTip, ShowTip, () => + { + gameObject.SetActive(false); + }); + } + else + { + Debug.LogError(request.error); + } + } + } + /// /// 更新系统时间 /// - public void UpdateTime(UnityAction error = null, UnityAction timeOut = null, UnityAction updateTimer = null) + public void UpdateTime(string datas, UnityAction error = null, UnityAction timeOut = null, UnityAction updateTimer = null) { try { - string datas = DecryptFileReader.ReadAndDecryptData("Timer.txt"); EndTimer = datas.Split('|')[0]; RecordData = datas.Split('|')[1]; //第一次获取获取系统时间 @@ -54,11 +81,13 @@ public class DateManager : MonoBehaviour } else { +#if !UNITY_WEBGL //把上一次存储得系统时间更新到最新 string timer = "Timer.txt"; RecordData = Data; string strMerge = EndTimer + "|" + RecordData; EncryptFileCreator.EncryptAndSaveData(strMerge, timer); +#endif updateTimer?.Invoke(); } } diff --git a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs index 1c6d60f5..744b1ab2 100644 --- a/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs +++ b/Assets/Scripts/Tools/ZXKLicenses/Encryption/DecryptFileReader.cs @@ -14,6 +14,12 @@ public class DecryptFileReader if (File.Exists(filePath)) return ""; // 读取加密文件 byte[] encryptedData = File.ReadAllBytes(fullPath); + return ReadAndDecryptData(encryptedData); + } + + + public static string ReadAndDecryptData(byte[] encryptedData) + { // 创建AES解密器 using (Aes aesAlg = Aes.Create()) diff --git a/Assets/Scripts/UI/UIScore.cs b/Assets/Scripts/UI/UIScore.cs index 41a5b380..4ef7f346 100644 --- a/Assets/Scripts/UI/UIScore.cs +++ b/Assets/Scripts/UI/UIScore.cs @@ -1,7 +1,9 @@ using Newtonsoft.Json; +using System; using System.Collections.Generic; using TMPro; using UnityEngine; +using static LYTWebGLHelper; namespace QFramework.Example { @@ -84,9 +86,9 @@ namespace QFramework.Example onlyCur = mData.onlyCurModule; } - List stepNames = new List(); - List maxScore = new List(); - List scores = new List(); + + List datas = new List(); + int seq = 0; if (onlyCur) { foreach (var item in ScoreController.Instance.GetCurScoreData()) @@ -98,9 +100,16 @@ namespace QFramework.Example obj.transform.Find("Score").GetComponent().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); + datas.Add(new Expstepvtwolist() + { + ExpStepName = item.Value.step + item.Value.name, + maxScore = int.Parse(item.Value.sum), + score = (int)item.Value.value, + startTime = item.Value.time, + endTime = item.Value.time, + seq = seq, + }); + seq++; } } else @@ -116,9 +125,16 @@ namespace QFramework.Example obj.transform.Find("Score").GetComponent().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); + datas.Add(new Expstepvtwolist() + { + ExpStepName = item.Value.step + item.Value.name, + maxScore = int.Parse(item.Value.sum), + score = (int)item.Value.value, + startTime = item.Value.time, + endTime = item.Value.time, + seq = seq + }); + seq++; } } } @@ -127,9 +143,10 @@ 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 +#if UNITY_WEBGL + + LYTWebGLHelper.Instance.UpLoadData((int)score, datas.ToArray()); +#endif } protected override void OnShow() diff --git a/Assets/StreamingAssets/Timer.txt b/Assets/StreamingAssets/Timer.txt new file mode 100644 index 00000000..a2dd3e38 --- /dev/null +++ b/Assets/StreamingAssets/Timer.txt @@ -0,0 +1 @@ +ILBJ05 lF)#BȲUv}]u.\G \ No newline at end of file diff --git a/Assets/StreamingAssets/Timer.txt.meta b/Assets/StreamingAssets/Timer.txt.meta new file mode 100644 index 00000000..884fc80c --- /dev/null +++ b/Assets/StreamingAssets/Timer.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9b4029b9b6235264f8d2594721eb300a +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs b/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs index 1607d79a..56356007 100644 --- a/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs +++ b/Assets/WebPlatform/LaiYiTe/LYTWebGLHelper.cs @@ -69,7 +69,7 @@ public class LYTWebGLHelper : MonoSingleton labData.PARA = datas[4]; labData.PARA2 = datas[5]; } - uploadUrl = Path.Combine(labData.HOST, "host/public/Exp/AddScore/"); + uploadUrl = Path.Combine(labData.HOST, "public/Exp/AddScore/"); } /// /// Decrypts encrypted text given a RSA private key file path.· RSA ˽Կļ @@ -104,8 +104,12 @@ public class LYTWebGLHelper : MonoSingleton - public void UpLoadData(int totalScore, List stepNames, List maxScore, List score) + public void UpLoadData(int totalScore, Expstepvtwolist[] datas) { + if (string.IsNullOrEmpty(labData.GUID)) + { + return; + } var data = new UploadData(); data.GUID = labData.GUID; int expId = 0; @@ -113,17 +117,17 @@ public class LYTWebGLHelper : MonoSingleton data.ExpID = expId; data.score = totalScore; data.flag = true; - - var list = new List(); - for (int i = 0; i < stepNames.Count; i++) - { - var step = new Expstepvtwolist(); - step.ExpStepName = stepNames[i]; - step.maxScore = maxScore[i]; - step.score = score[i]; - list.Add(step); - } - data.ExpStepVTwoList = list.ToArray(); + //var list = new List(); + //for (int i = 0; i < stepNames.Count; i++) + //{ + // var step = new Expstepvtwolist(); + // step.ExpStepName = stepNames[i]; + // step.maxScore = maxScore[i]; + // step.score = score[i]; + // step.seq = i + 1; + // list.Add(step); + //} + data.ExpStepVTwoList = datas; StartCoroutine(SendScore(JsonConvert.SerializeObject(data))); } @@ -185,9 +189,9 @@ public class LYTWebGLHelper : MonoSingleton // ʵ鲽״̬ public string StepState = ""; // ʵ鲽迪ʼʱ - public DateTime startTime = default; + public string startTime; // ʵ鲽ʱ - public DateTime endTime = default; + public string endTime; // ʵ鲽ʱλ public int expectTime = 0; // ʵ鲽֣0 ~100ٷ