OperateSetting.cs 12 KB

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