OperateSetting.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. ParseParameters();
  159. #region 本地化语言
  160. if (useLocalization)
  161. {
  162. LocalizationConfig.localization = true;
  163. InitCourseLocalization();
  164. }
  165. InitGameSetting();
  166. #endregion
  167. if (!string.IsNullOrEmpty(m_CourseName))
  168. {
  169. LoadCourse(m_CourseName);
  170. }
  171. InitQuestionInfo();
  172. InitOperationMode();
  173. ProcessManagement.Instance.awakePlay = false;
  174. }
  175. private void ParseParameters()
  176. {
  177. string[] args = System.Environment.GetCommandLineArgs();
  178. ///临时测试数据
  179. string para = "b0e6098c7b65e46928b38e09a506234abb0b9a0/闭式水泵整体拆装/访客/40008013900/127.0.0.1:15157/Exam/测试参数/这是第条参数/这是总平台参数";
  180. string[] tmpArgs = para.Split('/');
  181. // 文件各种:手机号/课程名/模式/地址
  182. string tmpPhoneNumber = "";
  183. string tmpCourseName = "";
  184. string tmpMode = "";
  185. UserProxy userProxy = DAL.Instance.Get<UserProxy>();
  186. userProxy.userInfo.userName = tmpArgs[2];
  187. userProxy.userInfo.phoneNumber = tmpArgs[3];
  188. Debug.Log(tmpArgs.Length + "-asd-" + args[1]);
  189. if (tmpArgs.Length < 4)
  190. {
  191. #region 电专平台接口解析
  192. // 文件各种:手机号/课程名/模式/地址
  193. tmpPhoneNumber = tmpArgs[0];
  194. tmpCourseName = tmpArgs[1];
  195. tmpMode = tmpArgs[2];
  196. //if (tmpArgs.Length > 3)
  197. //{
  198. // string tmpAddress = tmpArgs[3];
  199. // //GrpcChannelContronller.Instance.StartClient(tmpAddress);
  200. // GetInfoaboutSpecifiedUser(tmpPhoneNumber);
  201. //}
  202. #endregion
  203. }
  204. else
  205. {
  206. #region 通用平台接口解析
  207. tmpPhoneNumber = tmpArgs[5];
  208. tmpCourseName = tmpArgs[1];
  209. tmpMode = tmpArgs[2];
  210. GrpcChannelContronller.Instance.StartClient(tmpArgs[4]);
  211. tmpCourseName = tmpArgs[1];
  212. GlobalConfig.m_SelectDevice = tmpCourseName;
  213. switch (tmpArgs[5])
  214. {
  215. case "Learn":
  216. m_CurrentOperationMode = OperationMode.Learn;
  217. break;
  218. case "Practice":
  219. m_CurrentOperationMode = OperationMode.Practice;
  220. break;
  221. case "Exam":
  222. m_CurrentOperationMode = OperationMode.Exam;
  223. break;
  224. default:
  225. tmpMode = "学习";
  226. break;
  227. }
  228. Debug.Log(tmpCourseName + " --" + tmpMode);
  229. #endregion
  230. }
  231. }
  232. /// <summary>
  233. /// 初始化游戏设置
  234. /// </summary>
  235. private void InitGameSetting()
  236. {
  237. SettingInfo settingInfo = GetSettingInfo();
  238. if (LocalizationManager.HasLanguage(settingInfo.language))
  239. {
  240. LocalizationManager.CurrentLanguage = settingInfo.language;
  241. }
  242. RoamCameraController.Instance.TranslateSpeed = settingInfo.keySpeedValue * 20;
  243. RoamCameraController.Instance.MouseScrollMoveSpeed = settingInfo.mouseSpeedValue * 2;
  244. }
  245. /// <summary>
  246. /// 初始化题库
  247. /// </summary>
  248. private void InitQuestionInfo()
  249. {
  250. m_QuestionList = DAL.Instance.Get<QuestionProxy>().ReadStepMsgInfoFromTable(OperateSetting.Instance.m_CourseName + "_题库");
  251. }
  252. public QuestionInfo GetQuestionInfo(int stepID)
  253. {
  254. QuestionInfo tmpQuestionInfo = m_QuestionList.Find(t => t.StepId == stepID.ToString());
  255. return tmpQuestionInfo;
  256. }
  257. private void Start()
  258. {
  259. if (CameraRayCastManager.Instance != null) Debug.Log("<color=green>检测已开启</color>");
  260. }
  261. //启动流程
  262. public void StartProcess()
  263. {
  264. //加载考试时长及错误
  265. if (m_CurrentOperationMode == OperationMode.Exam|| m_CurrentOperationMode == OperationMode.FreeExam)
  266. {
  267. ExamManagerForPC tmpExamManagerForPC = this.gameObject.AddComponent<ExamManagerForPC>();
  268. tmpExamManagerForPC.examTime = this.examTime;
  269. tmpExamManagerForPC.m_maxErrorCount = maxErrorCount;
  270. UIKit.GetPanel<PC_OperatePanel>().StartExam(examTime);
  271. UIKit.GetPanel<PC_OperatePanel>().ExamInfo.ErrorCount.text = "x" + maxErrorCount.ToString();
  272. }
  273. else
  274. {
  275. UIKit.GetPanel<PC_OperatePanel>().StartGame();
  276. }
  277. InitOperationMode();
  278. if (m_CurrentOperationMode == OperationMode.FreeParctice || m_CurrentOperationMode == OperationMode.FreeExam)
  279. {
  280. FreeProcessManagement.Instance.ActiveProcess();
  281. //关闭自动执行步骤
  282. ProcessManagement.Instance.autoEnterNextProcess = false;
  283. }
  284. else
  285. {
  286. ProcessManagement.Instance.ActiveCurrentProcess();
  287. }
  288. }
  289. public void InitOperationMode()
  290. {
  291. if (m_CurrentOperationMode != OperationMode.FreeParctice&&m_CurrentOperationMode!=OperationMode.FreeExam)
  292. {
  293. foreach (var item in ProcessManagement.Instance.processes)
  294. {
  295. item.preprocess = item.GetOrAddComponent<Preprocess_VoiceAndCamera>();
  296. }
  297. }
  298. switch (m_CurrentOperationMode)
  299. {
  300. case OperationMode.Learn:
  301. Preprocess_VoiceAndCamera.playView = true;
  302. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = true;
  303. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = true;
  304. Preprocess_VoiceAndCamera.ViewMoveTime = 2;
  305. break;
  306. case OperationMode.Practice:
  307. Preprocess_VoiceAndCamera.playView = false;
  308. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  309. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  310. break;
  311. case OperationMode.Exam:
  312. Preprocess_VoiceAndCamera.playView = false;
  313. Preprocess_VoiceAndCamera.playAudio = false;
  314. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  315. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  316. break;
  317. case OperationMode.FreeParctice:
  318. case OperationMode.FreeExam:
  319. Preprocess_VoiceAndCamera.playView = false;
  320. Preprocess_VoiceAndCamera.playAudio = false;
  321. Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false;
  322. Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false;
  323. FreeProcessManagement.Instance.InitFreeProcess(m_CourseName);
  324. break;
  325. case OperationMode.Challenge:
  326. break;
  327. default:
  328. break;
  329. }
  330. }
  331. public void LoadCourse(string name)
  332. {
  333. if (m_CurrentOperationMode == OperationMode.Exam)
  334. {
  335. ExamSetProxy tmpProxy = DAL.Instance.Get<ExamSetProxy>();
  336. ExamSetInfo tmpExamInfo = tmpProxy.GetExamSetInfoByCourseName(name);
  337. if (tmpExamInfo != null)
  338. {
  339. maxErrorCount = int.Parse(tmpExamInfo.maxErrorCount);
  340. examTime = int.Parse(tmpExamInfo.examTime);
  341. }
  342. }
  343. UIKit.OpenPanel<ToolDisplayForm>();
  344. UIKit.OpenPanel<LogSystemForm>();
  345. m_OperatePanel = UIKit.OpenPanel<PC_OperatePanel>(
  346. new PC_OperatePanelData
  347. {
  348. courseName = m_CourseName,
  349. OpenTitleBg = m_ActiveTitlePanel
  350. });
  351. if (ProcessManagement.Instance)
  352. {
  353. ProcessManagement.Instance.EnterProcessEvent += m_OperatePanel.OnEnterProcessByStepID;
  354. ProcessManagement.Instance.processElementDisActiveEvent += m_OperatePanel.OnPrcessElementDisActive;
  355. ProcessManagement.Instance.processFinishEvent += ProcessEndPanel;
  356. }
  357. UIKit.OpenPanel<ArrowTipsPanel>();
  358. }
  359. /// <summary>
  360. /// 完成所有流程后打开练习结束界面/成绩单界面
  361. /// </summary>
  362. public void ProcessEndPanel()
  363. {
  364. switch (m_CurrentOperationMode)
  365. {
  366. case OperationMode.Practice:
  367. m_OperatePanel.PracticeEnd();
  368. break;
  369. case OperationMode.Exam:
  370. //ExamManagerForPC.instance.ExamFinish();
  371. //operatePanel.ExamEnd();
  372. break;
  373. }
  374. }
  375. private void OnDisable()
  376. {
  377. if (ProcessManagement.Instance)
  378. {
  379. ProcessManagement.Instance.EnterProcessEvent -= m_OperatePanel.OnEnterProcessByStepID;
  380. ProcessManagement.Instance.processElementDisActiveEvent -= m_OperatePanel.OnPrcessElementDisActive;
  381. ProcessManagement.Instance.processFinishEvent -= ProcessEndPanel;
  382. }
  383. }
  384. }