ExamManagerForVR.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. namespace ChivaXR.Op
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using Sirenix.OdinInspector;
  8. using VRTK;
  9. using ChivaXR.VR;
  10. using ProcedureBYQ;
  11. using QFramework;
  12. [RequireComponent(typeof(ExamHandleManager))]
  13. public class ExamManagerForVR : MonoBehaviour
  14. {
  15. public static ExamManagerForVR instance;
  16. public ExamProxy examProxy;
  17. #region 场景配置模块
  18. [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
  19. [Button("1.获取流程信息")]
  20. public void GetEaxmProcessElements()
  21. {
  22. List<ProcessElement> processElements = ProcessManagement.Instance.processes;
  23. //临时转存,用户数据恢复
  24. List<ExamProcessElement> tmpExamProcessElements = examProcessElements;
  25. //重建考试信息列表
  26. examProcessElements = new List<ExamProcessElement>();
  27. foreach (var item in processElements)
  28. {
  29. ExamProcessElement examProcessElement = tmpExamProcessElements.Find(t => t.elementDescript == item.processBase.GetPBDescribe());
  30. if (examProcessElement != null)
  31. {
  32. examProcessElements.Add(examProcessElement);
  33. }
  34. else
  35. {
  36. StepListProxy tmpProxy = DAL.Instance.Get<StepListProxy>();
  37. OperationStepDataInfo tmpInfo = tmpProxy.GetOpStepDataInfoById(item.stepID);
  38. examProcessElements.Add(new ExamProcessElement()
  39. {
  40. id = item.stepID,
  41. elementDescript = item.processBase.GetPBDescribe(),
  42. stepName = tmpInfo.stepName
  43. });
  44. }
  45. }
  46. }
  47. [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
  48. [Button("2.将所有的CurvedUI和箭头置为禁用(不影响编辑器跳步)")]
  49. public void GetCurvedUIAndDiasable()
  50. {
  51. //将环形UI置为禁用状态
  52. List<ProcessElement> processElements = ProcessManagement.Instance.processes;
  53. foreach (var item in processElements)
  54. {
  55. ProcessState_CurvedUI curvedUI = item.gameObject.GetComponent<ProcessState_CurvedUI>();
  56. if (curvedUI != null)
  57. {
  58. curvedUI.active = false;
  59. }
  60. }
  61. //将箭头提示置为禁用状态
  62. JianTouManager.Instance.SetJianTouActive(false);
  63. }
  64. [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
  65. [Button("3、初始化流程分数")]
  66. public void SetEaxmProcessScore()
  67. {
  68. if (examProcessElements.Count <= 0)
  69. {
  70. return;
  71. }
  72. foreach (var item in examProcessElements)
  73. {
  74. if (examProcessElements.Count <= 100)
  75. {
  76. item.scores = 1;
  77. }
  78. else
  79. {
  80. //item.scores = 100 / examProcessElements.Count;
  81. item.scores = 0.5f;
  82. }
  83. }
  84. RefreshScore();
  85. }
  86. #endregion
  87. #region 配分模块
  88. [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
  89. /// <summary>
  90. /// 考试信息
  91. /// </summary>
  92. [TableList(MaxScrollViewHeight = 20)]
  93. public List<ExamProcessElement> examProcessElements;
  94. private ProcessElement currentProcessElement;
  95. #endregion
  96. #region 成绩展示模块
  97. [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
  98. [LabelText("配置总分"), GUIColor(0, 1, 1, 1)]
  99. [Sirenix.OdinInspector.ReadOnly]
  100. public float totalScore;
  101. [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
  102. [Button("刷新总设定分数")]
  103. public void RefreshScore()
  104. {
  105. totalScore = 0;
  106. foreach (var item in examProcessElements)
  107. {
  108. totalScore += item.scores;
  109. }
  110. }
  111. [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
  112. [LabelText("最终得分"), GUIColor(1, 0.92f, 0.016f, 1)]
  113. [Sirenix.OdinInspector.ReadOnly]
  114. public float score;
  115. [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
  116. [LabelText("成绩展示时相机位置"), GUIColor(1, 0.92f, 0.016f, 1)]
  117. public Vector3 CameraPosition = new Vector3(-0.5461204f, -0.5791085f, 0.8489573f);
  118. [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
  119. [LabelText("成绩展示时相机角度"), GUIColor(1, 0.92f, 0.016f, 1)]
  120. public Quaternion CameraRotation = new Quaternion(0, 180, 0, 0);
  121. [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
  122. [LabelText("成绩展示时禁用相机移动"), GUIColor(1, 0.92f, 0.016f, 1)]
  123. public bool DisableCamerMove = false;
  124. private bool mResultUpLoad = false;
  125. [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
  126. [Button("打开成绩面板(运行时生效)")]
  127. public void ExamFinish()
  128. {
  129. SetCamerRigPositionAndRotation();
  130. ShowExamResultPanel();
  131. SetCamerRigDisable();
  132. UpLoadScore();
  133. CountExamDuration();
  134. }
  135. public void UpLoadScore()
  136. {
  137. examProxy.UpLoadExamResult(SettlementScore());
  138. mResultUpLoad = true;
  139. }
  140. /// <summary>
  141. /// 展示考试信息
  142. /// </summary>
  143. /// <returns></returns>
  144. private ExamResultPanel ShowExamResultPanel()
  145. {
  146. ExamResultPanel tmpExamPanel = null;
  147. if (Application.isPlaying)
  148. {
  149. tmpExamPanel = FindObjectOfType<ExamResultPanel>();
  150. if (tmpExamPanel == null)
  151. {
  152. var resLoader = ResLoader.Allocate();
  153. GameObject tmpPrefab = resLoader.LoadSync<GameObject>("ExamResultCanvas");
  154. if (tmpPrefab == null)
  155. {
  156. Debug.LogError("UI/ExamResultCanvas没有加载到!!!!");
  157. }
  158. else
  159. {
  160. GameObject tmpObj = Instantiate<GameObject>(tmpPrefab, null);
  161. tmpObj.SetActive(true);
  162. tmpExamPanel = tmpObj.GetComponentInChildren<ExamResultPanel>();
  163. }
  164. }
  165. }
  166. if (tmpExamPanel != null) tmpExamPanel.ShowScoreList(examProcessElements, SettlementScore(), m_RecordExamDuration);
  167. return tmpExamPanel;
  168. }
  169. /// <summary>
  170. /// 设置相机位置
  171. /// </summary>
  172. private void SetCamerRigPositionAndRotation()
  173. {
  174. if (Application.isPlaying)
  175. {
  176. GameObject camerRig = GameObject.Find("[CameraRig]");
  177. if (camerRig != null)
  178. {
  179. camerRig.transform.position = CameraPosition;
  180. camerRig.transform.rotation = CameraRotation;
  181. }
  182. }
  183. }
  184. /// <summary>
  185. /// 设置是否禁用相机移动
  186. /// </summary>
  187. private void SetCamerRigDisable()
  188. {
  189. if (Application.isPlaying)
  190. {
  191. PlayMoveWayController playMoveWayController = FindObjectOfType<PlayMoveWayController>();
  192. if (playMoveWayController != null)
  193. {
  194. playMoveWayController.enabled = !DisableCamerMove;
  195. }
  196. }
  197. }
  198. #endregion
  199. /// <summary>
  200. /// 记录考试时长
  201. /// </summary>
  202. private float m_RecordExamDuration;
  203. private void Awake()
  204. {
  205. instance = this;
  206. ProcessManagement.Instance.processElementActiveEvent += ProcessElementActive;
  207. ProcessManagement.Instance.processElementDisActiveEvent += ProcessElementDisActive;
  208. ProcessManagement.Instance.processFinishEvent += ExamFinish;
  209. examProxy = DAL.Instance.Get<ExamProxy>();
  210. examProxy.StartExam();
  211. }
  212. /// <summary>
  213. /// 步骤进入
  214. /// </summary>
  215. /// <param name="element"></param>
  216. private void ProcessElementActive(ProcessElement element)
  217. {
  218. currentProcessElement = element;
  219. }
  220. /// <summary>
  221. /// 步骤退出
  222. /// </summary>
  223. /// <param name="element"></param>
  224. private void ProcessElementDisActive(ProcessElement element)
  225. {
  226. JianTouManager.instance.SetJianTouActive(false);
  227. ExamProcessElement tmpElement = examProcessElements.Find(t => t.elementDescript == currentProcessElement.processBase.GetPBDescribe());
  228. if (tmpElement.finish == false)
  229. {
  230. tmpElement.finish = true;
  231. tmpElement.result = true;
  232. }
  233. SettlementScore();
  234. }
  235. public CVR_HintItem hintItem;
  236. /// <summary>
  237. /// 打开提示
  238. /// </summary>
  239. public void OpenPrompt()
  240. {
  241. SetCuredUIState(true);
  242. JianTouManager.instance.SetJianTouActive(true);
  243. hintItem.OpenHighlighter(OutLineType.hint);
  244. SetCurrentExamElementResult();
  245. }
  246. /// <summary>
  247. /// 设置正在考的步骤的状态
  248. /// </summary>
  249. private void SetCurrentExamElementResult()
  250. {
  251. ExamProcessElement examElent = examProcessElements.Find(t => t.elementDescript == currentProcessElement.processBase.GetPBDescribe());
  252. if (examElent != null)
  253. {
  254. examElent.finish = true;
  255. examElent.result = false;
  256. }
  257. }
  258. /// <summary>
  259. /// 设置环形UI状态
  260. /// </summary>
  261. /// <param name="state"></param>
  262. private void SetCuredUIState(bool state)
  263. {
  264. ProcessState_CurvedUI curveUI = currentProcessElement.GetComponent<ProcessState_CurvedUI>();
  265. if (curveUI != null)
  266. {
  267. curveUI.active = state;
  268. curveUI.EnterState(true);
  269. }
  270. }
  271. /// <summary>
  272. /// 分数结算
  273. /// </summary>
  274. private float SettlementScore()
  275. {
  276. score = 0;
  277. foreach (var item in examProcessElements)
  278. {
  279. if (item.finish == true && item.result == true)
  280. {
  281. score += item.scores;
  282. }
  283. }
  284. return score;
  285. }
  286. /// <summary>
  287. /// 统计考试时长
  288. /// </summary>
  289. private void CountExamDuration()
  290. {
  291. // 记录结束时的时间
  292. DateTime finishTime = DateTime.Now;
  293. m_RecordExamDuration = (float)(finishTime - examProxy.startTime).TotalMilliseconds;
  294. }
  295. private void OnDisable()
  296. {
  297. ProcessManagement.Instance.processElementActiveEvent -= ProcessElementActive;
  298. ProcessManagement.Instance.processElementActiveEvent -= ProcessElementDisActive;
  299. ProcessManagement.Instance.processFinishEvent -= ExamFinish;
  300. }
  301. private void OnDestroy()
  302. {
  303. if (!mResultUpLoad)
  304. {
  305. UpLoadScore();
  306. }
  307. }
  308. }
  309. [Serializable]
  310. public class ExamProcessElement
  311. {
  312. [Sirenix.OdinInspector.ReadOnly]
  313. public int id;
  314. [Sirenix.OdinInspector.ReadOnly]
  315. public string elementDescript;
  316. [Sirenix.OdinInspector.ReadOnly]
  317. public bool finish = false;
  318. [Sirenix.OdinInspector.ReadOnly]
  319. public bool result;
  320. [GUIColor(0, 1, 0, 1)]
  321. public float scores;
  322. /// <summary>
  323. /// 错误原因
  324. /// </summary>
  325. public string errorReason;
  326. /// <summary>
  327. /// 错误次数
  328. /// </summary>
  329. public int faultCount;
  330. /// <summary>
  331. /// 错误截图
  332. /// </summary>
  333. public List<string> screenshotList = new List<string>();
  334. /// <summary>
  335. /// 操作时间
  336. /// </summary>
  337. public DateTime operationTime;
  338. /// <summary>
  339. /// 步骤名称
  340. /// </summary>
  341. public string stepName;
  342. /// <summary>
  343. /// 正在上传的任务
  344. /// </summary>
  345. public List<string> m_UpLoading = new List<string>();
  346. }
  347. }