public void StartToDownload(ClassPaper classPaper) { closeBtn.SetActive(false); textLog.text = ""; RestUI(); StartCoroutine(GetAPaperInfo(classPaper)); }
private void PutContent() { for (int i = 0; i < content.childCount; i++) { Destroy(content.GetChild(i).gameObject); } PaperManager.GetFileList();//取得文件列表 List <int> allDownloadedID = PaperManager.GetAllDownloadID(); for (int i = allPaper.data.Count - 1; i >= 0; i--) { ClassPaper cp = allPaper.data[i]; GameObject gm = Instantiate(buttonPerfab, content); ExamItemCtrl eic = gm.GetComponentInChildren <ExamItemCtrl>(); string pj = cp.SoeAllow ? "<Color=Green>支持机器评卷</Color>" : "<Color=Red>不支持机器评卷</Color>"; //Debug.Log(cp.SoeAllow); eic.textItem.text = string.Format( "{0}\n<Color=Red>{1}<Color=Grey>_</Color>{2}</Color>", cp.name, cp.type, pj ); if (allDownloadedID.Contains(cp.id)) { LuoHaoExamPaper lhep = PaperManager.allDownloadedPaperFile[allPaper.data[i].id]; eic.isDownloaded = true; eic.classPaper = lhep.paper; eic.textItem.text += "\n<Color=Green>已下载</Color> <Color=Orange>大小:" + lhep.size + "</Color>\n<Color=Grey>时间:" + lhep.time + "</Color>"; eic.downloadBtnText.text = "删除"; eic.filePath = PaperManager.allDownloadedPath[lhep.id]; } else { eic.isDownloaded = false; eic.classPaper = allPaper.data[i]; eic.textItem.text += "\n<Color=Orange>未下载</Color>"; eic.downloadBtnText.text = "下载"; } } }
IEnumerator GetAPaperInfo(ClassPaper classPaper) { string url = GetPermisson.GetServerAddress + "/Paper/GetAPaper.php?token=" + UnityWebRequest.EscapeURL(LoginToKaoShi.userLoginCallback.data.token) + "&paperID=" + classPaper.id; UnityWebRequest uwr = UnityWebRequest.Get(url); //Debug.Log(LoginToKaoShi.userLoginCallback.data.token); //Debug.Log(url); textLog.text += "\n请求试卷信息..."; textInfo.text = "正在寻找试卷信息..."; uwr.SendWebRequest(); while (true) { textProcess.text = GetProcess(uwr.downloadProgress); imgProcess.fillAmount = uwr.downloadProgress; if (uwr.isDone) { break; } yield return(new WaitForSeconds(0.02f)); } if (uwr.error == "" || uwr.error == null) { try { apaper = JsonUtility.FromJson <APaper>(uwr.downloadHandler.text); // Debug.Log(uwr.downloadHandler.text); switch (apaper.code) { case 0: textLog.text += "\n试卷信息请求成功!"; /*创建文件夹*/ PaperManager.CreateBaseDir(apaper.data.id.ToString() + "EP"); textLog.text += "\n创建基文件夹成功!"; StartCoroutine(FileDownloadManager()); break; default: GlobalUIManager.guim.CreateNewDialogBox(apaper.msg); ShowCloseUI(); break; } } catch (System.Exception e) { textLog.text += "\n试卷信息请求失败!" + e.Message; GlobalUIManager.guim.CreateNewDialogBox("发生异常!请联系开发者!" + e.Message); ShowCloseUI(); } } else { GlobalUIManager.guim.CreateNewDialogBox(uwr.error); textLog.text += "\n发生异常!" + uwr.error; ShowCloseUI(); } }
/// <summary> /// 加载全部音频 /// </summary> /// <param name="cp"></param> /// <param name="callback"></param> /// <returns></returns> public IEnumerator LoadAnPaperAllAudios(ClassPaper cp, System.Action <Dictionary <string, AudioClip> > callback) { Dictionary <string, AudioClip> audioClips = new Dictionary <string, AudioClip>(); string[] stra = cp.partb_audio_ask.Split('/'); string[] strb = cp.partb_audio_anser.Split('/'); int acount = stra.Length; int bcount = strb.Length; ///传值 ProcessCtrl.threeAnser = strb; ProcessCtrl.fiveSubject = stra; for (int i = 0; i < stra.Length; i++) { if (!string.IsNullOrEmpty(stra[i].Trim())) { StartCoroutine(GetAudio(cp.path + "/" + stra[i], stra[i], delegate(string aname, AudioClip ac) { audioClips.Add(aname, ac); } )); } else { acount -= 1; } } for (int i = 0; i < strb.Length; i++) { if (!string.IsNullOrEmpty(strb[i].Trim())) { StartCoroutine(GetAudio(cp.path + "/" + strb[i], strb[i], delegate(string aname, AudioClip ac) { audioClips.Add(aname, ac); } )); } else { bcount -= 1; } } //PartC int ccount = 1; if (!string.IsNullOrEmpty(cp.partc_audio_name.Trim())) { StartCoroutine(GetAudio(cp.path + "/" + cp.partc_audio_name, cp.partc_audio_name, delegate(string aname, AudioClip ac) { audioClips.Add(aname, ac); } )); } else { ccount -= 1; } while (true) { if (audioClips.Count == acount + bcount + ccount) { callback?.Invoke(audioClips); break; } yield return(null); } }