123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- using ChivaXR;
- using ChivaXR.Op;
- using I2.Loc;
- using QFramework;
- using Sirenix.OdinInspector;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- public enum ErrorReason
- {
- SelectWrongTool,
- SelectWrongTarget
- }
- public class ExamManagerForPC : MonoBehaviour
- {
- public static ExamManagerForPC instance;
- /// <summary>
- /// 考试代理
- /// </summary>
- public ExamProxy m_ExamProxy;
- /// <summary>
- /// 记录考试时长
- /// </summary>
- private int m_RecordExamDuration;
- /// <summary>
- /// 开始时间
- /// </summary>
- private DateTime m_StartTime;
- /// <summary>
- /// 结束时间
- /// </summary>
- private DateTime m_EndTime;
- /// <summary>
- /// 允许错误次数
- /// </summary>
- public int m_maxErrorCount;
- private ProcessElement currentProcessElement;
- #region 场景配置模块
- [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
- [Button("1.获取流程信息")]
- public void GetEaxmProcessElements()
- {
- List<ProcessElement> processElements = ProcessManagement.Instance.processes;
- if (m_examProcessElements == null)
- {
- m_examProcessElements = new List<ExamProcessElement>();
- }
- ////临时转存,用户数据恢复
- List<ExamProcessElement> tmpExamProcessElements = m_examProcessElements;
- //重建考试信息列表
- m_examProcessElements = new List<ExamProcessElement>();
- foreach (var item in processElements)
- {
- ExamProcessElement examProcessElement = tmpExamProcessElements.Find(t => t.elementDescript == item.processBase.GetPBDescribe());
- if (examProcessElement != null)
- {
- m_examProcessElements.Add(examProcessElement);
- }
- else
- {
- StepListProxy tmpProxy = DAL.Instance.Get<StepListProxy>();
- OperationStepDataInfo tmpInfo = tmpProxy.GetOpStepDataInfoById(item.stepID);
- m_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;
- //将箭头提示置为禁用状态
- JianTouManager.Instance.SetJianTouActive(false);
- }
- [BoxGroup("场景配置模块", CenterLabel = true, Order = 0), GUIColor(0, 1, 0, 0.6f)]
- [Button("3、初始化流程分数")]
- public void SetEaxmProcessScore()
- {
- if (m_examProcessElements.Count <= 0)
- {
- return;
- }
- foreach (var item in m_examProcessElements)
- {
- if (m_examProcessElements.Count <= 100)
- {
- item.scores = 1;
- }
- else
- {
- //item.scores = 100 / examProcessElements.Count;
- item.scores = 0.5f;
- }
- }
- RefreshScore();
- }
- #endregion
- [Space(5)]
- #region 配分模块
- [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
- /// <summary>
- /// 考试信息
- /// </summary>
- [TableList(MaxScrollViewHeight = 20)]
- public List<ExamProcessElement> m_examProcessElements;
- [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
- [LabelText("配置总分"), GUIColor(0, 1, 1, 1)]
- [Sirenix.OdinInspector.ReadOnly]
- public float examSetTotalScore;
- [BoxGroup("配分模块", CenterLabel = true, Order = 1)]
- [Button("刷新总设定分数")]
- public void RefreshScore()
- {
- examSetTotalScore = 0;
- foreach (var item in m_examProcessElements)
- {
- examSetTotalScore += item.scores;
- }
- }
- #endregion
- [Space(5)]
- #region 成绩模块
- [BoxGroup("成绩模块", CenterLabel = true, Order = 3)]
- [LabelText("最终得分"), GUIColor(1, 0.92f, 0.016f, 1)]
- [Sirenix.OdinInspector.ReadOnly]
- public float score;
- [Space(5)]
- [BoxGroup("考试时长", CenterLabel = true, Order = 4)]
- [LabelText("考试时长(分钟)"), GUIColor(1, 0.1f, 0.016f, 1)]
- public int examTime;
- #endregion
- /// <summary>
- /// 是否上传结果
- /// </summary>
- private bool m_ResultUpload = false;
- /// <summary>
- /// 服务器下发的分数
- /// </summary>
- private float m_DistributeScores;
- private void Awake()
- {
- instance = this;
- GetEaxmProcessElements();
- GetCurvedUIAndDiasable();
- //如果没有读到考试数据自动非分/手动配分
- AutoEaxmProcessScore();
- Init();
- }
- public void Init()
- {
- ProcessManagement.Instance.processElementActiveEvent += ProcessElementActive;
- ProcessManagement.Instance.processElementDisActiveEvent += ProcessElementDisActive;
- ProcessManagement.Instance.processFinishEvent += ExamFinish;
- m_ExamProxy = DAL.Instance.Get<ExamProxy>();
- m_ExamProxy.StartExam();
- m_StartTime = DateTime.Now;
- }
- /// <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 = m_examProcessElements.Find(t => t.elementDescript == currentProcessElement.processBase.GetPBDescribe());
- if (tmpElement.finish == false)
- {
- tmpElement.finish = true;
- tmpElement.result = tmpElement.faultCount > 0 ? false : true;
- tmpElement.operationTime = DateTime.Now;
- }
- SetelementScore();
- }
- /// <summary>
- /// 自动配分
- /// </summary>
- public void AutoEaxmProcessScore()
- {
- if (m_examProcessElements.Count <= 0)
- {
- return;
- }
- int score = 200 / m_examProcessElements.Count;
- int count = 200 % m_examProcessElements.Count;
- for (int i = 0; i < m_examProcessElements.Count; i++)
- {
- if (count > i) m_examProcessElements[i].scores = ((float)score + 1) / 2;
- else m_examProcessElements[i].scores = (float)score / 2;
- }
- RefreshScore();
- }
- public float GetDistributeScores(StepInfoManager stepInfoManager)
- {
- float tmpScore = 0;
- for (int i = 0; i < m_examProcessElements.Count; i++)
- {
- m_examProcessElements[i].scores = stepInfoManager.S[i];
- }
- foreach (var item in stepInfoManager.S)
- {
- tmpScore += item;
- }
- RefreshScore();
- return tmpScore;
- }
- /// <summary>
- /// 根据接收到的数据进行分数填充
- /// </summary>
- public void ExamProcessScoreByReceiveData(StepInfoManager stepInfoManager)
- {
- for (int i = 0; i < m_examProcessElements.Count; i++)
- {
- m_examProcessElements[i].scores = float.Parse(stepInfoManager.S[i].ToString());
- }
- }
- /// <summary>
- /// 记录操作错误
- /// </summary>
- public void RecordFault(int processId, ErrorReason errorReason)
- {
- ExamProcessElement tmpElement = m_examProcessElements.Find(t => t.id == processId);
- if (tmpElement != null)
- {
- tmpElement.errorReason = errorReason.ToString();
- tmpElement.faultCount++;
- m_maxErrorCount--;
- UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ErrorCount.text = "x" + m_maxErrorCount.ToString();
- if (m_maxErrorCount <= 0)
- {
- ExamFinish();
- }
- string screenShotName = DateTime.UtcNow.Ticks.ToString();
- Debug.Log(screenShotName);
- StartCoroutine(ScrrenCapture(new Rect(0, 0, Screen.width, Screen.height), 0, screenShotName, tmpElement));
- }
- LocalizedString stepName = processId + "stepName";
- string wrongErrson = "操作错误";
- switch (errorReason)
- {
- case ErrorReason.SelectWrongTool:
- if (LocalizationManager.CurrentLanguage == "Chinese")
- {
- wrongErrson = "工器具错误";
- }
- else
- {
- wrongErrson = "ToolError";
- }
- break;
- case ErrorReason.SelectWrongTarget:
- if (LocalizationManager.CurrentLanguage == "Chinese")
- {
- wrongErrson = "操作点错误";
- }
- else
- {
- wrongErrson = "OperationError";
- }
- break;
- }
- UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ShowWrongInfo("<color=#FF9F00>" + stepName + "</color> : " + wrongErrson);
- }
- /// <summary>
- /// 分数结算
- /// </summary>
- private float SetelementScore()
- {
- score = 0;
- foreach (var item in m_examProcessElements)
- {
- if (item.finish == true && item.result == true)
- {
- score += item.scores;
- }
- }
- //StopAllCoroutines();
- return score;
- }
- /// <summary>
- /// 上传考核结果
- /// </summary>
- public void UploadExamResult()
- {
- ExamProxy examProxy = DAL.Instance.Get<ExamProxy>();
- examProxy.UpLoadExamResult(SetelementScore());
- m_ResultUpload = true;
- }
- /// <summary>
- /// 成绩展示
- /// </summary>
- public void ExamFinish()
- {
- m_EndTime = DateTime.Now;
- CountExamDuration();
- if (UIKit.GetPanel<PC_OperatePanel>())
- {
- UIKit.GetPanel<PC_OperatePanel>().ExamEnd(m_examProcessElements, SetelementScore(), m_RecordExamDuration);
- }
- ProcessManagement.Instance.StopCurrentProcess();
- if (!m_ResultUpload)
- {
- UploadExamResult();
- }
- if (UIKit.GetPanel<ArrowTipsPanel>())
- {
- UIKit.GetPanel<ArrowTipsPanel>().Clear();
- }
- }
- /// <summary>
- /// 统计考试时长
- /// </summary>
- private void CountExamDuration()
- {
- // 记录结束时的时间
- DateTime finishTime = DateTime.Now;
- m_RecordExamDuration = (int)(finishTime - m_ExamProxy.startTime).TotalSeconds;
- }
- private void OnDisable()
- {
- ProcessManagement.Instance.processElementActiveEvent -= ProcessElementActive;
- ProcessManagement.Instance.processElementActiveEvent -= ProcessElementDisActive;
- ProcessManagement.Instance.processFinishEvent -= ExamFinish;
- }
- Texture2D screenShot;//保存截取的纹理
- IEnumerator ScrrenCapture(Rect rect, int a, string screenShotName, ExamProcessElement examProcessElement)
- {
- Debug.Log("截图:" + screenShotName);
- screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
- yield return new WaitForSeconds(0.5f);
- yield return new WaitForEndOfFrame();
- screenShot.ReadPixels(rect, 0, 0);
- screenShot.Apply();
- //推送
- //PushHelper.InitBasicData();
- //StartCoroutine(PushHelper.SendFileStreamPushRequest(screenShot, screenShotName, (result, msg, flag, cmnAttachId) =>
- //{
- // if (!result)
- // {
- // Debug.LogError(msg);
- // }
- // else
- // {
- // Debug.Log("考试模块图片上传成功" + cmnAttachId.data.cmnAttachId);
- // examProcessElement.screenshotList.Add(cmnAttachId.data.cmnAttachId);
- // }
- // examProcessElement.m_UpLoading.Remove(screenShotName);
- //}));
- examProcessElement.m_UpLoading.Add(screenShotName);
- }
- /// <summary>
- /// 获取该ID的分数
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public float GetScoreById(int id)
- {
- float tmpScore = 0;
- //PullProxy tmpPullProxy = DAL.Instance.Get<PullProxy>();
- //StepInfoManager tmpStepInfoManager = tmpPullProxy.GetExamStepInfoManager();
- //if (tmpStepInfoManager == null)
- //{
- // tmpScore = m_examProcessElements[id - 1].scores;
- //}
- //else
- //{
- // tmpScore = tmpStepInfoManager.S[id - 1];
- //}
- return tmpScore;
- }
- /// <summary>
- /// 获取总分比值
- /// </summary>
- public float GetTotalScore()
- {
- float tmpTotalScore = 0;
- foreach (var item in m_examProcessElements)
- {
- if (item.finish && item.result)
- {
- tmpTotalScore += item.scores;
- }
- }
- if (m_DistributeScores == 0)
- {
- return tmpTotalScore / examSetTotalScore;
- }
- else
- {
- float ratio = (float)tmpTotalScore / (float)examSetTotalScore;
- return ratio;
- }
- }
- /// <summary>
- /// 是否上传完成
- /// </summary>
- /// <returns></returns>
- public bool IsFinishUpLoad()
- {
- foreach (var item in m_examProcessElements)
- {
- if (item.m_UpLoading.Count > 0)
- {
- return false;
- }
- }
- return true;
- }
- }
|