完成答题的所有修改

master
zc 2023-12-26 23:25:22 +08:00
parent 6bf6a6b096
commit e396d2e0e8
15 changed files with 220 additions and 33 deletions

View File

@ -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

View File

@ -82,32 +82,33 @@ public class ExcelManager : SingleManager<ExcelManager>
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<ExcelManager>
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<SaveDataInfo> 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();
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
namespace Script.Excel
{
@ -29,6 +30,7 @@ namespace Script.Excel
private Dictionary<int, SaveDataInfo> _saveDataInfos = new Dictionary<int, SaveDataInfo>();
public int Count => _saveDataInfos.Count;
public List<SaveDataInfo> DataInfos => _saveDataInfos.Values.ToList();
public SaveDataInfo AddInfo(int id, string title, string subject)
{

View File

@ -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);

View File

@ -12,6 +12,7 @@ namespace Script
public SaveDataInfo CurrentInfo => currentInfo;
public int Count => saveData.Count;
public SaveData SaveData => saveData;
public GlobalManager()
{

32
Assets/Script/Test.cs Normal file
View File

@ -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);
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d6dcaa418a4d42b8b9b927bb2215f702
timeCreated: 1703564209

View File

@ -148,7 +148,9 @@ namespace Script.UI
foreach (var go in toggleItemList)
{
go.SetActive(false);
go.GetComponent<Toggle>().onValueChanged.RemoveAllListeners();
var toggle = go.GetComponent<Toggle>();
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();
}
}

View File

@ -36,7 +36,7 @@ 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)
@ -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}%");
}
}
}

View File

@ -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();

View File

@ -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);
}
}
}

View File

@ -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);

View File

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

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 88145f02c7986b94cb076dc547508527
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: