123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- namespace ChivaXR.Op
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- using VRTK;
- using ChivaXR.VR;
- using ProcedureBYQ;
- using QFramework;
- [RequireComponent(typeof(ExamHandleManager))]
- public class ExamManagerForVR : MonoBehaviour
- {
- public static ExamManagerForVR instance;
- public ExamProxy examProxy;
- #region 场景配置模块
- [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
- [Button("1.获取流程信息")]
- public void GetEaxmProcessElements()
- {
- List<ProcessElement> processElements = ProcessManagement.Instance.processes;
- //临时转存,用户数据恢复
- List<ExamProcessElement> tmpExamProcessElements = examProcessElements;
- //重建考试信息列表
- examProcessElements = new List<ExamProcessElement>();
- foreach (var item in processElements)
- {
- ExamProcessElement examProcessElement = tmpExamProcessElements.Find(t => t.elementDescript == item.processBase.GetPBDescribe());
- if (examProcessElement != null)
- {
- examProcessElements.Add(examProcessElement);
- }
- else
- {
- StepListProxy tmpProxy = DAL.Instance.Get<StepListProxy>();
- OperationStepDataInfo tmpInfo = tmpProxy.GetOpStepDataInfoById(item.stepID);
- examProcessElements.Add(new ExamProcessElement()
- {
- id = item.stepID,
- elementDescript = item.processBase.GetPBDescribe(),
- stepName = tmpInfo.stepName
- });
- }
- }
- }
- [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
- [Button("2.将所有的CurvedUI和箭头置为禁用(不影响编辑器跳步)")]
- public void GetCurvedUIAndDiasable()
- {
- //将环形UI置为禁用状态
- List<ProcessElement> processElements = ProcessManagement.Instance.processes;
- foreach (var item in processElements)
- {
- ProcessState_CurvedUI curvedUI = item.gameObject.GetComponent<ProcessState_CurvedUI>();
- if (curvedUI != null)
- {
- curvedUI.active = false;
- }
- }
- //将箭头提示置为禁用状态
- JianTouManager.Instance.SetJianTouActive(false);
- }
- [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
- [Button("3、初始化流程分数")]
- public void SetEaxmProcessScore()
- {
- if (examProcessElements.Count <= 0)
- {
- return;
- }
- foreach (var item in examProcessElements)
- {
- if (examProcessElements.Count <= 100)
- {
- item.scores = 1;
- }
- else
- {
- //item.scores = 100 / examProcessElements.Count;
- item.scores = 0.5f;
- }
- }
- RefreshScore();
- }
- #endregion
- #region 配分模块
- [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
- /// <summary>
- /// 考试信息
- /// </summary>
- [TableList(MaxScrollViewHeight = 20)]
- public List<ExamProcessElement> examProcessElements;
- private ProcessElement currentProcessElement;
- #endregion
- #region 成绩展示模块
- [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
- [LabelText("配置总分"), GUIColor(0, 1, 1, 1)]
- [Sirenix.OdinInspector.ReadOnly]
- public float totalScore;
- [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
- [Button("刷新总设定分数")]
- public void RefreshScore()
- {
- totalScore = 0;
- foreach (var item in examProcessElements)
- {
- totalScore += item.scores;
- }
- }
- [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
- [LabelText("最终得分"), GUIColor(1, 0.92f, 0.016f, 1)]
- [Sirenix.OdinInspector.ReadOnly]
- public float score;
- [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
- [LabelText("成绩展示时相机位置"), GUIColor(1, 0.92f, 0.016f, 1)]
- public Vector3 CameraPosition = new Vector3(-0.5461204f, -0.5791085f, 0.8489573f);
- [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
- [LabelText("成绩展示时相机角度"), GUIColor(1, 0.92f, 0.016f, 1)]
- public Quaternion CameraRotation = new Quaternion(0, 180, 0, 0);
- [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
- [LabelText("成绩展示时禁用相机移动"), GUIColor(1, 0.92f, 0.016f, 1)]
- public bool DisableCamerMove = false;
- private bool mResultUpLoad = false;
- [BoxGroup("成绩展示模块", CenterLabel = true, Order = 3)]
- [Button("打开成绩面板(运行时生效)")]
- public void ExamFinish()
- {
- SetCamerRigPositionAndRotation();
- ShowExamResultPanel();
- SetCamerRigDisable();
- UpLoadScore();
- CountExamDuration();
- }
- public void UpLoadScore()
- {
- examProxy.UpLoadExamResult(SettlementScore());
- mResultUpLoad = true;
- }
- /// <summary>
- /// 展示考试信息
- /// </summary>
- /// <returns></returns>
- private ExamResultPanel ShowExamResultPanel()
- {
- ExamResultPanel tmpExamPanel = null;
- if (Application.isPlaying)
- {
- tmpExamPanel = FindObjectOfType<ExamResultPanel>();
- if (tmpExamPanel == null)
- {
- var resLoader = ResLoader.Allocate();
- GameObject tmpPrefab = resLoader.LoadSync<GameObject>("ExamResultCanvas");
- if (tmpPrefab == null)
- {
- Debug.LogError("UI/ExamResultCanvas没有加载到!!!!");
- }
- else
- {
- GameObject tmpObj = Instantiate<GameObject>(tmpPrefab, null);
- tmpObj.SetActive(true);
- tmpExamPanel = tmpObj.GetComponentInChildren<ExamResultPanel>();
- }
- }
- }
- if (tmpExamPanel != null) tmpExamPanel.ShowScoreList(examProcessElements, SettlementScore(), m_RecordExamDuration);
- return tmpExamPanel;
- }
- /// <summary>
- /// 设置相机位置
- /// </summary>
- private void SetCamerRigPositionAndRotation()
- {
- if (Application.isPlaying)
- {
- GameObject camerRig = GameObject.Find("[CameraRig]");
- if (camerRig != null)
- {
- camerRig.transform.position = CameraPosition;
- camerRig.transform.rotation = CameraRotation;
- }
- }
- }
- /// <summary>
- /// 设置是否禁用相机移动
- /// </summary>
- private void SetCamerRigDisable()
- {
- if (Application.isPlaying)
- {
- PlayMoveWayController playMoveWayController = FindObjectOfType<PlayMoveWayController>();
- if (playMoveWayController != null)
- {
- playMoveWayController.enabled = !DisableCamerMove;
- }
- }
- }
- #endregion
- /// <summary>
- /// 记录考试时长
- /// </summary>
- private float m_RecordExamDuration;
-
- private void Awake()
- {
- instance = this;
- ProcessManagement.Instance.processElementActiveEvent += ProcessElementActive;
- ProcessManagement.Instance.processElementDisActiveEvent += ProcessElementDisActive;
- ProcessManagement.Instance.processFinishEvent += ExamFinish;
- examProxy = DAL.Instance.Get<ExamProxy>();
- examProxy.StartExam();
- }
- /// <summary>
- /// 步骤进入
- /// </summary>
- /// <param name="element"></param>
- private void ProcessElementActive(ProcessElement element)
- {
- currentProcessElement = element;
- }
- /// <summary>
- /// 步骤退出
- /// </summary>
- /// <param name="element"></param>
- private void ProcessElementDisActive(ProcessElement element)
- {
- JianTouManager.instance.SetJianTouActive(false);
- ExamProcessElement tmpElement = examProcessElements.Find(t => t.elementDescript == currentProcessElement.processBase.GetPBDescribe());
- if (tmpElement.finish == false)
- {
- tmpElement.finish = true;
- tmpElement.result = true;
- }
- SettlementScore();
- }
- public CVR_HintItem hintItem;
- /// <summary>
- /// 打开提示
- /// </summary>
- public void OpenPrompt()
- {
- SetCuredUIState(true);
- JianTouManager.instance.SetJianTouActive(true);
- hintItem.OpenHighlighter(OutLineType.hint);
- SetCurrentExamElementResult();
- }
- /// <summary>
- /// 设置正在考的步骤的状态
- /// </summary>
- private void SetCurrentExamElementResult()
- {
- ExamProcessElement examElent = examProcessElements.Find(t => t.elementDescript == currentProcessElement.processBase.GetPBDescribe());
- if (examElent != null)
- {
- examElent.finish = true;
- examElent.result = false;
- }
- }
- /// <summary>
- /// 设置环形UI状态
- /// </summary>
- /// <param name="state"></param>
- private void SetCuredUIState(bool state)
- {
- ProcessState_CurvedUI curveUI = currentProcessElement.GetComponent<ProcessState_CurvedUI>();
- if (curveUI != null)
- {
- curveUI.active = state;
- curveUI.EnterState(true);
- }
- }
- /// <summary>
- /// 分数结算
- /// </summary>
- private float SettlementScore()
- {
- score = 0;
- foreach (var item in examProcessElements)
- {
- if (item.finish == true && item.result == true)
- {
- score += item.scores;
- }
- }
- return score;
- }
- /// <summary>
- /// 统计考试时长
- /// </summary>
- private void CountExamDuration()
- {
- // 记录结束时的时间
- DateTime finishTime = DateTime.Now;
- m_RecordExamDuration = (float)(finishTime - examProxy.startTime).TotalMilliseconds;
- }
-
- private void OnDisable()
- {
- ProcessManagement.Instance.processElementActiveEvent -= ProcessElementActive;
- ProcessManagement.Instance.processElementActiveEvent -= ProcessElementDisActive;
- ProcessManagement.Instance.processFinishEvent -= ExamFinish;
- }
- private void OnDestroy()
- {
- if (!mResultUpLoad)
- {
- UpLoadScore();
- }
- }
- }
- [Serializable]
- public class ExamProcessElement
- {
- [Sirenix.OdinInspector.ReadOnly]
- public int id;
- [Sirenix.OdinInspector.ReadOnly]
- public string elementDescript;
- [Sirenix.OdinInspector.ReadOnly]
- public bool finish = false;
- [Sirenix.OdinInspector.ReadOnly]
- public bool result;
- [GUIColor(0, 1, 0, 1)]
- public float scores;
- /// <summary>
- /// 错误原因
- /// </summary>
- public string errorReason;
- /// <summary>
- /// 错误次数
- /// </summary>
- public int faultCount;
- /// <summary>
- /// 错误截图
- /// </summary>
- public List<string> screenshotList = new List<string>();
- /// <summary>
- /// 操作时间
- /// </summary>
- public DateTime operationTime;
- /// <summary>
- /// 步骤名称
- /// </summary>
- public string stepName;
- /// <summary>
- /// 正在上传的任务
- /// </summary>
- public List<string> m_UpLoading = new List<string>();
- }
- }
|