OperateSetting.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. LoadCourse(m_CourseName);
  168. InitQuestionInfo();
  169. InitOperationMode();
  170. ProcessManagement.Instance.awakePlay = false;
  171. }
  172. /// <summary>
  173. /// 初始化游戏设置
  174. /// </summary>
  175. private void InitGameSetting()
  176. {
  177. SettingInfo settingInfo = GetSettingInfo();
  178. if (LocalizationManager.HasLanguage(settingInfo.language))
  179. {
  180. LocalizationManager.CurrentLanguage = settingInfo.language;
  181. }
  182. RoamCameraController.Instance.TranslateSpeed = settingInfo.keySpeedValue * 20;
  183. RoamCameraController.Instance.MouseScrollMoveSpeed = settingInfo.mouseSpeedValue * 2;
  184. }
  185. /// <summary>
  186. /// 初始化题库
  187. /// </summary>
  188. private void InitQuestionInfo()
  189. {
  190. m_QuestionList = DAL.Instance.Get<QuestionProxy>().ReadStepMsgInfoFromTable(OperateSetting.Instance.m_CourseName + "_题库");
  191. }
  192. public QuestionInfo GetQuestionInfo(int stepID)
  193. {
  194. QuestionInfo tmpQuestionInfo = m_QuestionList.Find(t => t.StepId == stepID.ToString());
  195. return tmpQuestionInfo;
  196. }
  197. private void Start()
  198. {
  199. if (CameraRayCastManager.Instance != null) Debug.Log("<color=green>检测已开启</color>");
  200. }
  201. //启动流程
  202. public void StartProcess()
  203. {
  204. //加载考试时长及错误
  205. if (m_CurrentOperationMode == OperationMode.Exam|| m_CurrentOperationMode == OperationMode.FreeExam)
  206. {
  207. ExamManagerForPC tmpExamManagerForPC = this.gameObject.AddComponent<ExamManagerForPC>();
  208. tmpExamManagerForPC.examTime = this.examTime;
  209. tmpExamManagerForPC.m_maxErrorCount = maxErrorCount;
  210. UIKit.GetPanel<PC_OperatePanel>().StartExam(examTime);
  211. UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ErrorCount.text = "x" + maxErrorCount.ToString();
  212. }
  213. else
  214. {
  215. UIKit.GetPanel<PC_OperatePanel>().StartGame();
  216. }
  217. InitOperationMode();
  218. if (m_CurrentOperationMode == OperationMode.FreeParctice || m_CurrentOperationMode == OperationMode.FreeExam)
  219. {
  220. FreeProcessManagement.Instance.ActiveProcess();
  221. //关闭自动执行步骤
  222. ProcessManagement.Instance.autoEnterNextProcess = false;
  223. }
  224. else
  225. {
  226. ProcessManagement.Instance.ActiveCurrentProcess();
  227. }
  228. }
  229. public void InitOperationMode()
  230. {
  231. if (m_CurrentOperationMode != OperationMode.FreeParctice&&m_CurrentOperationMode!=OperationMode.FreeExam)
  232. {
  233. foreach (var item in ProcessManagement.Instance.processes)
  234. {
  235. item.preprocess = item.GetOrAddComponent<Preprocess_VoiceAndCamera>();
  236. }
  237. }
  238. switch (m_CurrentOperationMode)
  239. {
  240. case OperationMode.Learn:
  241. Preprocess_VoiceAndCamera.playView = true;
  242. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = true;
  243. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = true;
  244. Preprocess_VoiceAndCamera.ViewMoveTime = 2;
  245. break;
  246. case OperationMode.Practice:
  247. Preprocess_VoiceAndCamera.playView = false;
  248. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  249. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  250. break;
  251. case OperationMode.Exam:
  252. Preprocess_VoiceAndCamera.playView = false;
  253. Preprocess_VoiceAndCamera.playAudio = false;
  254. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  255. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  256. break;
  257. case OperationMode.FreeParctice:
  258. case OperationMode.FreeExam:
  259. Preprocess_VoiceAndCamera.playView = false;
  260. Preprocess_VoiceAndCamera.playAudio = false;
  261. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  262. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  263. FreeProcessManagement.Instance.InitFreeProcess(m_CourseName);
  264. break;
  265. case OperationMode.Challenge:
  266. break;
  267. default:
  268. break;
  269. }
  270. }
  271. public void LoadCourse(string name)
  272. {
  273. UIKit.OpenPanel<ToolDisplayForm>();
  274. UIKit.OpenPanel<LogSystemForm>();
  275. m_OperatePanel = UIKit.OpenPanel<PC_OperatePanel>(
  276. new PC_OperatePanelData
  277. {
  278. courseName = m_CourseName,
  279. OpenTitleBg = m_ActiveTitlePanel
  280. });
  281. if (ProcessManagement.Instance)
  282. {
  283. ProcessManagement.Instance.EnterProcessEvent += m_OperatePanel.OnEnterProcessByStepID;
  284. ProcessManagement.Instance.processElementDisActiveEvent += m_OperatePanel.OnPrcessElementDisActive;
  285. ProcessManagement.Instance.processFinishEvent += ProcessEndPanel;
  286. }
  287. UIKit.OpenPanel<ArrowTipsPanel>();
  288. }
  289. /// <summary>
  290. /// 完成所有流程后打开练习结束界面/成绩单界面
  291. /// </summary>
  292. public void ProcessEndPanel()
  293. {
  294. switch (m_CurrentOperationMode)
  295. {
  296. case OperationMode.Practice:
  297. m_OperatePanel.PracticeEnd();
  298. break;
  299. case OperationMode.Exam:
  300. //ExamManagerForPC.instance.ExamFinish();
  301. //operatePanel.ExamEnd();
  302. break;
  303. }
  304. }
  305. private void OnDisable()
  306. {
  307. if (ProcessManagement.Instance)
  308. {
  309. ProcessManagement.Instance.EnterProcessEvent -= m_OperatePanel.OnEnterProcessByStepID;
  310. ProcessManagement.Instance.processElementDisActiveEvent -= m_OperatePanel.OnPrcessElementDisActive;
  311. ProcessManagement.Instance.processFinishEvent -= ProcessEndPanel;
  312. }
  313. }
  314. }