OperateSetting.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. private List<QuestionInfo> m_QuestionList=new List<QuestionInfo>();
  77. #region 本地化语言
  78. public bool useLocalization = false;
  79. public string en_courseName;
  80. /// <summary>
  81. /// 课程数据多语言初始化
  82. /// </summary>
  83. public void InitCourseLocalization()
  84. {
  85. StepListProxy m_StepListProxy = DAL.Instance.Get<StepListProxy>();
  86. List<OperationStepDataInfo> tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(m_CourseName);
  87. List<string[]> courseLocalization = new List<string[]>();
  88. courseLocalization.Add(new string[] { "Key", "Type", "Desc", "Chinese", "English [en-US]" });
  89. for (int i = 0; i < tmpStepListInfos.Count; i++)
  90. {
  91. List<string> tempLocalizationTerm = new List<string>();
  92. //parentStep;
  93. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "parentStepName");
  94. tempLocalizationTerm.Add("Text");
  95. tempLocalizationTerm.Add("");
  96. tempLocalizationTerm.Add(tmpStepListInfos[i].parentStepName);
  97. tempLocalizationTerm.Add(tmpStepListInfos[i].en_parentStepName);
  98. courseLocalization.Add(tempLocalizationTerm.ToArray());
  99. //StepName
  100. tempLocalizationTerm.Clear();
  101. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepName");
  102. tempLocalizationTerm.Add("Text");
  103. tempLocalizationTerm.Add("");
  104. tempLocalizationTerm.Add(tmpStepListInfos[i].stepName);
  105. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepName);
  106. courseLocalization.Add(tempLocalizationTerm.ToArray());
  107. //stepDescr
  108. tempLocalizationTerm.Clear();
  109. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepDescr");
  110. tempLocalizationTerm.Add("Text");
  111. tempLocalizationTerm.Add("");
  112. tempLocalizationTerm.Add(tmpStepListInfos[i].stepDescr);
  113. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepDescr);
  114. courseLocalization.Add(tempLocalizationTerm.ToArray());
  115. //stepMattersNeedingAttention
  116. tempLocalizationTerm.Clear();
  117. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepMattersNeedingAttention");
  118. tempLocalizationTerm.Add("Text");
  119. tempLocalizationTerm.Add("");
  120. tempLocalizationTerm.Add(tmpStepListInfos[i].stepMattersNeedingAttention);
  121. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepMattersNeedingAttention);
  122. courseLocalization.Add(tempLocalizationTerm.ToArray());
  123. }
  124. LanguageSource languageSource = this.gameObject.AddComponent<LanguageSource>();
  125. languageSource.SourceData.Import_CSV(string.Empty, courseLocalization, eSpreadsheetUpdateMode.Replace);
  126. TermData data = languageSource.SourceData.AddTerm(ScriptTerms.operatepanel.coursetitle);
  127. data.Languages[0] = m_CourseName;
  128. data.Languages[1] = en_courseName;
  129. LocalizationManager.LocalizeAll();
  130. }
  131. /// <summary>
  132. /// 获取相机配置数据
  133. /// </summary>
  134. /// <returns></returns>
  135. private SettingInfo GetSettingInfo()
  136. {
  137. // 拼接文件基本路径
  138. string filePath = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath,
  139. "Json",
  140. "SettingInfo.json");
  141. string fileData = FileHelper.GetAllDataInfo(filePath);
  142. SettingInfo config = JsonUtility.FromJson<SettingInfo>(fileData);
  143. return config == null ? null : config;
  144. }
  145. #endregion
  146. private void Awake()
  147. {
  148. ResKit.Init();
  149. if (GlobalData.m_CurrentOperationMode != OperationMode.None)
  150. {
  151. m_CurrentOperationMode = GlobalData.m_CurrentOperationMode;
  152. }
  153. #region 本地化语言
  154. if (useLocalization)
  155. {
  156. LocalizationConfig.localization = true;
  157. InitCourseLocalization();
  158. }
  159. InitGameSetting();
  160. #endregion
  161. if (!string.IsNullOrEmpty(m_CourseName))
  162. LoadCourse(m_CourseName);
  163. InitQuestionInfo();
  164. InitOperationMode();
  165. ProcessManagement.Instance.awakePlay = false;
  166. }
  167. /// <summary>
  168. /// 初始化游戏设置
  169. /// </summary>
  170. private void InitGameSetting()
  171. {
  172. SettingInfo settingInfo = GetSettingInfo();
  173. if (LocalizationManager.HasLanguage(settingInfo.language))
  174. {
  175. LocalizationManager.CurrentLanguage = settingInfo.language;
  176. }
  177. RoamCameraController.Instance.TranslateSpeed = settingInfo.keySpeedValue * 20;
  178. RoamCameraController.Instance.MouseScrollMoveSpeed = settingInfo.mouseSpeedValue * 2;
  179. }
  180. /// <summary>
  181. /// 初始化题库
  182. /// </summary>
  183. private void InitQuestionInfo()
  184. {
  185. m_QuestionList = DAL.Instance.Get<QuestionProxy>().ReadStepMsgInfoFromTable(OperateSetting.Instance.m_CourseName + "_题库");
  186. }
  187. public QuestionInfo GetQuestionInfo(int stepID)
  188. {
  189. QuestionInfo tmpQuestionInfo = m_QuestionList.Find(t => t.StepId == ProcessManagement.Instance.currentStepID.ToString());
  190. return tmpQuestionInfo;
  191. }
  192. private void Start()
  193. {
  194. if (CameraRayCastManager.Instance != null) Debug.Log("<color=green>检测已开启</color>");
  195. }
  196. //启动流程
  197. public void StartProcess()
  198. {
  199. //加载考试时长及错误
  200. if (m_CurrentOperationMode == OperationMode.Exam)
  201. {
  202. ExamManagerForPC tmpExamManagerForPC = this.gameObject.AddComponent<ExamManagerForPC>();
  203. tmpExamManagerForPC.examTime = this.examTime;
  204. tmpExamManagerForPC.m_maxErrorCount = maxErrorCount;
  205. UIKit.GetPanel<PC_OperatePanel>().StartExam(examTime);
  206. UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ErrorCount.text = "x" + maxErrorCount.ToString();
  207. }
  208. else
  209. {
  210. UIKit.GetPanel<PC_OperatePanel>().StartGame();
  211. }
  212. InitOperationMode();
  213. if (m_CurrentOperationMode == OperationMode.FreeParctice || m_CurrentOperationMode == OperationMode.FreeExam)
  214. {
  215. FreeProcessManagement.Instance.ActiveProcess();
  216. //关闭自动执行步骤
  217. ProcessManagement.Instance.autoEnterNextProcess = false;
  218. }
  219. else
  220. {
  221. ProcessManagement.Instance.ActiveCurrentProcess();
  222. }
  223. }
  224. public void InitOperationMode()
  225. {
  226. if (m_CurrentOperationMode != OperationMode.FreeParctice)
  227. {
  228. foreach (var item in ProcessManagement.Instance.processes)
  229. {
  230. item.preprocess = item.GetOrAddComponent<Preprocess_VoiceAndCamera>();
  231. }
  232. }
  233. switch (m_CurrentOperationMode)
  234. {
  235. case OperationMode.Learn:
  236. Preprocess_VoiceAndCamera.playView = true;
  237. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = true;
  238. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = true;
  239. Preprocess_VoiceAndCamera.ViewMoveTime = 2;
  240. break;
  241. case OperationMode.Practice:
  242. Preprocess_VoiceAndCamera.playView = false;
  243. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  244. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  245. break;
  246. case OperationMode.Exam:
  247. Preprocess_VoiceAndCamera.playView = false;
  248. Preprocess_VoiceAndCamera.playAudio = false;
  249. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  250. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  251. break;
  252. case OperationMode.FreeParctice:
  253. case OperationMode.FreeExam:
  254. Preprocess_VoiceAndCamera.playView = false;
  255. Preprocess_VoiceAndCamera.playAudio = false;
  256. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  257. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  258. FreeProcessManagement.Instance.InitFreeProcess(m_CourseName);
  259. break;
  260. case OperationMode.Challenge:
  261. break;
  262. default:
  263. break;
  264. }
  265. }
  266. public void LoadCourse(string name)
  267. {
  268. UIKit.OpenPanel<ToolDisplayForm>();
  269. UIKit.OpenPanel<LogSystemForm>();
  270. m_OperatePanel = UIKit.OpenPanel<PC_OperatePanel>(
  271. new PC_OperatePanelData
  272. {
  273. courseName = m_CourseName,
  274. OpenTitleBg = m_ActiveTitlePanel
  275. });
  276. if (ProcessManagement.Instance)
  277. {
  278. ProcessManagement.Instance.EnterProcessEvent += m_OperatePanel.OnEnterProcessByStepID;
  279. ProcessManagement.Instance.processElementDisActiveEvent += m_OperatePanel.OnPrcessElementDisActive;
  280. ProcessManagement.Instance.processFinishEvent += ProcessEndPanel;
  281. }
  282. UIKit.OpenPanel<ArrowTipsPanel>();
  283. }
  284. /// <summary>
  285. /// 完成所有流程后打开练习结束界面/成绩单界面
  286. /// </summary>
  287. public void ProcessEndPanel()
  288. {
  289. switch (m_CurrentOperationMode)
  290. {
  291. case OperationMode.Practice:
  292. m_OperatePanel.PracticeEnd();
  293. break;
  294. case OperationMode.Exam:
  295. //ExamManagerForPC.instance.ExamFinish();
  296. //operatePanel.ExamEnd();
  297. break;
  298. }
  299. }
  300. private void OnDisable()
  301. {
  302. if (ProcessManagement.Instance)
  303. {
  304. ProcessManagement.Instance.EnterProcessEvent -= m_OperatePanel.OnEnterProcessByStepID;
  305. ProcessManagement.Instance.processElementDisActiveEvent -= m_OperatePanel.OnPrcessElementDisActive;
  306. ProcessManagement.Instance.processFinishEvent -= ProcessEndPanel;
  307. }
  308. }
  309. }