using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; using UnityEngine.UI; using Random = UnityEngine.Random; public class GameRoot : MonoBehaviour { public static GameRoot Instance = null; [Header("用户账号")] public Text userText; [SerializeField] private float _score = 0; private ResSvc resSvc; [Header("是否随机加载关卡")] public bool isRndom = false; [Header("AB卷")] public int ABType = 0;//0-A,1-B public Text ABtext; [Header("是否为抽免费的题")] public bool isFree = false; [HideInInspector] [Header("考试抽卷题型数量")] public int testTypeCount = 6; [Header("第几套试卷,为0则随机")] public int _TestIndex; //记录关卡是否完成 [HideInInspector] public bool[] PassOverGroup; public int AllPassCount; public Transform PassPreant; public GameObject _cavans; [Header("组件")] public Button TimeOutBtn; public GameObject TimeOutTip; public GameObject SlectedWnd; public GameObject ResultWnd; public GameObject sumbitTip; public GameObject answerTip; public Text relustTxt; public Text testTxt; public Text titleTxt; [HideInInspector] public bool isCountDown = false; [Header("倒计时组件")] public GameObject TimeObj; public Text minuteTxt; public Text secondTxt; [Header("分数组件")] public GameObject scoreItem; public Text scoreTxt; public float passingScore; public Text FailTxt; public Text SuccedTxt; [Header("当前正在答题关卡")] public PassPart CurrentPass; public GameObject userTip; //记录选择题答案字典 public Dictionary> _choiceDict = new Dictionary>(); //记录多选题答案字典 public Dictionary> _moreChoiceDict = new Dictionary>(); //记录操作题答案字典 public Dictionary> _oprerationDict = new Dictionary>(); //关卡管理 [HideInInspector] public List _passList = new List(); //错题集合 public Dictionary> _errorDict = new Dictionary>(); public List _unDoneList = new List(); //已检查过的多答案题 private Dictionary OKQuesitionDict = new Dictionary(); //考试题型列表 private Dictionary _testPassDict = new Dictionary(); public int[] TestScore; public int[] TestScore2; public int[] TestScore3; public int[] TestScore4; public int[] TestScore5; public int[] TestScore6; private void Awake() { if (GameRoot.Instance == null) { DontDestroyOnLoad(this); Instance = this; } float ran = Random.Range(0.1f, 1); if (ran > 0.5f) { ABType = 0; ABtext.text = "A"; } else { ABType = 1; ABtext.text = "B"; } //配置文件加载 resSvc = GetComponent(); resSvc.Init(); //关卡完成状态初始化 if (isRndom && !isFree) { AllPassCount = 12; } else if (!isRndom && !isFree) { AllPassCount = 12; } else if (isFree) { AllPassCount = 1; } PassOverGroup = new bool[AllPassCount + 1]; for (int i = 0; i < PassOverGroup.Length; i++) { PassOverGroup[i] = false; } //加载菜单 LoadMenu(); //_cavans = this.transform.Find("Canvas").gameObject; testTxt.text = Screen.width + "-" + Screen.height; TimeOutBtn.onClick.AddListener(() => { TimeOutTip.SetActive(false); TimeObj.SetActive(false); //CheckAllPassOver(); //ChceckAllAnswer(); ReturnMenu(); }); if (isRndom) { titleTxt.text = "消防技能在线模拟考试-考核模式"; } else { titleTxt.text = "消防技能在线模拟考试-练习模式"; } RegisterTestPass(); resSvc.GetSomePassScore(1, TestScore); //resSvc.GetSomePassScore(2,TestScore2); //resSvc.GetSomePassScore(3,TestScore3); //resSvc.GetSomePassScore(4,TestScore4); //resSvc.GetSomePassScore(5,TestScore5); //resSvc.GetSomePassScore(6,TestScore6); } private void Start() { //EduCoderTool.WebConnecter.Singleton.SendMsg("type", "getTaskData"); EduCoderTool.WebConnecter.Singleton.SendMsg("type", "getTaskData"); } float timer = 0f; private void Update() { if (prgCB != null) { prgCB(); } //更新得分 //if (isRndom) //{ // _score = Mathf.Clamp(_score, 0, 100); //} scoreTxt.text = _score.ToString(); timer += Time.deltaTime; if (timer>=5f) { EduCoderTool.WebConnecter.Singleton.SendMsg("type", "checkUserStatus"); EduCoderTool.WebConnecter.Singleton.SendMsg("type", "getTaskData"); if (userText.text.Contains("游客")) { userTip.SetActive(true); } else { userTip.SetActive(false); } timer = 0f; } } /// /// 提交按钮的所有题是否完成检测方法 /// public void CheckAllPassOver() { int num = 0; for (int i = 0; i < PassOverGroup.Length; i++) { if (PassOverGroup[i]) { num++; } } if (num != PassOverGroup.Length) { sumbitTip.gameObject.SetActive(true); } else { Result(); } } #region 答案管理方法 /// /// 检查所有题型答案 /// public void ChceckAllAnswer() { Debug.Log("开始检测答案"); CheckChoiceAnswer(); CheckMoreChoiceAnswer(); CheckOperationAnswer(); string str = ""; int index = 0; List lst = new List(); foreach (var item in _errorDict) { str += "-" + item.Key; } Debug.Log("错题有:" + str); } /// /// 提交选择题答案函数 /// PassIndex:关卡索引 /// QuestionIndex:问题索引 /// answer:记录用户所选的答案(ABCD对应0123) /// /// 关卡索引 /// 问题索引 /// 记录用户所选的答案(ABCD对应0123) public static void SubmitChoiceAnswer(int PassIndex, int QuestionIndex, int answer) { Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + answer); if (GameRoot.Instance == null) return; //如果不存在则创建并放入字典 if (!GameRoot.Instance._choiceDict.ContainsKey(PassIndex)) { Dictionary dict = new Dictionary(); dict.Add(QuestionIndex, answer); GameRoot.Instance._choiceDict.Add(PassIndex, dict); Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + answer); } else { //继续记录 int data = answer; Dictionary dict = new Dictionary(); if (GameRoot.Instance._choiceDict.TryGetValue(PassIndex, out dict)) { dict[QuestionIndex] = data; GameRoot.Instance._choiceDict[PassIndex] = dict; Debug.Log("关卡字典已存在,更新" + QuestionIndex + "问题的答案为" + answer); } } } /// /// 提交多选题答案函数 /// PassIndex:关卡索引 /// QuestionIndex:问题索引 /// answer:记录用户所选的答案(ABCD对应0123) /// /// 关卡索引 /// 问题索引 /// 记录用户所选的答案 public static void SubmitMoreChoiceAnswer(int PassIndex, int QuestionIndex, int[] answer, bool isSort = true) { Debug.Log("测试" + "记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + ArrToString(answer)); if (GameRoot.Instance == null) return; //如果不存在则创建并放入字典 if (!GameRoot.Instance._moreChoiceDict.ContainsKey(PassIndex)) { Dictionary dict = new Dictionary(); dict.Add(QuestionIndex, answer); GameRoot.Instance._moreChoiceDict.Add(PassIndex, dict); if (isSort) { Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + ArrToString(answer, true)); } else { Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + ArrToString(answer, false)); } } else { //继续记录 int[] data = answer; Dictionary dict = new Dictionary(); if (GameRoot.Instance._moreChoiceDict.TryGetValue(PassIndex, out dict)) { dict[QuestionIndex] = data; GameRoot.Instance._moreChoiceDict[PassIndex] = dict; Debug.Log("关卡字典已存在,更新" + QuestionIndex + "问题的答案为" + answer); } } } /// /// 提交操作题答案函数 /// PassIndex:关卡索引 /// QuestionIndex:问题索引 /// answer:记录用户所选的答案(ABCD对应0123) /// /// 关卡索引 /// 问题索引 /// 记录用户所选的答案 public static void SubmitOprerationAnswer(int PassIndex, int QuestionIndex, bool[] answer) { Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + ArrToString(answer)); ; if (GameRoot.Instance == null) return; //如果不存在则创建并放入字典 if (!GameRoot.Instance._oprerationDict.ContainsKey(PassIndex)) { Dictionary dict = new Dictionary(); dict.Add(QuestionIndex, answer); GameRoot.Instance._oprerationDict.Add(PassIndex, dict); Debug.Log("记录第" + PassIndex + "关卡" + QuestionIndex + "的问题答案为" + answer.ToString()); } else { //继续记录 bool[] data = answer; Dictionary dict = new Dictionary(); if (GameRoot.Instance._oprerationDict.TryGetValue(PassIndex, out dict)) { dict[QuestionIndex] = data; GameRoot.Instance._oprerationDict[PassIndex] = dict; Debug.Log("关卡字典已存在,更新" + QuestionIndex + "问题的答案为" + answer.ToString()); } } } public void AddScore(int passIndex, int key) { _score += resSvc.GetQuestionScore(passIndex, key); //if (passIndex <= 8) //{ // passingScore += resSvc.GetQuestionScore(passIndex, key); //} } /// /// 核算选择题方法 /// public void CheckChoiceAnswer() { foreach (var item in _choiceDict) { PassPart passPart = null; int PassIndex = item.Key; List list = new List(); foreach (var answer in item.Value) { switch (PassIndex) { case 7: if (answer.Key == 1) { if (answer.Value == 1 || answer.Value == 2) { AddScore(PassIndex, answer.Key); } else { #region 加入错误集 for (int i = 0; i < _passList.Count; i++) { if (_passList[i].passInfo.PassIndex == PassIndex) { passPart = _passList[i]; } } list.Add(answer.Key); if (_errorDict.ContainsKey(passPart._passIndex)) { List templist = new List(); templist = _errorDict[passPart._passIndex]; if (!templist.Contains(answer.Key)) { templist.Add(answer.Key); } _errorDict[passPart._passIndex] = templist; } else { _errorDict.Add(passPart._passIndex, list); } Debug.Log("第" + passPart._passIndex + "关第" + answer.Key + "小题错误"); #endregion } } if (answer.Key == 3) { if (answer.Value != 0) { AddScore(PassIndex, answer.Key); } } int[] indexs_7 = { 1, 3 }; if (!OKQuesitionDict.ContainsKey(7)) { OKQuesitionDict.Add(7, indexs_7); } break; } //此变量用来判断当前小题是否是已经判断过的“多答案题”,如是则跳往下个小题判断 bool skip = false; foreach (var arr in OKQuesitionDict) { for (int i = 0; i < arr.Value.Length; i++) { if (PassIndex == arr.Key && arr.Value[i] == answer.Key) { skip = true; } } } if (!skip) { if (resSvc.CheckAnswerIsTrue(PassIndex, answer.Key, answer.Value) == false)//检测是否正确 { for (int i = 0; i < _passList.Count; i++) { if (_passList[i].passInfo.PassIndex == PassIndex) { passPart = _passList[i]; } } list.Add(answer.Key); if (_errorDict.ContainsKey(passPart._passIndex)) { List templist = new List(); templist = _errorDict[passPart._passIndex]; if (!templist.Contains(answer.Key)) { templist.Add(answer.Key); } _errorDict[passPart._passIndex] = templist; } else { _errorDict.Add(passPart._passIndex, list); } Debug.Log("第" + passPart._passIndex + "关第" + answer.Key + "小题错误"); } else { AddScore(PassIndex, answer.Key); } } } } } /// /// 核算多选题题方法 /// public void CheckMoreChoiceAnswer() { foreach (var item in _moreChoiceDict) { PassPart passPart = null; int PassIndex = item.Key; List list = new List(); foreach (var answer in item.Value) { if (resSvc.CheckAnswerIsTrue(PassIndex, answer.Key, answer.Value) == false)//如果错误则加入错题集 { for (int i = 0; i < _passList.Count; i++) { if (_passList[i].passInfo.PassIndex == PassIndex) { passPart = _passList[i]; } } list.Add(answer.Key); if (_errorDict.ContainsKey(passPart._passIndex)) { List templist = new List(); templist = _errorDict[passPart._passIndex]; if (!templist.Contains(answer.Key)) { templist.Add(answer.Key); } _errorDict[passPart._passIndex] = templist; } else { _errorDict.Add(passPart._passIndex, list); } Debug.Log("第" + passPart._passIndex + "关第" + answer.Key + "小题错误"); } else { AddScore(PassIndex, answer.Key); } } } } /// /// 核算操作题方法 /// public void CheckOperationAnswer() { foreach (var item in _oprerationDict) { PassPart passPart = null; int PassIndex = item.Key; List list = new List(); foreach (var answer in item.Value) { int index = 0; for (int i = 0; i < answer.Value.Length; i++) { if (answer.Value[i] == false) { for (int j = 0; j < _passList.Count; j++) { if (_passList[j].passInfo.PassIndex == PassIndex) { passPart = _passList[j]; } } list.Add(answer.Key); if (_errorDict.ContainsKey(passPart._passIndex)) { List templist = new List(); templist = _errorDict[passPart._passIndex]; if (!templist.Contains(answer.Key)) { templist.Add(answer.Key); } _errorDict[passPart._passIndex] = templist; } else { _errorDict.Add(passPart._passIndex, list); } Debug.Log("第" + passPart._passIndex + "关第" + answer.Key + "小题错误"); } else { index++; } if (answer.Value.Length == index) { AddScore(PassIndex, answer.Key); } } } } } #endregion #region 关卡管理 private void RegisterTestPass() { int count = testTypeCount;//共有几套试卷 int index = 8;//每套抽取数量 int[] testPass; for (int i = 1; i < count + 1; i++) { switch (i) { case 1: testPass = new int[] { 32, 10, 11, 12, 13, 14, 15, 16 }; _testPassDict.Add(i, testPass); break; case 2: testPass = new int[] { 19, 20, 21, 25, 18, 27, 17, 22 }; _testPassDict.Add(i, testPass); break; case 3: testPass = new int[] { 9, 10, 11, 12, 14, 18, 23, 24 }; _testPassDict.Add(i, testPass); break; case 4: testPass = new int[] { 32, 19, 20, 25, 27, 14, 26, 28 }; _testPassDict.Add(i, testPass); break; case 5: testPass = new int[] { 10, 20, 21, 12, 27, 14, 29, 30 }; _testPassDict.Add(i, testPass); break; case 6: testPass = new int[] { 25, 10, 11, 32, 13, 18, 31, 15 }; _testPassDict.Add(i, testPass); break; } } } /// /// 考核模式下计时 /// public void StartCountDownTime() { isCountDown = true; TimeObj.SetActive(true); float time = CurrentPass.passInfo.time; StartCoroutine(CountDown(time, minuteTxt, secondTxt, () => { // PassOverGroup[CurrentPass._passIndex] = true; if (isRndom) { CurrentPass.passOver(); TimeOutTip.SetActive(true); } })); } IEnumerator CountDown(float minute, Text MinuteText, Text SecendText, Action action = null) { float min = minute; float scend = 0; MinuteText.text = min.ToString("0"); SecendText.text = scend.ToString("0"); while (isCountDown) { yield return new WaitForEndOfFrame(); if (scend <= 0) { min -= 1; scend = 60; MinuteText.text = min.ToString("0"); SecendText.text = scend.ToString("0"); } else { scend -= Time.deltaTime; SecendText.text = scend.ToString("0"); } if (min < 0) { MinuteText.text = 0.ToString("0"); SecendText.text = 0.ToString("0"); if (action != null) action(); break; } } } /// /// 加载关卡选择窗口 /// /// /// /// /// public void LoadPassPart(string path, bool isRandom, int passNum, Transform parent) { if (isFree) { GameObject pass = Resources.Load(path); PassInfo info = resSvc.GetPassInfo(10); if (info != null) { GameObject go = GameObject.Instantiate(pass, parent); PassPart passPart = go.AddComponent(); passPart.passInfo = info; passPart.SetPassIndex(10 ); passPart.Init(); //记录 _passList.Add(passPart); } return; } if (!isRandom) { if (_passList.Count == 0) { for (int i = 1; i < passNum + 1; i++) { GameObject pass = Resources.Load(path); if (pass != null) { int index = i; PassInfo info = resSvc.GetPassInfo(i); if (info != null) { GameObject go = GameObject.Instantiate(pass, parent); PassPart passPart = go.AddComponent(); passPart.passInfo = info; passPart.SetPassIndex(index); passPart.Init(); //记录 _passList.Add(passPart); } else { Debug.Log("加载" + info + "不存在"); } } else { Debug.Log(path + "加载预设不存在"); } } } } else { if (_passList.Count == 0) { //for (int i = 1; i <= 12; i++) //{ // GameObject pass = Resources.Load(path); // if (pass != null) // { // int index = i; // PassInfo info = resSvc.GetPassInfo(i); // if (info != null) // { // GameObject go = GameObject.Instantiate(pass, parent); // PassPart passPart = go.AddComponent(); // passPart.passInfo = info; // passPart.SetPassIndex(index); // passPart.Init(); // //记录 // _passList.Add(passPart); // } // else // { // Debug.Log("加载" + info + "不存在"); // } // } //} //随机加载6套剩余题型 --- 消防中级用不到 //if (_TestIndex == 0) //{ // _TestIndex = Random.Range(1, 6); //} //int testIndex=_TestIndex; //int[] passGroup; //if (_testPassDict.TryGetValue(testIndex, out passGroup)) //{ // for (int i = 0; i < passGroup.Length; i++) // { // GameObject pass = Resources.Load(path); // if (pass != null) // { // int index = passGroup[i]; // PassInfo info = resSvc.GetPassInfo(index); // info.PassIndex = index; // if (info != null) // { // GameObject go = GameObject.Instantiate(pass, parent); // PassPart passPart = go.AddComponent(); // passPart.passInfo = info; // passPart.SetPassIndex(i+1+ passGroup.Length); // passPart.Init(); // //记录 // _passList.Add(passPart); // } // else // { // Debug.Log("加载" + info + "不存在"); // } // } // } #region 随机加载剩余关卡(备用) int[] nums = new int[12]; for (int i = 0; i < 12; i++) { nums[i] = i + 1; } //GetRandomNum(nums); RandomSort(nums); for (int i = 0; i < AllPassCount; i++) { GameObject pass = Resources.Load(path); if (pass != null) { int index = nums[i]; PassInfo info = resSvc.GetPassInfo(index); if (info != null) { GameObject go = GameObject.Instantiate(pass, parent); PassPart passPart = go.AddComponent(); passPart.passInfo = info; passPart.SetPassIndex(i + 1); passPart.Init(); //记录 _passList.Add(passPart); } else { Debug.Log("加载" + info.PassIndex + "不存在"); } } } #endregion } } } /// /// 记录关卡是否完成 /// /// 关卡索引 /// 是否完成 public static void SubmitPassState(int passIndex, bool isover) { if (GameRoot.Instance == null || isover == false) return; foreach (var item in GameRoot.Instance._passList) { if (item.passInfo.PassIndex == passIndex) { GameRoot.Instance.PassOverGroup[item._passIndex] = true; Debug.Log("提示:" + item._passIndex + "关已完成"); } } } private Action prgCB = null; public void AsyncLoadScene(string sceneName, Action loaded) { AsyncOperation sceneAsync = SceneManager.LoadSceneAsync(sceneName); prgCB = () => { float val = sceneAsync.progress; if (val == 1) { if (loaded != null) { loaded(); } prgCB = null; sceneAsync = null; } }; } public void LoadMenu() { if (GameRoot.Instance == null) return; AsyncLoadScene("Menu", () => { //关卡窗口加载 LoadPassPart("Prefab/UI/part", isRndom, AllPassCount, PassPreant); _cavans.SetActive(true); //考试模式显示分数 if (isRndom) { scoreItem.gameObject.SetActive(true); } else { scoreItem.gameObject.SetActive(false); } }); } /// /// 返回时显示正确答案 /// private void ShowAnswerTip() { GameRoot.Instance.answerTip.SetActive(true); List tips = resSvc.GetAnswerTip(CurrentPass._passIndex); Transform tipsPreant = GameObject.FindGameObjectWithTag("AnswerTipPreant").transform; for (int i = 0; i < tips.Count; i++) { GameObject go = GameObject.Instantiate(Resources.Load("Prefab/UI/answerTip"), tipsPreant); Text txt = go.GetComponent(); txt.text = tips[i].PassIndex + "-" + tips[i].QuestionIndex + ":" + tips[i].answer; go.GetComponent().OnTextChange(txt.text); } } /// /// 清理显示的正确答案 /// public void ClearAnwerTips() { Transform tipsPreant = GameObject.FindGameObjectWithTag("AnswerTipPreant").transform; for (int i = 0; i < tipsPreant.childCount; i++) { Destroy(tipsPreant.GetChild(i).gameObject); } GameRoot.Instance.answerTip.SetActive(false); } /// /// 返回大厅方法 /// public static void ReturnMenu() { if (GameRoot.Instance != null) { //异步加载并且检测已完成的关卡 GameRoot.Instance.AsyncLoadScene("Menu", () => { int num = GameRoot.Instance.PassOverGroup.Length; int overNum = 0; for (int i = 1; i < num; i++) { if (GameRoot.Instance.PassOverGroup[i] == true) { foreach (var item in GameRoot.Instance._passList) { if (item._passIndex == i) { overNum += 1; item.passOver(); } } } } //if (overNum == GameRoot.Instance.AllPassCount) //{ // //跳转进结算界面 // Debug.Log("所有关卡已完成"); // GameRoot.Instance.Result(); //} Debug.Log("目前已完成的关卡数:" + overNum); //关卡窗口恢复 GameRoot.Instance.SetActiveMenuCanvans(true); GameRoot.Instance.TimeObj.SetActive(false); GameRoot.Instance.isCountDown = false; if (!GameRoot.Instance.isRndom) { GameRoot.Instance.ShowAnswerTip(); } }); } else { SceneManager.LoadScene("Menu"); } } public void SetActiveMenuCanvans(bool b) { _cavans.SetActive(b); } /// /// 答题结果 /// public void Result() { SlectedWnd.SetActive(false); ResultWnd.SetActive(true); //检查未做的题 for (int i = 1; i < AllPassCount + 1; i++) { if (PassOverGroup[i] == false) { _unDoneList.Add(i); } } GameObject truetip = Resources.Load("Prefab/UI/trueTip"); GameObject errtip = Resources.Load("Prefab/UI/errorTip"); GameObject emptyTip = Resources.Load("Prefab/UI/empytTip"); GameObject haveErrorTip = Resources.Load("Prefab/UI/haveErrorTip"); Transform AllTipPreant = GameObject.FindGameObjectWithTag("AllTipPreant").transform; Transform Errorpreant = GameObject.FindGameObjectWithTag("ErrorTipPreant").transform; //先列出所有题号 int num = 0; Image[] images = new Image[_passList.Count + 1]; for (int i = 1; i < _passList.Count + 1; i++) { GameObject go = GameObject.Instantiate(emptyTip, AllTipPreant); go.transform.GetChild(0).GetComponent().text = i.ToString(); images[i] = go.GetComponent(); num++; } relustTxt.text = num.ToString(); //将题号按颜色区分 红-全错 灰-有错有对 -白未做 for (int i = 1; i < images.Length; i++) { images[i].color = Color.green; } foreach (var item in _errorDict) { for (int i = 0; i < item.Value.Count; i++) { images[item.Key].color = Color.red; } } for (int i = 0; i < _unDoneList.Count; i++)//-未做的题 { int index = _unDoneList[i]; images[index].color = Color.white; } List keyList = new List(); List errorNote = new List();//错误详细列表 foreach (var item in _errorDict) { keyList.Add(item.Key); } //先排序关卡号 for (int i = 0; i < keyList.Count - 1; i++) { for (int j = 0; j < keyList.Count - 2; j++) { if (keyList[j] > keyList[j + 1]) { int temp = keyList[j]; keyList[j] = keyList[j + 1]; keyList[j + 1] = temp; } } } //再排序小题号 for (int i = 0; i < keyList.Count; i++) { List tempList = new List(); if (_errorDict.TryGetValue(keyList[i], out tempList)) { //排序 for (int j = 0; j < tempList.Count - 1; j++) { for (int k = 0; k < tempList.Count - 2; k++) { if (tempList[j] > tempList[j + 1]) { int temp = tempList[j]; tempList[j] = tempList[j + 1]; try { tempList[j + 1] = temp; } catch { Debug.LogWarning(j + "-" + j + 1); } } } } //创建错误提示 for (int a = 0; a < tempList.Count; a++) { GameObject go = GameObject.Instantiate(errtip, Errorpreant); go.transform.GetChild(0).GetComponent().text = keyList[i] + "-" + tempList[a]; } } //显示是否合格 if (_score < 30 || _unDoneList.Count > 0) { FailTxt.gameObject.SetActive(true); } else if (_score >= 30) { SuccedTxt.gameObject.SetActive(true); } } } //重新开启答题 public void ReStart() { Destroy(this.gameObject); SceneManager.LoadScene("Start"); } public void SubmitScoreToEducoder() { if (isRndom) { EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true,(double)_score); Debug.Log("已上传成绩为" + _score); } } #endregion #region 其他 void RandomSort(int[] array) { int last = array.Length - 1; for (int i = 0; i < array.Length; i++) { //剩下的牌的总数 int num = array.Length - i; int randomIndex = Random.Range(0, num);//随机抽一张牌 int temp = array[last]; array[last] = array[randomIndex]; array[randomIndex] = temp; last--;//位置改变 } } public int[] GetRandomNum(int[] num) { for (int i = 0; i < num.Length; i++) { int temp = num[i]; int randomIndex = Random.Range(0, num.Length); num[i] = num[randomIndex]; num[randomIndex] = temp; } return num; } public static string ArrToString(int[] arr, bool isSort = true) { string str = ""; int[] arrP = new int[arr.Length]; if (isSort) { arrP = Sort(arr); } else { arrP = arr; } //int[] arrP = Sort(arr); for (int i = 0; i < arrP.Length; i++) { if (arrP[i].ToString() != "") { str += arrP[i].ToString(); } } return str; } public static string ArrToString(bool[] arr) { string str = ""; for (int i = 0; i < arr.Length; i++) { if (arr[i].ToString() != "") { str += arr[i].ToString(); } } return str; } public static int[] Sort(int[] arr) { for (var i = 0; i < arr.Length; i++) { //每一轮数值比较 for (var j = i; j < arr.Length - 1; j++) { //谁小谁放在前面 if (arr[i] > arr[i + 1]) { var temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; } } } return arr; #endregion } } public class UserData { public string username; }