You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
5.2 KiB
127 lines
5.2 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using UnityEngine.UI;
|
||
|
using System;
|
||
|
using System.IO;
|
||
|
using AX.TrackRecord;
|
||
|
|
||
|
public class ExamQuestionItemManager : BaseSubItemManager {
|
||
|
protected Button CheckAnswerButton;
|
||
|
protected Button DeleteAnswerButton;
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
CheckIfHasAnswer();
|
||
|
}
|
||
|
public override void ButtonInit()
|
||
|
{
|
||
|
CheckAnswerButton = transform.Find("check").GetComponent<Button>();
|
||
|
DeleteAnswerButton = transform.Find("delete").GetComponent<Button>();
|
||
|
}
|
||
|
public override void CheckIfHasAnswer()
|
||
|
{
|
||
|
/*一个考题有多个答案文件时采用该种方法
|
||
|
string path = ExamInfoHelpClass.CurrentWorkPath + "answer/" + question.QuestionID + "/";
|
||
|
string fileDir = Path.GetDirectoryName(path);
|
||
|
//有该考题ID的答案目录,且目录中有文件
|
||
|
if (Directory.Exists(fileDir) && Directory.GetFiles(fileDir).Length>0)
|
||
|
{
|
||
|
CheckAnswerButton.gameObject.SetActive(true);
|
||
|
//DeleteAnswerButton.gameObject.SetActive(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
CheckAnswerButton.gameObject.SetActive(false);
|
||
|
//DeleteAnswerButton.gameObject.SetActive(false);
|
||
|
}*/
|
||
|
//如果还没有下载考题,不能答题
|
||
|
var examObj = transform.parent.parent.parent.parent.parent;
|
||
|
var manager = examObj.GetComponent<ExamItemManager>();
|
||
|
if (manager.ExamOver || !manager.HasQuestionFiles || manager.CurExamState==ExamState.ExamOver)
|
||
|
return;
|
||
|
//判断考题是否已经有答案
|
||
|
//一个考题只有一个答案文件时采用以下方法
|
||
|
string filename = ExamInfoHelpClass.CurrentWorkPath + "Answers/" + manager.Exam.ID + "_" + question.ID + ".xml";
|
||
|
if (File.Exists(filename))
|
||
|
{
|
||
|
CheckAnswerButton.gameObject.SetActive(true);
|
||
|
DeleteAnswerButton.gameObject.SetActive(true);
|
||
|
examObj.Find("StartAnswerQuestionButton").gameObject.SetActive(false);
|
||
|
examObj.Find("CheckQuestionButton").gameObject.SetActive(false);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
CheckAnswerButton.gameObject.SetActive(false);
|
||
|
DeleteAnswerButton.gameObject.SetActive(false);
|
||
|
|
||
|
var StartAnswerQuestionButton = examObj.Find("StartAnswerQuestionButton").gameObject;
|
||
|
var CheckQuestionButton = examObj.Find("CheckQuestionButton").gameObject;
|
||
|
StartAnswerQuestionButton.SetActive(QuestionToggle.isOn);
|
||
|
CheckQuestionButton.SetActive(QuestionToggle.isOn);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void CheckAnswerButtonClick()
|
||
|
{
|
||
|
var manager = transform.parent.parent.parent.parent.parent.GetComponent<ExamItemManager>();
|
||
|
if (manager.ExamOver)
|
||
|
return;
|
||
|
if (manager.RemainSeconds < TimeManager.TipTime)
|
||
|
{
|
||
|
manager.transform.Find("TiShi").gameObject.SetActive(true);
|
||
|
manager.transform.Find("TiShi").GetComponent<UITiShiManager>().Get("考试时间不足,无法查看!");
|
||
|
return;
|
||
|
}
|
||
|
QuestionToggle.isOn = true;
|
||
|
//定位到对应考题ID的答案文件夹
|
||
|
//string filename = "Answers/" + question.ID + ".xml";
|
||
|
//BaseItemManager.XmlPath = filename;
|
||
|
//BaseItemManager.CurQues = question;
|
||
|
//QuestionToggle.isOn = true;
|
||
|
//LoadManager.Instance.IsMakeScore = true;///////////////////
|
||
|
manager.Question = question;
|
||
|
ExamInfoHelpClass.loadSceneMode = ExamInfoHelpClass.LoadSceneMode.CheckAnswer;
|
||
|
ExamInfoHelpClass.selectSceneID = (ExamInfoHelpClass.Scene)question.SceneType;//给Selected.selectSceneID赋值
|
||
|
MySceneManager.MyLoadScene(question.SceneType.ToString());
|
||
|
TimeManager.RemainSeconds = manager.RemainSeconds;
|
||
|
TimeManager.LastTime = DateTime.Now;
|
||
|
}
|
||
|
public void DeleteAnswerButtonClick()
|
||
|
{
|
||
|
var manager = transform.parent.parent.parent.parent.parent.GetComponent<ExamItemManager>();
|
||
|
if (manager.ExamOver)
|
||
|
return;
|
||
|
QuestionToggle.isOn = true;
|
||
|
GameObject TipWindow = Instantiate(Resources.Load<GameObject>("UIPrefab/TipWindow"));
|
||
|
TipWindow.GetComponent<TipWindowManager>().SetWindow(
|
||
|
"确定删除?", new UnityEngine.Events.UnityAction(OKDelete), new UnityEngine.Events.UnityAction(CancelDelete));
|
||
|
|
||
|
}
|
||
|
private void OKDelete()
|
||
|
{
|
||
|
var examObj = transform.parent.parent.parent.parent.parent;
|
||
|
var manager = examObj.GetComponent<BaseItemManager>();
|
||
|
string filepath = ExamInfoHelpClass.CurrentWorkPath + "Answers/" + manager.Exam.ID + "_" + question.ID + ".xml";
|
||
|
File.Delete(filepath);
|
||
|
CheckIfHasAnswer();
|
||
|
|
||
|
//删除答案文件后,在对应的Answelist中删除元素
|
||
|
var list = BaseItemManager.AnswerList;
|
||
|
var item = list.Find((a) => { return a.FilePath == (manager.Exam.ID + "_" + question.ID + ".xml"); });//Lambda
|
||
|
list.Remove(item);
|
||
|
//for (int i = 0; i < list.Count; i++)
|
||
|
//{
|
||
|
// if(list[i].FilePath== (question.ID + ".xml"))
|
||
|
// {
|
||
|
// list.Remove(list[i]);
|
||
|
// break;
|
||
|
// }
|
||
|
//}
|
||
|
transform.parent.parent.parent.parent.parent.GetComponent<BaseItemManager>().CheckIfShowSubmitButton();
|
||
|
}
|
||
|
private void CancelDelete()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|