From e396d2e0e86101df53ed77661afe95587c7927a6 Mon Sep 17 00:00:00 2001 From: zc <1062808664@qq.com> Date: Tue, 26 Dec 2023 23:25:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=AD=94=E9=A2=98=E7=9A=84?= =?UTF-8?q?=E6=89=80=E6=9C=89=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/SampleScene.unity | 44 +++++++ Assets/Script/Excel/ExcelManager.cs | 115 +++++++++++++++--- Assets/Script/Excel/SaveDataInfo.cs | 2 + Assets/Script/File/FileManager.cs | 2 +- Assets/Script/File/GlobalManager.cs | 1 + Assets/Script/Test.cs | 32 +++++ Assets/Script/Test.cs.meta | 3 + Assets/Script/UI/Item/Right_QuestionItem.cs | 6 +- Assets/Script/UI/Panel/AnsweringPanel.cs | 24 ++-- Assets/Script/UI/Panel/FinishPanel.cs | 6 + Assets/Script/UI/Panel/SummaryPanel.cs | 2 +- Assets/Script/UI/Panel/TipsPanel.cs | 1 + Assets/StreamingAssets/TXT.meta | 8 ++ Assets/StreamingAssets/TXT/data-659127385.txt | 0 .../TXT/data-659127385.txt.meta | 7 ++ 15 files changed, 220 insertions(+), 33 deletions(-) create mode 100644 Assets/Script/Test.cs create mode 100644 Assets/Script/Test.cs.meta create mode 100644 Assets/StreamingAssets/TXT.meta create mode 100644 Assets/StreamingAssets/TXT/data-659127385.txt create mode 100644 Assets/StreamingAssets/TXT/data-659127385.txt.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 5a64716..2c64643 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -10501,6 +10501,50 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 997595766} m_CullTransparentMesh: 1 +--- !u!1 &1007527457 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1007527459} + - component: {fileID: 1007527458} + m_Layer: 0 + m_Name: Test + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1007527458 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1007527457} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d6dcaa418a4d42b8b9b927bb2215f702, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1007527459 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1007527457} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 945.3645, y: 410.25293, z: 24.352406} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1010436609 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Script/Excel/ExcelManager.cs b/Assets/Script/Excel/ExcelManager.cs index b3f400b..1d34507 100644 --- a/Assets/Script/Excel/ExcelManager.cs +++ b/Assets/Script/Excel/ExcelManager.cs @@ -82,32 +82,33 @@ public class ExcelManager : SingleManager public void SaveAndExpIndex(SaveDataInfo info, int index) { - string path = Application.streamingAssetsPath + "/程序输出数据" + DateTime.Now.Ticks + ".xlsx"; + string path = Application.streamingAssetsPath + "/程序输出数据" + ".xlsx"; FileStream fs = new FileStream(path, FileMode.OpenOrCreate); using (var pck = new ExcelPackage(fs)) { - var sheet = pck.Workbook.Worksheets.Add("Sheet1"); + ExcelWorksheet worksheet; + if (pck.Workbook.Worksheets.Count <= 0) + { + worksheet = pck.Workbook.Worksheets.Add("Sheet1"); + } + else + { + worksheet = pck.Workbook.Worksheets[1]; + } if (index == 0) { string[] hands = new[] { "选手ID", "赛项", "科目", "第一题", "第二题", "第三题", "第四题", "第五题", "分数", "正确数量", "错误数量", "未答数量", "正确率", "用时" }; for (int i = 0; i < hands.Length; i++) { - sheet.SetValue(1, i + 2, hands[i]); + worksheet.SetValue(1, i + 2, hands[i]); } } - // for (var j = 0; j < info.strings.Length; j++) - // { - // //第0行、列留白 - // // sheet.Cells[i + 2, j + 2].Value = data.infos[i].strings[j]; - // - // sheet.SetValue(index + 2, j + 2, info.strings[j]); - // } int j = 0; - sheet.SetValue(index + 2, j + 2, info.id); - sheet.SetValue(index + 2, j + 3, info.title); - sheet.SetValue(index + 2, j + 4, info.subject); + worksheet.SetValue(index + 2, j + 2, info.id); + worksheet.SetValue(index + 2, j + 3, info.title); + worksheet.SetValue(index + 2, j + 4, info.subject); int num = 0; foreach (var infoAnswerData in info.answerDatas) { @@ -132,16 +133,90 @@ public class ExcelManager : SingleManager sb.AppendLine(result); } - sheet.SetValue(index + 2, num + j + 5, sb.ToString()); + worksheet.SetValue(index + 2, num + j + 5, sb.ToString()); num++; } - sheet.SetValue(index + 2, j + 10, info.score); - sheet.SetValue(index + 2, j + 11, info.trueCount); - sheet.SetValue(index + 2, j + 12, info.falseCount); - sheet.SetValue(index + 2, j + 13, info.nullCount); - sheet.SetValue(index + 2, j + 14, info.accuracy); - sheet.SetValue(index + 2, j + 15, info.time); + worksheet.SetValue(index + 2, j + 10, info.score); + worksheet.SetValue(index + 2, j + 11, info.trueCount); + worksheet.SetValue(index + 2, j + 12, info.falseCount); + worksheet.SetValue(index + 2, j + 13, info.nullCount); + worksheet.SetValue(index + 2, j + 14, info.accuracy); + worksheet.SetValue(index + 2, j + 15, info.time); + + pck.Save(); + } + + fs.Dispose(); + } + + public void SaveAndExpIndex(SaveData saveData) + { + List infos = saveData.DataInfos; + + string path = Application.streamingAssetsPath + "/程序输出数据" + DateTime.Now.Ticks + ".xlsx"; + FileStream fs = new FileStream(path, FileMode.OpenOrCreate); + using (var pck = new ExcelPackage(fs)) + { + ExcelWorksheet worksheet; + if (pck.Workbook.Worksheets.Count <= 0) + { + worksheet = pck.Workbook.Worksheets.Add("Sheet1"); + } + else + { + worksheet = pck.Workbook.Worksheets[1]; + } + + string[] hands = new[] { "选手ID", "赛项", "科目", "第一题", "第二题", "第三题", "第四题", "第五题", "分数", "正确数量", "错误数量", "未答数量", "正确率", "用时" }; + for (int i = 0; i < hands.Length; i++) + { + worksheet.SetValue(1, i + 2, hands[i]); + } + + int index = 0; + foreach (var info in infos) + { + int j = 0; + worksheet.SetValue(index + 2, j + 2, info.id); + worksheet.SetValue(index + 2, j + 3, info.title); + worksheet.SetValue(index + 2, j + 4, info.subject); + int num = 0; + foreach (var infoAnswerData in info.answerDatas) + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("题目:"); + sb.AppendLine(infoAnswerData.title); + sb.AppendLine("选项:"); + foreach (var option in infoAnswerData.options) + { + sb.AppendLine(option); + } + + sb.AppendLine("正确答案:"); + foreach (var answer in infoAnswerData.answers) + { + sb.AppendLine(answer); + } + + sb.AppendLine("回答结果:"); + foreach (var result in infoAnswerData.result) + { + sb.AppendLine(result); + } + + worksheet.SetValue(index + 2, num + j + 5, sb.ToString()); + num++; + } + + worksheet.SetValue(index + 2, j + 10, info.score); + worksheet.SetValue(index + 2, j + 11, info.trueCount); + worksheet.SetValue(index + 2, j + 12, info.falseCount); + worksheet.SetValue(index + 2, j + 13, info.nullCount); + worksheet.SetValue(index + 2, j + 14, info.accuracy); + worksheet.SetValue(index + 2, j + 15, info.time); + index++; + } pck.Save(); } diff --git a/Assets/Script/Excel/SaveDataInfo.cs b/Assets/Script/Excel/SaveDataInfo.cs index 6da31b9..0b6181c 100644 --- a/Assets/Script/Excel/SaveDataInfo.cs +++ b/Assets/Script/Excel/SaveDataInfo.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace Script.Excel { @@ -29,6 +30,7 @@ namespace Script.Excel private Dictionary _saveDataInfos = new Dictionary(); public int Count => _saveDataInfos.Count; + public List DataInfos => _saveDataInfos.Values.ToList(); public SaveDataInfo AddInfo(int id, string title, string subject) { diff --git a/Assets/Script/File/FileManager.cs b/Assets/Script/File/FileManager.cs index c46350b..754599b 100644 --- a/Assets/Script/File/FileManager.cs +++ b/Assets/Script/File/FileManager.cs @@ -22,7 +22,7 @@ namespace Script public FileManager() { - dataPath = Application.streamingAssetsPath + $"/data{GenerateGlobalID.GenerateIntID()}.txt"; + dataPath = Application.streamingAssetsPath + $"/TXT/data{GenerateGlobalID.GenerateIntID()}.txt"; if (!File.Exists(dataPath)) { var fileStream = File.Create(dataPath); diff --git a/Assets/Script/File/GlobalManager.cs b/Assets/Script/File/GlobalManager.cs index 766f173..d5c6b45 100644 --- a/Assets/Script/File/GlobalManager.cs +++ b/Assets/Script/File/GlobalManager.cs @@ -12,6 +12,7 @@ namespace Script public SaveDataInfo CurrentInfo => currentInfo; public int Count => saveData.Count; + public SaveData SaveData => saveData; public GlobalManager() { diff --git a/Assets/Script/Test.cs b/Assets/Script/Test.cs new file mode 100644 index 0000000..9ffc0a2 --- /dev/null +++ b/Assets/Script/Test.cs @@ -0,0 +1,32 @@ +using System; +using UnityEngine; + +namespace Script +{ + public class Test : MonoBehaviour + { + private int index = 3; + + private void Update() + { + if (Input.GetKeyDown(KeyCode.A)) + { + index++; + GlobalManager.Instance.AddInfo(index, "hhhh", "eeee"); + GlobalManager.Instance.AddInfo(2, "hhhh", "eeee"); + GlobalManager.Instance.AddInfo(3, "hhhh", "eeee"); + GlobalManager.Instance.AddInfo(4, "hhhh", "eeee"); + ExcelManager.Instance.SaveAndExpIndex(GlobalManager.Instance.SaveData); + Debug.Log(index); + } + + if (Input.GetKeyDown(KeyCode.W)) + { + index++; + GlobalManager.Instance.AddInfo(index, "hhhh", "eeee"); + ExcelManager.Instance.SaveAndExpIndex(GlobalManager.Instance.CurrentInfo, index); + Debug.Log(index); + } + } + } +} \ No newline at end of file diff --git a/Assets/Script/Test.cs.meta b/Assets/Script/Test.cs.meta new file mode 100644 index 0000000..f739883 --- /dev/null +++ b/Assets/Script/Test.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d6dcaa418a4d42b8b9b927bb2215f702 +timeCreated: 1703564209 \ No newline at end of file diff --git a/Assets/Script/UI/Item/Right_QuestionItem.cs b/Assets/Script/UI/Item/Right_QuestionItem.cs index 9a5f1e3..ec0e795 100644 --- a/Assets/Script/UI/Item/Right_QuestionItem.cs +++ b/Assets/Script/UI/Item/Right_QuestionItem.cs @@ -148,7 +148,9 @@ namespace Script.UI foreach (var go in toggleItemList) { go.SetActive(false); - go.GetComponent().onValueChanged.RemoveAllListeners(); + var toggle = go.GetComponent(); + toggle.isOn = false; + toggle.onValueChanged.RemoveAllListeners(); } var count = str.Length - toggleItemList.Count; @@ -205,7 +207,7 @@ namespace Script.UI EventManager.Instance.FireNow(this, new QuestionSureEventArgs(currentIndex, !isNull)); if (!isNull) { - _toggleGroup.allowSwitchOff = false; + // _toggleGroup.allowSwitchOff = false; answerData.StopSetData(); } } diff --git a/Assets/Script/UI/Panel/AnsweringPanel.cs b/Assets/Script/UI/Panel/AnsweringPanel.cs index 4a174db..1704c72 100644 --- a/Assets/Script/UI/Panel/AnsweringPanel.cs +++ b/Assets/Script/UI/Panel/AnsweringPanel.cs @@ -36,9 +36,9 @@ namespace Script.UI base.Init(); btn_ConfirmSubmit.onClick.AddListener(ClickConfirmSubmit); - EventManager.Instance.Subscribe(QuestionSureEventArgs.EventId,QuestionSureEvent); + EventManager.Instance.Subscribe(QuestionSureEventArgs.EventId, QuestionSureEvent); } - + private void QuestionSureEvent(object sender, GameEventArgs e) { var args = e as QuestionSureEventArgs; @@ -56,6 +56,12 @@ namespace Script.UI public override void ResetPanelData() { base.ResetPanelData(); + Debug.Log("重置抽题数据"); + _aDataInfos.Clear(); + _bDataInfos.Clear(); + _cDataInfos.Clear(); + _dDataInfos.Clear(); + // 数据存入 _aDataInfos.Add(ExcelManager.Instance.GetRandomAInfo); _bDataInfos.Add(ExcelManager.Instance.GetRandomBInfo); @@ -74,7 +80,7 @@ namespace Script.UI ShowIndexQuestion, ShowIndexQuestion ); - GlobalManager.Instance.AddCurrentAnswer(_aDataInfos[0].topic,_aDataInfos[0].options,_aDataInfos[0].answer); + GlobalManager.Instance.AddCurrentAnswer(_aDataInfos[0].topic, _aDataInfos[0].options, _aDataInfos[0].answer); _rightQuestionItems[1].SetData( 1, @@ -85,7 +91,7 @@ namespace Script.UI ShowIndexQuestion, ShowIndexQuestion ); - GlobalManager.Instance.AddCurrentAnswer(_bDataInfos[0].topic,_bDataInfos[0].options,_bDataInfos[0].answer); + GlobalManager.Instance.AddCurrentAnswer(_bDataInfos[0].topic, _bDataInfos[0].options, _bDataInfos[0].answer); _rightQuestionItems[2].SetData( 2, @@ -96,7 +102,7 @@ namespace Script.UI ShowIndexQuestion, ShowIndexQuestion ); - GlobalManager.Instance.AddCurrentAnswer(_cDataInfos[0].topic,_cDataInfos[0].options,_cDataInfos[0].answer); + GlobalManager.Instance.AddCurrentAnswer(_cDataInfos[0].topic, _cDataInfos[0].options, _cDataInfos[0].answer); _rightQuestionItems[3].SetData( 3, @@ -107,7 +113,7 @@ namespace Script.UI ShowIndexQuestion, ShowIndexQuestion ); - GlobalManager.Instance.AddCurrentAnswer(_cDataInfos[1].topic,_cDataInfos[1].options,_cDataInfos[1].answer); + GlobalManager.Instance.AddCurrentAnswer(_cDataInfos[1].topic, _cDataInfos[1].options, _cDataInfos[1].answer); _rightQuestionItems[4].SetData( 4, @@ -118,7 +124,7 @@ namespace Script.UI ShowIndexQuestion, ShowIndexQuestion ); - GlobalManager.Instance.AddCurrentAnswer(_dDataInfos[0].topic,_dDataInfos[0].options,_dDataInfos[0].answer); + GlobalManager.Instance.AddCurrentAnswer(_dDataInfos[0].topic, _dDataInfos[0].options, _dDataInfos[0].answer); // txt_ID.text = GlobalManager.Instance.CurrentInfo.id; @@ -137,7 +143,7 @@ namespace Script.UI public override void Dispose() { base.Dispose(); - EventManager.Instance.Unsubscribe(QuestionSureEventArgs.EventId,QuestionSureEvent); + EventManager.Instance.Unsubscribe(QuestionSureEventArgs.EventId, QuestionSureEvent); } #region Down Left @@ -241,7 +247,7 @@ namespace Script.UI // GlobalManager.Instance.summaryInfo.falseCount = falseCount; // GlobalManager.Instance.summaryInfo.nullCount = nullCount; // GlobalManager.Instance.summaryInfo.accuracy = $"{count}%"; - GlobalManager.Instance.SetCurrentScoreAndOther(score.ToString(),trueCount.ToString(),falseCount.ToString(),nullCount.ToString(),$"{count}%"); + GlobalManager.Instance.SetCurrentScoreAndOther(score.ToString(), trueCount.ToString(), falseCount.ToString(), nullCount.ToString(), $"{count}%"); } } } \ No newline at end of file diff --git a/Assets/Script/UI/Panel/FinishPanel.cs b/Assets/Script/UI/Panel/FinishPanel.cs index 7d91bf9..c430d39 100644 --- a/Assets/Script/UI/Panel/FinishPanel.cs +++ b/Assets/Script/UI/Panel/FinishPanel.cs @@ -19,6 +19,12 @@ namespace Script.UI btn_Exit.onClick.RemoveListener(ClickExit); } + public override void Open() + { + base.Open(); + ExcelManager.Instance.SaveAndExpIndex(GlobalManager.Instance.SaveData); + } + private void ClickExit() { Application.Quit(); diff --git a/Assets/Script/UI/Panel/SummaryPanel.cs b/Assets/Script/UI/Panel/SummaryPanel.cs index 90e97cf..64f3574 100644 --- a/Assets/Script/UI/Panel/SummaryPanel.cs +++ b/Assets/Script/UI/Panel/SummaryPanel.cs @@ -70,7 +70,7 @@ namespace Script.UI sb.AppendLine($"正确率:{txt_Accuracy.text}"); sb.AppendLine($"用时:{txt_Time.text}"); FileManager.Instance.SavePlayerData(sb.ToString()); - ExcelManager.Instance.SaveAndExpIndex(GlobalManager.Instance.CurrentInfo, GlobalManager.Instance.Count - 1); + // ExcelManager.Instance.SaveAndExpIndex(GlobalManager.Instance.CurrentInfo, GlobalManager.Instance.Count - 1); } } } \ No newline at end of file diff --git a/Assets/Script/UI/Panel/TipsPanel.cs b/Assets/Script/UI/Panel/TipsPanel.cs index 5c81c37..9c018dd 100644 --- a/Assets/Script/UI/Panel/TipsPanel.cs +++ b/Assets/Script/UI/Panel/TipsPanel.cs @@ -60,6 +60,7 @@ namespace Script.UI var answeringPanel = panelBase as AnsweringPanel; if (answeringPanel != null) answeringPanel.SaveData(); answeringPanel.Stop(); + index = 0; action?.Invoke(true); UIManager.Instance.OpenPanel(PanelType.Summary); diff --git a/Assets/StreamingAssets/TXT.meta b/Assets/StreamingAssets/TXT.meta new file mode 100644 index 0000000..3589efe --- /dev/null +++ b/Assets/StreamingAssets/TXT.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 368984d8846e2974bb7c0e23e820e25d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StreamingAssets/TXT/data-659127385.txt b/Assets/StreamingAssets/TXT/data-659127385.txt new file mode 100644 index 0000000..e69de29 diff --git a/Assets/StreamingAssets/TXT/data-659127385.txt.meta b/Assets/StreamingAssets/TXT/data-659127385.txt.meta new file mode 100644 index 0000000..a744369 --- /dev/null +++ b/Assets/StreamingAssets/TXT/data-659127385.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 88145f02c7986b94cb076dc547508527 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: