OperateSetting.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. [LabelText("默认空模式")]
  33. None
  34. }
  35. public class OperateSetting : MonoSingleton<OperateSetting>
  36. {
  37. [LabelText("需要加载的检修配置表格名称")]
  38. public string m_CourseName;
  39. [LabelText("是否打开标题界面")]
  40. public bool m_ActiveTitlePanel = true;
  41. /// <summary>
  42. /// 设置操作模式
  43. /// </summary>
  44. [LabelText("设置操作模式")]
  45. public OperationMode m_CurrentOperationMode = OperationMode.Practice;
  46. [LabelText("考试时间")]
  47. public int examTime = 20;
  48. [LabelText("最大容错次数")]
  49. public int maxErrorCount = 30;
  50. public ToolPackUILogic ToolPackUILogic;
  51. /// <summary>
  52. /// 工具包中的工具
  53. /// </summary>
  54. [HideInInspector]
  55. public List<ToolConfig> m_ToolKitToolConfigs;
  56. /// <summary>
  57. /// 当前步骤正确的工具名称
  58. /// </summary>
  59. public List<string> m_CurrentStepRightToolNames;
  60. private PC_OperatePanel m_OperatePanel;
  61. #region 本地化语言
  62. public bool useLocalization = false;
  63. public string en_courseName;
  64. /// <summary>
  65. /// 课程数据多语言初始化
  66. /// </summary>
  67. public void InitCourseLocalization()
  68. {
  69. StepListProxy m_StepListProxy = DAL.Instance.Get<StepListProxy>();
  70. List<OperationStepDataInfo> tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(m_CourseName);
  71. List<string[]> courseLocalization = new List<string[]>();
  72. courseLocalization.Add(new string[] { "Key", "Type", "Desc", "Chinese", "English [en-US]" });
  73. for (int i = 0; i < tmpStepListInfos.Count; i++)
  74. {
  75. List<string> tempLocalizationTerm = new List<string>();
  76. //parentStep;
  77. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "parentStepName");
  78. tempLocalizationTerm.Add("Text");
  79. tempLocalizationTerm.Add("");
  80. tempLocalizationTerm.Add(tmpStepListInfos[i].parentStepName);
  81. tempLocalizationTerm.Add(tmpStepListInfos[i].en_parentStepName);
  82. courseLocalization.Add(tempLocalizationTerm.ToArray());
  83. //StepName
  84. tempLocalizationTerm.Clear();
  85. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepName");
  86. tempLocalizationTerm.Add("Text");
  87. tempLocalizationTerm.Add("");
  88. tempLocalizationTerm.Add(tmpStepListInfos[i].stepName);
  89. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepName);
  90. courseLocalization.Add(tempLocalizationTerm.ToArray());
  91. //stepDescr
  92. tempLocalizationTerm.Clear();
  93. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepDescr");
  94. tempLocalizationTerm.Add("Text");
  95. tempLocalizationTerm.Add("");
  96. tempLocalizationTerm.Add(tmpStepListInfos[i].stepDescr);
  97. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepDescr);
  98. courseLocalization.Add(tempLocalizationTerm.ToArray());
  99. //stepMattersNeedingAttention
  100. tempLocalizationTerm.Clear();
  101. tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepMattersNeedingAttention");
  102. tempLocalizationTerm.Add("Text");
  103. tempLocalizationTerm.Add("");
  104. tempLocalizationTerm.Add(tmpStepListInfos[i].stepMattersNeedingAttention);
  105. tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepMattersNeedingAttention);
  106. courseLocalization.Add(tempLocalizationTerm.ToArray());
  107. }
  108. LanguageSource languageSource = this.gameObject.AddComponent<LanguageSource>();
  109. languageSource.SourceData.Import_CSV(string.Empty, courseLocalization, eSpreadsheetUpdateMode.Replace);
  110. TermData data = languageSource.SourceData.AddTerm(ScriptTerms.operatepanel.coursetitle);
  111. data.Languages[0] = m_CourseName;
  112. data.Languages[1] = en_courseName;
  113. LocalizationManager.LocalizeAll();
  114. }
  115. /// <summary>
  116. /// 获取相机配置数据
  117. /// </summary>
  118. /// <returns></returns>
  119. private SettingInfo GetSettingInfo()
  120. {
  121. // 拼接文件基本路径
  122. string filePath = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath,
  123. "Json",
  124. "SettingInfo.json");
  125. string fileData = FileHelper.GetAllDataInfo(filePath);
  126. SettingInfo config = JsonUtility.FromJson<SettingInfo>(fileData);
  127. return config == null ? null : config;
  128. }
  129. #endregion
  130. private void Awake()
  131. {
  132. ResKit.Init();
  133. if (GlobalData.m_CurrentOperationMode != OperationMode.None)
  134. {
  135. m_CurrentOperationMode = GlobalData.m_CurrentOperationMode;
  136. }
  137. #region 本地化语言
  138. if (useLocalization)
  139. {
  140. LocalizationConfig.localization = true;
  141. InitCourseLocalization();
  142. }
  143. InitGameSetting();
  144. #endregion
  145. if (!string.IsNullOrEmpty(m_CourseName))
  146. LoadCourse(m_CourseName);
  147. InitOperationMode();
  148. ProcessManagement.Instance.awakePlay = false;
  149. }
  150. /// <summary>
  151. /// 初始化游戏设置
  152. /// </summary>
  153. private void InitGameSetting()
  154. {
  155. SettingInfo settingInfo = GetSettingInfo();
  156. if (LocalizationManager.HasLanguage(settingInfo.language))
  157. {
  158. LocalizationManager.CurrentLanguage = settingInfo.language;
  159. }
  160. RoamCameraController.Instance.TranslateSpeed = settingInfo.keySpeedValue * 20;
  161. RoamCameraController.Instance.MouseScrollMoveSpeed = settingInfo.mouseSpeedValue * 2;
  162. }
  163. private void Start()
  164. {
  165. if (CameraRayCastManager.Instance != null) Debug.Log("<color=green>检测已开启</color>");
  166. }
  167. //启动流程
  168. public void StartProcess()
  169. {
  170. //加载考试时长及错误
  171. if (m_CurrentOperationMode == OperationMode.Exam)
  172. {
  173. ExamManagerForPC tmpExamManagerForPC = this.gameObject.AddComponent<ExamManagerForPC>();
  174. tmpExamManagerForPC.examTime = this.examTime;
  175. tmpExamManagerForPC.m_maxErrorCount = maxErrorCount;
  176. UIKit.GetPanel<PC_OperatePanel>().StartExam(examTime);
  177. UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ErrorCount.text = "x" + maxErrorCount.ToString();
  178. }
  179. else
  180. {
  181. UIKit.GetPanel<PC_OperatePanel>().StartGame();
  182. }
  183. InitOperationMode();
  184. ProcessManagement.Instance.ActiveCurrentProcess();
  185. }
  186. public void InitOperationMode()
  187. {
  188. foreach (var item in ProcessManagement.Instance.processes)
  189. {
  190. item.preprocess = item.GetOrAddComponent<Preprocess_VoiceAndCamera>();
  191. }
  192. switch (m_CurrentOperationMode)
  193. {
  194. case OperationMode.Learn:
  195. Preprocess_VoiceAndCamera.playView = true;
  196. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = true;
  197. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = true;
  198. Preprocess_VoiceAndCamera.ViewMoveTime = 2;
  199. break;
  200. case OperationMode.Practice:
  201. Preprocess_VoiceAndCamera.playView = false;
  202. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  203. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  204. break;
  205. case OperationMode.Exam:
  206. Preprocess_VoiceAndCamera.playView = false;
  207. Preprocess_VoiceAndCamera.playAudio = false;
  208. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  209. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  210. break;
  211. case OperationMode.Challenge:
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. public void LoadCourse(string name)
  218. {
  219. UIKit.OpenPanel<ToolDisplayForm>();
  220. UIKit.OpenPanel<LogSystemForm>();
  221. m_OperatePanel = UIKit.OpenPanel<PC_OperatePanel>(
  222. new PC_OperatePanelData
  223. {
  224. courseName = m_CourseName,
  225. OpenTitleBg = m_ActiveTitlePanel
  226. });
  227. if (ProcessManagement.Instance)
  228. {
  229. ProcessManagement.Instance.EnterProcessEvent += m_OperatePanel.OnEnterProcessByStepID;
  230. ProcessManagement.Instance.processElementDisActiveEvent += m_OperatePanel.OnPrcessElementDisActive;
  231. ProcessManagement.Instance.processFinishEvent += ProcessEndPanel;
  232. }
  233. UIKit.OpenPanel<ArrowTipsPanel>();
  234. }
  235. /// <summary>
  236. /// 完成所有流程后打开练习结束界面/成绩单界面
  237. /// </summary>
  238. public void ProcessEndPanel()
  239. {
  240. switch (m_CurrentOperationMode)
  241. {
  242. case OperationMode.Practice:
  243. m_OperatePanel.PracticeEnd();
  244. break;
  245. case OperationMode.Exam:
  246. //ExamManagerForPC.instance.ExamFinish();
  247. //operatePanel.ExamEnd();
  248. break;
  249. }
  250. }
  251. private void OnDisable()
  252. {
  253. if (ProcessManagement.Instance)
  254. {
  255. ProcessManagement.Instance.EnterProcessEvent -= m_OperatePanel.OnEnterProcessByStepID;
  256. ProcessManagement.Instance.processElementDisActiveEvent -= m_OperatePanel.OnPrcessElementDisActive;
  257. ProcessManagement.Instance.processFinishEvent -= ProcessEndPanel;
  258. }
  259. }
  260. }