using ChivaXR; using QFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using System.ComponentModel; using I2.Loc; using System.Globalization; public enum OperationMode { /// /// 学习模式 /// [LabelText("学习模式")] Learn, /// /// 练习模式 /// [LabelText("练习模式")] Practice, /// /// 考试模式 /// [LabelText("考核模式")] Exam, /// /// 闯关模式 /// [LabelText("闯关模式")] Challenge, [LabelText("默认空模式")] None } public class OperateSetting : MonoSingleton { [LabelText("需要加载的检修配置表格名称")] public string m_CourseName; [LabelText("是否打开标题界面")] public bool m_ActiveTitlePanel = true; /// /// 设置操作模式 /// [LabelText("设置操作模式")] public OperationMode m_CurrentOperationMode = OperationMode.Practice; [LabelText("考试时间")] public int examTime = 20; [LabelText("最大容错次数")] public int maxErrorCount = 30; public ToolPackUILogic ToolPackUILogic; [HideInInspector] public List m_ToolLibraryToolConfigs; /// /// 当前步骤正确的工具名称 /// public List m_CurrentStepRightToolNames; private PC_OperatePanel m_OperatePanel; #region 本地化语言 public bool useLocalization = false; public string en_courseName; /// /// 课程数据多语言初始化 /// public void InitCourseLocalization() { StepListProxy m_StepListProxy = DAL.Instance.Get(); List tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(m_CourseName); List courseLocalization = new List(); courseLocalization.Add(new string[] { "Key", "Type", "Desc", "Chinese", "English [en-US]" }); for (int i = 0; i < tmpStepListInfos.Count; i++) { List tempLocalizationTerm = new List(); //parentStep; tempLocalizationTerm.Add(tmpStepListInfos[i].id + "parentStepName"); tempLocalizationTerm.Add("Text"); tempLocalizationTerm.Add(""); tempLocalizationTerm.Add(tmpStepListInfos[i].parentStepName); tempLocalizationTerm.Add(tmpStepListInfos[i].en_parentStepName); courseLocalization.Add(tempLocalizationTerm.ToArray()); //StepName tempLocalizationTerm.Clear(); tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepName"); tempLocalizationTerm.Add("Text"); tempLocalizationTerm.Add(""); tempLocalizationTerm.Add(tmpStepListInfos[i].stepName); tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepName); courseLocalization.Add(tempLocalizationTerm.ToArray()); //stepDescr tempLocalizationTerm.Clear(); tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepDescr"); tempLocalizationTerm.Add("Text"); tempLocalizationTerm.Add(""); tempLocalizationTerm.Add(tmpStepListInfos[i].stepDescr); tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepDescr); courseLocalization.Add(tempLocalizationTerm.ToArray()); //stepMattersNeedingAttention tempLocalizationTerm.Clear(); tempLocalizationTerm.Add(tmpStepListInfos[i].id + "stepMattersNeedingAttention"); tempLocalizationTerm.Add("Text"); tempLocalizationTerm.Add(""); tempLocalizationTerm.Add(tmpStepListInfos[i].stepMattersNeedingAttention); tempLocalizationTerm.Add(tmpStepListInfos[i].en_stepMattersNeedingAttention); courseLocalization.Add(tempLocalizationTerm.ToArray()); } LanguageSource languageSource = this.gameObject.AddComponent(); languageSource.SourceData.Import_CSV(string.Empty, courseLocalization, eSpreadsheetUpdateMode.Replace); TermData data = languageSource.SourceData.AddTerm(ScriptTerms.operatepanel.coursetitle); data.Languages[0] = m_CourseName; data.Languages[1] = en_courseName; LocalizationManager.LocalizeAll(); } /// /// 获取相机配置数据 /// /// private SettingInfo GetSettingInfo() { // 拼接文件基本路径 string filePath = PathHelper.CombineFilePath(PathHelper.m_ReadOnlyPath, "Json", "SettingInfo.json"); string fileData = FileHelper.GetAllDataInfo(filePath); SettingInfo config = JsonUtility.FromJson(fileData); return config == null ? null : config; } #endregion private void Awake() { ResKit.Init(); if (GlobalData.m_CurrentOperationMode != OperationMode.None) { m_CurrentOperationMode = GlobalData.m_CurrentOperationMode; } #region 本地化语言 if (useLocalization) { LocalizationConfig.localization = true; InitCourseLocalization(); } InitGameSetting(); #endregion if (!string.IsNullOrEmpty(m_CourseName)) LoadCourse(m_CourseName); InitOperationMode(); ProcessManagement.Instance.awakePlay = false; } /// /// 初始化游戏设置 /// private void InitGameSetting() { SettingInfo settingInfo = GetSettingInfo(); if (LocalizationManager.HasLanguage(settingInfo.language)) { LocalizationManager.CurrentLanguage = settingInfo.language; } RoamCameraController.Instance.TranslateSpeed = settingInfo.keySpeedValue * 20; RoamCameraController.Instance.MouseScrollMoveSpeed = settingInfo.mouseSpeedValue * 2; } private void Start() { if (CameraRayCastManager.Instance != null) Debug.Log("检测已开启"); } //启动流程 public void StartProcess() { //加载考试时长及错误 if (m_CurrentOperationMode == OperationMode.Exam) { ExamManagerForPC tmpExamManagerForPC = this.gameObject.AddComponent(); tmpExamManagerForPC.examTime = this.examTime; tmpExamManagerForPC.m_maxErrorCount = maxErrorCount; UIKit.GetPanel().StartExam(examTime); UIKit.GetPanel().ExamInfo.ErrorCount.text = "x" + maxErrorCount.ToString(); } else { UIKit.GetPanel().StartGame(); } InitOperationMode(); ProcessManagement.Instance.ActiveCurrentProcess(); } public void InitOperationMode() { foreach (var item in ProcessManagement.Instance.processes) { item.preprocess = item.GetOrAddComponent(); } switch (m_CurrentOperationMode) { case OperationMode.Learn: Preprocess_VoiceAndCamera.playView = true; Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = true; Preprocess_VoiceAndCamera.WaitViewFinishedToExit = true; Preprocess_VoiceAndCamera.ViewMoveTime = 2; break; case OperationMode.Practice: Preprocess_VoiceAndCamera.playView = false; Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false; Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false; break; case OperationMode.Exam: Preprocess_VoiceAndCamera.playView = false; Preprocess_VoiceAndCamera.playAudio = false; Preprocess_VoiceAndCamera.WaitAudioFinishedToExit = false; Preprocess_VoiceAndCamera.WaitViewFinishedToExit = false; break; case OperationMode.Challenge: break; default: break; } } public void LoadCourse(string name) { UIKit.OpenPanel(); UIKit.OpenPanel(); m_OperatePanel = UIKit.OpenPanel( new PC_OperatePanelData { courseName = m_CourseName, OpenTitleBg = m_ActiveTitlePanel }); if (ProcessManagement.Instance) { ProcessManagement.Instance.EnterProcessEvent += m_OperatePanel.OnEnterProcessByStepID; ProcessManagement.Instance.processElementDisActiveEvent += m_OperatePanel.OnPrcessElementDisActive; ProcessManagement.Instance.processFinishEvent += ProcessEndPanel; } UIKit.OpenPanel(); } /// /// 完成所有流程后打开练习结束界面/成绩单界面 /// public void ProcessEndPanel() { switch (m_CurrentOperationMode) { case OperationMode.Practice: m_OperatePanel.PracticeEnd(); break; case OperationMode.Exam: //ExamManagerForPC.instance.ExamFinish(); //operatePanel.ExamEnd(); break; } } private void OnDisable() { if (ProcessManagement.Instance) { ProcessManagement.Instance.EnterProcessEvent -= m_OperatePanel.OnEnterProcessByStepID; ProcessManagement.Instance.processElementDisActiveEvent -= m_OperatePanel.OnPrcessElementDisActive; ProcessManagement.Instance.processFinishEvent -= ProcessEndPanel; } } }