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.
160 lines
5.8 KiB
160 lines
5.8 KiB
using UnityEngine; |
|
using System.Collections.Generic; |
|
using UnityEngine.UI; |
|
using System; |
|
using AX.MessageSystem; |
|
|
|
public abstract class BaseItemManager : MonoBehaviour { |
|
|
|
protected Text ExamNameText; |
|
protected Text StartTimeText; |
|
protected Text DurationTimeText; |
|
protected Text EndTimeText; |
|
protected GameObject TiShi; |
|
protected GameObject ParentGrid; |
|
protected List<QuestionInfo> items = new List<QuestionInfo>(); |
|
[HideInInspector] |
|
public Transform CurSelectedTrans; |
|
[HideInInspector] |
|
public bool HasQuestionFiles = false; |
|
[HideInInspector] |
|
protected Dropdown DropDownList; |
|
protected GameObject ItemPrefab; |
|
|
|
public static ExaminationInfo CurExam;//当前选中的考试 |
|
public static QuestionInfo CurQues;//当前选中的考题 |
|
public static List<AnswerInfo> AnswerList = new List<AnswerInfo>(); |
|
public static long CurExamID;//当前选中的考试ID |
|
public static long CurQuestionID;//代表考题ID,也代表考生ID |
|
public static string XmlPath;//当前工作目录不用再写了,赋值举例:“question/1.xml” |
|
protected ExaminationInfo exam = new ExaminationInfo(); |
|
|
|
public float RemainSeconds = -10;//小于0,是初始值还没开始考试 |
|
public TimeSpan deltaTimeBetweenLocalAndServer;//服务端与本地时间的差 |
|
|
|
public ExaminationInfo Exam |
|
{ |
|
set |
|
{ |
|
exam = value; |
|
ExamNameText.text = exam.Name; |
|
StartTimeText.text = exam.StartingTime.ToShortDateString() + " " + exam.StartingTime.ToShortTimeString(); |
|
DurationTimeText.text = exam.Duration.ToString(); |
|
EndTimeText.text = exam.Deadline.ToShortDateString() + " " + exam.Deadline.ToShortTimeString(); |
|
items.Clear(); |
|
for (int i = 0; i < exam.QuestionInfos.Count; i++) |
|
{ |
|
|
|
items.Add(exam.QuestionInfos[i]); |
|
} |
|
//SetDropDownItem(quesList); |
|
GenerateQuestionItem(); |
|
CheckIfShowSubmitButton(); |
|
} |
|
get |
|
{ |
|
return exam; |
|
} |
|
} |
|
/// <summary> |
|
/// 在Awake中进行初始化工作,不然就晚了 |
|
/// </summary> |
|
public virtual void Awake() |
|
{ |
|
ExamNameText = transform.Find("CaptionText").GetComponent<Text>(); |
|
StartTimeText = transform.Find("StartTimeText/Content").GetComponent<Text>(); |
|
EndTimeText = transform.Find("EndTimeText/Content").GetComponent<Text>(); |
|
DurationTimeText = transform.Find("DurationTimeText/Content").GetComponent<Text>(); |
|
ParentGrid = transform.Find("QuestionSelectWin/ScrollView/Viewport/Content").gameObject; |
|
SetItemPrefab(); |
|
} |
|
|
|
public void RefreshTime(IMessage message) |
|
{ |
|
var ServerTime = (DateTime)message.Data; |
|
deltaTimeBetweenLocalAndServer = DateTime.Now - ServerTime; |
|
} |
|
public void ShowTimeAccordingSeconds(int second) |
|
{ |
|
var hour = second / 3600; |
|
var min = (second % 3600) / 60; |
|
var sec = (second % 3600) % 60; |
|
transform.Find("RemainTimeText/Content").GetComponent<Text>().text = hour + ":" + min + ":" + sec; |
|
} |
|
|
|
public abstract void SetItemPrefab(); |
|
void SetDropDownItem(List<QuestionInfo_o> quesList) |
|
{ |
|
//DropDownList.options.Clear(); |
|
for (int i = 0; i < quesList.Count; i++) |
|
{ |
|
Dropdown.OptionData data = new Dropdown.OptionData(); |
|
data.text = quesList[i].QuestionName; |
|
DropDownList.options.Add(data); |
|
} |
|
DropDownList.captionText.text = DropDownList.options[0].text; |
|
//DropDownList.transform.GetComponentInChildren<Text>().text = DropDownList.options[0].text; |
|
XmlPath = quesList[0].QuestionXMLPath; |
|
Debug.Log(XmlPath); |
|
} |
|
protected void GenerateQuestionItem() //开始创建考题节点预设 |
|
{ |
|
//foreach(Transform child in ParentGrid.transform) |
|
//{ |
|
// Destroy(child.gameObject); |
|
//} |
|
for (int i = 0; i < items.Count; i++) |
|
{ |
|
GameObject question = Instantiate(ItemPrefab); |
|
question.transform.SetParent(ParentGrid.transform); |
|
question.transform.localScale = new Vector3(1, 1, 1); |
|
question.name =items[i].ID+"/"+items[i].FilePath; |
|
question.GetComponent<BaseSubItemManager>().Question = items[i]; |
|
|
|
|
|
//if (0 == i)//赋个默认值 |
|
//{ |
|
// question.transform.FindChild("Toggle").GetComponent<Toggle>().isOn = true;//该处赋值会自动触发XmlPath属性赋值 |
|
//} |
|
} |
|
CheckIfHasFile(items); |
|
} |
|
//protected void AddOneQuestionItem(QuestionInfo questionI) |
|
//{ |
|
// GameObject question = Instantiate(ItemPrefab); |
|
// question.transform.SetParent(ParentGrid.transform); |
|
// question.transform.localScale = new Vector3(1, 1, 1); |
|
// question.name = "question-" + items.Count; |
|
// question.GetComponent<BaseSubItemManager>().Question = questionI; |
|
//} |
|
public abstract void CheckIfHasFile(List<QuestionInfo> items); |
|
public abstract void CheckIfShowSubmitButton(); |
|
|
|
public void ValueChange() |
|
{ |
|
XmlPath = items[DropDownList.value].FilePath; |
|
Debug.Log(XmlPath); |
|
} |
|
protected QuestionInfo question; |
|
public QuestionInfo Question |
|
{ |
|
set |
|
{ |
|
question = value; |
|
XmlPath = question.FilePath; |
|
CurQuestionID = question.ID; |
|
CurExamID = exam.ID; |
|
CurExam = exam; |
|
CurQues = question; |
|
|
|
Debug.Log(question.FilePath); |
|
Debug.Log(CurQuestionID); |
|
Debug.Log(CurExamID); |
|
if (transform.Find("ExamTip") && transform.Find("ExamTip").gameObject.activeInHierarchy) |
|
{ |
|
transform.Find("ExamTip").gameObject.SetActive(false); |
|
} |
|
} |
|
} |
|
|
|
}
|
|
|