PranticeManagerForPC.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using ChivaXR;
  2. using ChivaXR.Op;
  3. using Org.BouncyCastle.Bcpg.OpenPgp;
  4. using QFramework;
  5. using Sirenix.OdinInspector;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEditor;
  10. using UnityEngine;
  11. public class PranticeManagerForPC : MonoBehaviour
  12. {
  13. public static PranticeManagerForPC instance;
  14. [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
  15. /// <summary>
  16. /// 考试信息
  17. /// </summary>
  18. [TableList(MaxScrollViewHeight = 20)]
  19. public List<PranticeProcessElement> m_PranticeProcessElements;
  20. private ProcessElement currentProcessElement;
  21. [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
  22. [Button("1.获取流程信息")]
  23. public void GetPranticeProcessElements()
  24. {
  25. List<ProcessElement> processElements = ProcessManagement.Instance.processes;
  26. //临时转存,用户数据恢复
  27. List<PranticeProcessElement> tmpExamProcessElements = m_PranticeProcessElements;
  28. //重建考试信息列表
  29. m_PranticeProcessElements = new List<PranticeProcessElement>();
  30. foreach (var item in processElements)
  31. {
  32. PranticeProcessElement examProcessElement = tmpExamProcessElements.Find(t => t.elementDescript == item.processBase.GetPBDescribe());
  33. if (examProcessElement != null)
  34. {
  35. m_PranticeProcessElements.Add(examProcessElement);
  36. }
  37. else
  38. {
  39. StepListProxy tmpProxy = DAL.Instance.Get<StepListProxy>();
  40. if (tmpProxy == null)
  41. {
  42. tmpProxy.ReadStepMsgInfoFromTable(OperateSetting.Instance.m_CourseName);
  43. }
  44. OperationStepDataInfo tmpInfo = tmpProxy.GetOpStepDataInfoById(item.stepID);
  45. m_PranticeProcessElements.Add(new PranticeProcessElement()
  46. {
  47. id = item.stepID,
  48. elementDescript = item.processBase.GetPBDescribe(),
  49. stepName = tmpInfo.stepName
  50. });
  51. }
  52. }
  53. }
  54. /// <summary>
  55. /// 练习开始时间
  56. /// </summary>
  57. public DateTime m_StartTime;
  58. /// <summary>
  59. /// 练习结束时间
  60. /// </summary>
  61. public DateTime m_EndTime;
  62. private void Awake()
  63. {
  64. instance = this;
  65. GetPranticeProcessElements();
  66. m_StartTime = DateTime.Now;
  67. }
  68. public void Init()
  69. {
  70. ProcessManagement.Instance.processElementActiveEvent += ProcessElementActive;
  71. ProcessManagement.Instance.processElementDisActiveEvent += ProcessElementDisActive;
  72. ProcessManagement.Instance.processFinishEvent += PranticeFinish;
  73. }
  74. /// <summary>
  75. /// 步骤进入
  76. /// </summary>
  77. /// <param name="element"></param>
  78. private void ProcessElementActive(ProcessElement element)
  79. {
  80. currentProcessElement = element;
  81. }
  82. /// <summary>
  83. /// 步骤退出
  84. /// </summary>
  85. /// <param name="element"></param>
  86. private void ProcessElementDisActive(ProcessElement element)
  87. {
  88. JianTouManager.instance.SetJianTouActive(false);
  89. PranticeProcessElement tmpElement = m_PranticeProcessElements.Find(t => t.elementDescript == currentProcessElement.processBase.GetPBDescribe());
  90. if (tmpElement.finish == false)
  91. {
  92. tmpElement.finish = true;
  93. if (tmpElement.errorReason == null)
  94. {
  95. tmpElement.result = true;
  96. }
  97. tmpElement.operationTime = DateTime.Now;
  98. }
  99. }
  100. /// <summary>
  101. /// 成绩展示
  102. /// </summary>
  103. public void PranticeFinish()
  104. {
  105. m_EndTime = DateTime.Now;
  106. UIKit.OpenPanel<PC_PranticeResultPanel>(new PC_PranticeResultPanelData() { pranticeProcessElementsData = m_PranticeProcessElements });
  107. }
  108. /// <summary>
  109. /// 记录操作错误
  110. /// </summary>
  111. /// <param name="processId"></param>
  112. public void RecordFault(int processId)
  113. {
  114. PranticeProcessElement tmpElement = m_PranticeProcessElements.Find(t => t.id == processId);
  115. if (tmpElement != null)
  116. {
  117. tmpElement.errorReason = "操作错误";
  118. tmpElement.result = false;
  119. string screenShotName = DateTime.UtcNow.Ticks.ToString();
  120. StartCoroutine(ScrrenCapture(new Rect(0, 0, Screen.width, Screen.height), 0, screenShotName, tmpElement));
  121. }
  122. }
  123. Texture2D screenShot;//保存截取的纹理
  124. IEnumerator ScrrenCapture(Rect rect, int a, string screenShotName, PranticeProcessElement pranticeProcessElement)
  125. {
  126. Debug.Log("截图:" + screenShotName);
  127. screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
  128. yield return new WaitForSeconds(0.5f);
  129. yield return new WaitForEndOfFrame();
  130. screenShot.ReadPixels(rect, 0, 0);
  131. screenShot.Apply();
  132. //推送
  133. //PushHelper.InitBasicData();
  134. //StartCoroutine(PushHelper.SendFileStreamPushRequest(screenShot, screenShotName, (result, msg, flag, cmnAttachId) =>
  135. // {
  136. // if (!result)
  137. // {
  138. // Debug.LogError(msg);
  139. // }
  140. // else
  141. // {
  142. // pranticeProcessElement.screenshotList.Add(cmnAttachId.data.cmnAttachId);
  143. // }
  144. // pranticeProcessElement.m_UpLoading.Remove(screenShotName);
  145. // }));
  146. pranticeProcessElement.m_UpLoading.Add(screenShotName);
  147. }
  148. /// <summary>
  149. /// 是否上传完成
  150. /// </summary>
  151. /// <returns></returns>
  152. public bool IsFinishUpLoad()
  153. {
  154. foreach (var item in m_PranticeProcessElements)
  155. {
  156. if (item.m_UpLoading.Count > 0)
  157. {
  158. return false;
  159. }
  160. }
  161. return true;
  162. }
  163. }
  164. [Serializable]
  165. public class PranticeProcessElement
  166. {
  167. [Sirenix.OdinInspector.ReadOnly]
  168. public int id;
  169. [Sirenix.OdinInspector.ReadOnly]
  170. public string elementDescript;
  171. /// <summary>
  172. /// 错误与否
  173. /// </summary>
  174. [Sirenix.OdinInspector.ReadOnly]
  175. public bool result;
  176. /// <summary>
  177. /// 是否完成
  178. /// </summary>
  179. [Sirenix.OdinInspector.ReadOnly]
  180. public bool finish = false;
  181. /// <summary>
  182. /// 错误截图
  183. /// </summary>
  184. public List<string> screenshotList = new List<string>();
  185. /// <summary>
  186. /// 操作时间
  187. /// </summary>
  188. public DateTime operationTime;
  189. /// <summary>
  190. /// 错误原因
  191. /// </summary>
  192. public string errorReason;
  193. /// <summary>
  194. /// 步骤名称
  195. /// </summary>
  196. public string stepName;
  197. /// <summary>
  198. /// 正在上传的任务
  199. /// </summary>
  200. public List<string> m_UpLoading = new List<string>();
  201. }