OperateSetting.cs 9.8 KB

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