OperateSetting.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. using ChivaXR;
  2. using QFramework;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using Sirenix.OdinInspector;
  7. using System.ComponentModel;
  8. using I2.Loc;
  9. using System.Globalization;
  10. public enum OperationMode
  11. {
  12. /// <summary>
  13. /// 学习模式
  14. /// </summary>
  15. [LabelText("学习模式")]
  16. Learn,
  17. /// <summary>
  18. /// 练习模式
  19. /// </summary>
  20. [LabelText("练习模式")]
  21. Practice,
  22. /// <summary>
  23. /// 考试模式
  24. /// </summary>
  25. [LabelText("考核模式")]
  26. Exam,
  27. /// <summary>
  28. /// 闯关模式
  29. /// </summary>
  30. [LabelText("闯关模式")]
  31. Challenge,
  32. /// <summary>
  33. /// 自由练习
  34. /// </summary>
  35. [LabelText("自由练习模式")]
  36. FreeParctice,
  37. /// <summary>
  38. /// 自由考核
  39. /// </summary>
  40. [LabelText("自由考核模式")]
  41. FreeExam,
  42. [LabelText("默认空模式")]
  43. None
  44. }
  45. public class OperateSetting : MonoSingleton<OperateSetting>
  46. {
  47. [LabelText("需要加载的检修配置表格名称")]
  48. public string m_CourseName;
  49. [LabelText("是否打开标题界面")]
  50. public bool m_ActiveTitlePanel = true;
  51. /// <summary>
  52. /// 设置操作模式
  53. /// </summary>
  54. [LabelText("设置操作模式")]
  55. public OperationMode m_CurrentOperationMode = OperationMode.Practice;
  56. [LabelText("考试时间")]
  57. public int examTime = 20;
  58. [LabelText("最大容错次数")]
  59. public int maxErrorCount = 30;
  60. public ToolPackUILogic ToolPackUILogic;
  61. /// <summary>
  62. /// 工具包中的工具
  63. /// </summary>
  64. [HideInInspector]
  65. public List<ToolConfig> m_ToolKitToolConfigs;
  66. /// <summary>
  67. /// 当前步骤正确的工具名称
  68. /// </summary>
  69. public List<string> m_CurrentStepRightToolNames;
  70. private PC_OperatePanel m_OperatePanel;
  71. /// <summary>
  72. /// 是否开启题库
  73. /// </summary>
  74. [HideInInspector]
  75. public bool isOpenQuestion=true;
  76. /// <summary>
  77. /// 是否开启检查模式
  78. /// </summary>
  79. [HideInInspector]
  80. public bool isOpenCheck = false;
  81. private List<QuestionInfo> m_QuestionList=new List<QuestionInfo>();
  82. #region 本地化语言
  83. public bool useLocalization = false;
  84. public string en_courseName;
  85. /// <summary>
  86. /// 课程数据多语言初始化
  87. /// </summary>
  88. public void InitCourseLocalization()
  89. {
  90. StepListProxy m_StepListProxy = DAL.Instance.Get<StepListProxy>();
  91. List<OperationStepDataInfo> tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(m_CourseName);
  92. List<string[]> courseLocalization = new List<string[]>();
  93. courseLocalization.Add(new string[] { "Key", "Type", "Desc", "Chinese", "English [en-US]" });
  94. for (int i = 0; i < tmpStepListInfos.Count; i++)
  95. {
  96. List<string> tempLocalizationTerm = new List<string>();
  97. //parentStep;
  98. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "parentStepName");
  99. tempLocalizationTerm.Add("Text");
  100. tempLocalizationTerm.Add("");
  101. tempLocalizationTerm.Add(tmpStepListInfos[i].parentStepName);
  102. tempLocalizationTerm.Add(tmpStepListInfos[i].en_parentStepName);
  103. courseLocalization.Add(tempLocalizationTerm.ToArray());
  104. //StepName
  105. tempLocalizationTerm.Clear();
  106. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepName");
  107. tempLocalizationTerm.Add("Text");
  108. tempLocalizationTerm.Add("");
  109. tempLocalizationTerm.Add(tmpStepListInfos[i].stepName);
  110. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepName);
  111. courseLocalization.Add(tempLocalizationTerm.ToArray());
  112. //stepDescr
  113. tempLocalizationTerm.Clear();
  114. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepDescr");
  115. tempLocalizationTerm.Add("Text");
  116. tempLocalizationTerm.Add("");
  117. tempLocalizationTerm.Add(tmpStepListInfos[i].stepDescr);
  118. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepDescr);
  119. courseLocalization.Add(tempLocalizationTerm.ToArray());
  120. //stepMattersNeedingAttention
  121. tempLocalizationTerm.Clear();
  122. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepMattersNeedingAttention");
  123. tempLocalizationTerm.Add("Text");
  124. tempLocalizationTerm.Add("");
  125. tempLocalizationTerm.Add(tmpStepListInfos[i].stepMattersNeedingAttention);
  126. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepMattersNeedingAttention);
  127. courseLocalization.Add(tempLocalizationTerm.ToArray());
  128. }
  129. LanguageSource languageSource = this.gameObject.AddComponent<LanguageSource>();
  130. languageSource.SourceData.Import_CSV(string.Empty, courseLocalization, eSpreadsheetUpdateMode.Replace);
  131. TermData data = languageSource.SourceData.AddTerm(ScriptTerms.operatepanel.coursetitle);
  132. data.Languages[0] = m_CourseName;
  133. data.Languages[1] = en_courseName;
  134. LocalizationManager.LocalizeAll();
  135. }
  136. /// <summary>
  137. /// 获取相机配置数据
  138. /// </summary>
  139. /// <returns></returns>
  140. private SettingInfo GetSettingInfo()
  141. {
  142. // 拼接文件基本路径
  143. string filePath = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath,
  144. "Json",
  145. "SettingInfo.json");
  146. string fileData = FileHelper.GetAllDataInfo(filePath);
  147. SettingInfo config = JsonUtility.FromJson<SettingInfo>(fileData);
  148. return config == null ? null : config;
  149. }
  150. #endregion
  151. private void Awake()
  152. {
  153. ResKit.Init();
  154. if (GlobalData.m_CurrentOperationMode != OperationMode.None)
  155. {
  156. m_CurrentOperationMode = GlobalData.m_CurrentOperationMode;
  157. }
  158. #region 本地化语言
  159. if (useLocalization)
  160. {
  161. LocalizationConfig.localization = true;
  162. InitCourseLocalization();
  163. }
  164. InitGameSetting();
  165. #endregion
  166. if (!string.IsNullOrEmpty(m_CourseName))
  167. {
  168. LoadCourse(m_CourseName);
  169. }
  170. InitQuestionInfo();
  171. InitOperationMode();
  172. ProcessManagement.Instance.awakePlay = false;
  173. }
  174. /// <summary>
  175. /// 初始化游戏设置
  176. /// </summary>
  177. private void InitGameSetting()
  178. {
  179. SettingInfo settingInfo = GetSettingInfo();
  180. if (LocalizationManager.HasLanguage(settingInfo.language))
  181. {
  182. LocalizationManager.CurrentLanguage = settingInfo.language;
  183. }
  184. RoamCameraController.Instance.TranslateSpeed = settingInfo.keySpeedValue * 20;
  185. RoamCameraController.Instance.MouseScrollMoveSpeed = settingInfo.mouseSpeedValue * 2;
  186. }
  187. /// <summary>
  188. /// 初始化题库
  189. /// </summary>
  190. private void InitQuestionInfo()
  191. {
  192. m_QuestionList = DAL.Instance.Get<QuestionProxy>().ReadStepMsgInfoFromTable(OperateSetting.Instance.m_CourseName + "_题库");
  193. }
  194. public QuestionInfo GetQuestionInfo(int stepID)
  195. {
  196. QuestionInfo tmpQuestionInfo = m_QuestionList.Find(t => t.StepId == stepID.ToString());
  197. return tmpQuestionInfo;
  198. }
  199. private void Start()
  200. {
  201. if (CameraRayCastManager.Instance != null) Debug.Log("<color=green>检测已开启</color>");
  202. }
  203. //启动流程
  204. public void StartProcess()
  205. {
  206. //加载考试时长及错误
  207. if (m_CurrentOperationMode == OperationMode.Exam|| m_CurrentOperationMode == OperationMode.FreeExam)
  208. {
  209. ExamManagerForPC tmpExamManagerForPC = this.gameObject.AddComponent<ExamManagerForPC>();
  210. tmpExamManagerForPC.examTime = this.examTime;
  211. tmpExamManagerForPC.m_maxErrorCount = maxErrorCount;
  212. UIKit.GetPanel<PC_OperatePanel>().StartExam(examTime);
  213. UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ErrorCount.text = "x" + maxErrorCount.ToString();
  214. }
  215. else
  216. {
  217. UIKit.GetPanel<PC_OperatePanel>().StartGame();
  218. }
  219. InitOperationMode();
  220. if (m_CurrentOperationMode == OperationMode.FreeParctice || m_CurrentOperationMode == OperationMode.FreeExam)
  221. {
  222. FreeProcessManagement.Instance.ActiveProcess();
  223. //关闭自动执行步骤
  224. ProcessManagement.Instance.autoEnterNextProcess = false;
  225. }
  226. else
  227. {
  228. ProcessManagement.Instance.ActiveCurrentProcess();
  229. }
  230. }
  231. public void InitOperationMode()
  232. {
  233. if (m_CurrentOperationMode != OperationMode.FreeParctice&&m_CurrentOperationMode!=OperationMode.FreeExam)
  234. {
  235. foreach (var item in ProcessManagement.Instance.processes)
  236. {
  237. item.preprocess = item.GetOrAddComponent<Preprocess_VoiceAndCamera>();
  238. }
  239. }
  240. switch (m_CurrentOperationMode)
  241. {
  242. case OperationMode.Learn:
  243. Preprocess_VoiceAndCamera.playView = true;
  244. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = true;
  245. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = true;
  246. Preprocess_VoiceAndCamera.ViewMoveTime = 2;
  247. break;
  248. case OperationMode.Practice:
  249. Preprocess_VoiceAndCamera.playView = false;
  250. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  251. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  252. break;
  253. case OperationMode.Exam:
  254. Preprocess_VoiceAndCamera.playView = false;
  255. Preprocess_VoiceAndCamera.playAudio = false;
  256. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  257. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  258. break;
  259. case OperationMode.FreeParctice:
  260. case OperationMode.FreeExam:
  261. Preprocess_VoiceAndCamera.playView = false;
  262. Preprocess_VoiceAndCamera.playAudio = false;
  263. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  264. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  265. FreeProcessManagement.Instance.InitFreeProcess(m_CourseName);
  266. break;
  267. case OperationMode.Challenge:
  268. break;
  269. default:
  270. break;
  271. }
  272. }
  273. public void LoadCourse(string name)
  274. {
  275. if (m_CurrentOperationMode == OperationMode.Exam)
  276. {
  277. ExamSetProxy tmpProxy = DAL.Instance.Get<ExamSetProxy>();
  278. ExamSetInfo tmpExamInfo = tmpProxy.GetExamSetInfoByCourseName(name);
  279. if (tmpExamInfo != null)
  280. {
  281. maxErrorCount = int.Parse(tmpExamInfo.maxErrorCount);
  282. examTime = int.Parse(tmpExamInfo.examTime);
  283. }
  284. else
  285. {
  286. Debug.LogError("未加载到考试配置信息,加载默认配置");
  287. }
  288. }
  289. UIKit.OpenPanel<ToolDisplayForm>();
  290. UIKit.OpenPanel<LogSystemForm>(UILevel.PopUI);
  291. m_OperatePanel = UIKit.OpenPanel<PC_OperatePanel>(
  292. new PC_OperatePanelData
  293. {
  294. courseName = m_CourseName,
  295. OpenTitleBg = m_ActiveTitlePanel
  296. });
  297. if (ProcessManagement.Instance)
  298. {
  299. ProcessManagement.Instance.EnterProcessEvent += m_OperatePanel.OnEnterProcessByStepID;
  300. ProcessManagement.Instance.processElementDisActiveEvent += m_OperatePanel.OnPrcessElementDisActive;
  301. ProcessManagement.Instance.processFinishEvent += ProcessEndPanel;
  302. }
  303. UIKit.OpenPanel<ArrowTipsPanel>();
  304. }
  305. /// <summary>
  306. /// 完成所有流程后打开练习结束界面/成绩单界面
  307. /// </summary>
  308. public void ProcessEndPanel()
  309. {
  310. switch (m_CurrentOperationMode)
  311. {
  312. case OperationMode.Practice:
  313. m_OperatePanel.PracticeEnd();
  314. break;
  315. case OperationMode.Exam:
  316. //ExamManagerForPC.instance.ExamFinish();
  317. //operatePanel.ExamEnd();
  318. break;
  319. }
  320. }
  321. private void OnDisable()
  322. {
  323. if (ProcessManagement.Instance)
  324. {
  325. ProcessManagement.Instance.EnterProcessEvent -= m_OperatePanel.OnEnterProcessByStepID;
  326. ProcessManagement.Instance.processElementDisActiveEvent -= m_OperatePanel.OnPrcessElementDisActive;
  327. ProcessManagement.Instance.processFinishEvent -= ProcessEndPanel;
  328. }
  329. }
  330. }