using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI; using UnityEngine.Networking; using UnityEngine.SceneManagement; public class ExamRecord : MonoBehaviour { public ReadExamData ExamData; public ArticleControl ArtCon;//物资身份码 public IDCodeSelect CodeSelectCon;//物资身份码选择 public List List_Order;//考试流程 //[NonSerialized] public List List_Operate = new List();//操作记录 public Text T_Rec;//操作记录 //统计分数 int TotalScore; bool ifComplete; public GameObject Panel_Report,Panel_SubmitEnd;//成绩报告 public RecordBar OneRecBar;//一条记录 //计时 DateTime DT_Start, DT_End; TimeSpan DT_Use; //详细信息 public Text Text_UserName, Text_UseTime, Text_Score, Text_Time; bool isSubmit; void Start() { DT_Start = DateTime.Now; } public void Score() { if (isSubmit) return; isSubmit = true; ////////////////考生信息 Text_UserName.text = PlayerPrefs.GetString("studentName"); Text_Time.text = DT_Start.ToString(); //////////////用时 DT_End = DateTime.Now; DT_Use = DT_End - DT_Start; Text_UseTime.text = (1 + (int)DT_Use.TotalMinutes).ToString() + "分钟"; //////////////添加勾选物资码结果记录 CodeSelectCon.Conform(); //////////////添加物资状态判断记录 ArtCon.Conform(); for (a = 0; a < List_Order.Count; a++) { RecordBar newBar = Instantiate(OneRecBar.gameObject, OneRecBar.transform.parent).GetComponent(); newBar.T_Num.text = (a + 1).ToString(); newBar.T_Title.text = List_Order[a].CheckStr.ToString(); ifComplete = false; for (b = 0; b < List_Operate.Count; b++) { if (List_Operate[b].Contains(List_Order[a].CheckStr)) { ifComplete = true; break; } } if (ifComplete) { newBar.T_Comp.text = "完成"; newBar.T_Score.text = List_Order[a].Score.ToString(); TotalScore += List_Order[a].Score; } else { newBar.T_Comp.text = "未完成"; newBar.T_Score.text = ""; } newBar.gameObject.SetActive(true); } //////////////总分 Text_Score.text = TotalScore.ToString(); //////////////操作记录 T_Rec.text = ""; for (b = 0; b < List_Operate.Count; b++) { T_Rec.text += List_Operate[b].ToString() + "\r\n"; } if (PlayerPrefs.GetInt("Mode", 0) == 2)//考核模式 { Panel_SubmitEnd.SetActive(true);//提示已提交 } else//学习/训练模式展示成绩单 { Panel_Report.SetActive(true); } //////////////写入 int currExamNum = PlayerPrefs.GetInt("TaskNum"); PlayerPrefs.SetInt("UseTime_" + currExamNum, (int)DT_Use.TotalMinutes); PlayerPrefs.SetInt("Score_" + currExamNum, TotalScore); PlayerPrefs.SetInt("Join_" + currExamNum, 1); } public void EndBack() { if (PlayerPrefs.GetInt("Mode", 0) == 2)//考核模式 SceneManager.LoadScene("Item"); else//学习/训练模式 SceneManager.LoadScene("Menu"); } /// /// 获取考核点步骤 /// /// public void ReadStep(string wTitle) { ExamType = wTitle; StartCoroutine(PostCheckStep()); Invoke("CheckReadComplete", 1); } //读取完成,获取内容 bool ifMatch;//是否匹配 void CheckReadComplete() { if (ReadResult == 1)//成功 { //为关键字匹配数据 for (a = 0; a < List_Order.Count; a++) { List_Order[a].CheckStr = List_Order[a].StepName; if (List_Order[a].StepKey != "无")//关键字不为空 { ifMatch = false; for (b = 0; b < ExamData.List_Task.Count; b++) { if (List_Order[a].StepKey == ExamData.List_Task[b].PropName) { List_Order[a].CheckStr += ExamData.List_Task[b].Value;//最终验证字符 ifMatch = true;//已匹配到 break; } } if (!ifMatch)//未匹配到-表示是直接参数值 List_Order[a].CheckStr += List_Order[a].StepKey; } Debug.Log("考察点" + (a + 1).ToString() + ":" + List_Order[a].CheckStr + "/" + List_Order[a].Score); } if (ifShowStep) ShowStep(); } else if (ReadResult == -1)//失败 { } else Invoke("CheckReadComplete", 1); } /// /// //读取步骤详细 /// /// WWWForm Form; UnityWebRequest Request_Detail; string ExamType, ExamStr, SubStr; int ReadResult,a, b, c, d, e; IEnumerator PostCheckStep() { Form = new WWWForm(); Form.AddField("title", ExamType); Request_Detail = UnityWebRequest.Post(PlayerPrefs.GetString("业务流程考核点数据"), Form); Debug.Log("业务流程考核点数据:"+PlayerPrefs.GetString("业务流程考核点数据")); yield return Request_Detail.SendWebRequest(); if (Request_Detail.isHttpError || Request_Detail.isNetworkError) { Debug.Log("错误" + Request_Detail.error); ReadResult = -1; } else { List_Order = new List(); ExamStr = Request_Detail.downloadHandler.text; Debug.Log("业务流程考核点数据:" + ExamStr); //解析处理 ExamStr = ExamStr.Replace("\\\"", "");//去除\" ExamStr = ExamStr.Substring(ExamStr.IndexOf("content") + 8);//去掉头 //Debug.Log(ExamStr); while (ExamStr.Contains("{") && ExamStr.Contains("}")) { a = ExamStr.IndexOf("{"); b = ExamStr.IndexOf("}"); //取一条数据{} SubStr = ExamStr.Substring(a + 1, b - a - 1); //Debug.Log(SubStr); //列表 Step tempTask = new Step(); c = SubStr.IndexOf("name:"); d = SubStr.IndexOf("code:"); e = SubStr.IndexOf("value:"); if (d - c > 6) tempTask.StepName = SubStr.Substring(c + 5, d - 6);//数据1 if (e - d > 6) tempTask.StepKey= SubStr.Substring(d + 5, e - d - 6).Trim();//数据2 if (e + 6 < SubStr.Length) tempTask.Score =int .Parse ( SubStr.Substring(e + 6));//数据3 //裁切 ExamStr = ExamStr.Substring(b + 1); //Debug.Log(tempTask.StepName + "/" + tempTask.Score); List_Order.Add(tempTask);//列表添加 } ReadResult = 1; } } public bool ifShowStep; public GameObject Panel_Step; public List Items; int i; void ShowStep() { Panel_Step.SetActive(true); for (i = 0; i < List_Order.Count; i++) { //Debug.Log(i.ToString() + "," + Items.Count.ToString()); if (i >= Items.Count) Items.Add(Instantiate(Items[0].transform.parent, Items[0].transform.parent.parent).GetChild(0).GetComponent()); Items[i].text = (i + 1).ToString() + "." + List_Order[i].StepName; } } /// /// 仅添加文字 /// /// 步骤名称 public void AddLog(string oName) { List_Operate.Add(DateTime.Now.ToString("hh:mm:ss") + " " + oName); } InputField currInput; /// /// 设置当前输入框 /// /// public void SetCurrInputField(InputField In) { currInput = In; } /// /// 添加文字和文本内容 /// public void AddLogAndInput(string oName) { List_Operate.Add(DateTime.Now.ToString("hh:mm:ss") + " " + oName + currInput.text.ToUpper()); } Toggle currTog; /// /// 设置当前单选框 /// public void SetCurrToggle(Toggle cTog) { currTog = cTog; } /// /// 添加文字和单选状态 /// public void AddLogAndToggle(string oName) { if (currTog .isOn ) List_Operate.Add(DateTime.Now.ToString("hh:mm:ss") + " 勾选" + oName); else List_Operate.Add(DateTime.Now.ToString("hh:mm:ss") + " 勾选取消" + oName); } [Serializable] /// /// 步骤 /// public class Step { public string StepName;//属性 public string StepKey;//关键字 public int Score;//分值 public string CheckStr;//最终检测的字符串(属性+数值) } }