using UnityEngine; using UnityEngine.UI; using QFramework; using Chiva.Toolkit.Function.NoBorder; using System.Collections.Generic; using System; using ChivaXR.Op; using System.Collections; using ChivaXR; using I2.Loc; using static SteamVR_TrackedObject; namespace QFramework { public class PC_OperatePanelData : UIPanelData { public string courseName = string.Empty; public bool OpenTitleBg; } public partial class PC_OperatePanel : UIPanel { List tmpStepListInfos; private string operateName; private AudioSource audioSource; /// /// 步骤数据代理 /// private StepListProxy m_StepListProxy; #region 多语言适配 private int CurrentStepID; public void RefrushLocalization() { if (LocalizationConfig.localization) { //左侧设备名称 LocalizedString courseTitle = ScriptTerms.operatepanel.coursetitle; OperationTitle_Shadow.text = courseTitle; OperationTitle.text = courseTitle; RefrushOperationTitleUISize(); //步骤标题 LocalizedString SubTitle = CurrentStepID + "stepDescr"; OperateStep.SubtitleText.text = SubTitle; } //TitleText.text = m_ParentIndex.ToString() + "." + m_Index.ToString() + " " + m_StepMsgInfo.stepName; } void OnEnable() { LocalizationManager.OnLocalizeEvent += LocalizationManager_OnLocalizeEvent; LocalizationManager_OnLocalizeEvent(); } void OnDisEnable() { LocalizationManager.OnLocalizeEvent -= LocalizationManager_OnLocalizeEvent; } private void LocalizationManager_OnLocalizeEvent() { if (LocalizationConfig.localization) { RefrushLocalization(); } } #endregion protected override void OnInit(IUIData uiData = null) { m_StepListProxy = DAL.Instance.Get(); mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData(); OperationTitle_Shadow.text = mData.courseName; OperationTitle.text = mData.courseName; RefrushOperationTitleUISize(); UserProxy tmpUserProxy = DAL.Instance.Get(); OperateStep.UserName.text = tmpUserProxy.userInfo.userName; OperateStep.HeadPortraitText.text = tmpUserProxy.userInfo.userName.Substring(0, 1); InitUI(); InitLogic(); } private void InitUI() { MinBtn.onClick.AddListener(() => WindowsSetting.Instance.OnMinBtnClick()); SystemBtn.onClick.AddListener(() => UIKit.OpenPanel()); CloseBtn.onClick.AddListener(() => { Application.Quit(); }); StartTips.gameObject.SetActive(true); } private void InitLogic() { audioSource = FindObjectOfType(); if (audioSource == null) { GameObject gameObject = new GameObject("AudioSource"); audioSource = gameObject.AddComponent(); } switch (OperateSetting.Instance.m_CurrentOperationMode) { case OperationMode.Learn: operateName = "操作步骤"; OperateStep.HelpBtn.gameObject.SetActive(false); OperateStep.AutoPlayBtn.gameObject.SetActive(true); OperateStep.ToolLibraryBtn.gameObject.SetActive(false); OperateStep.EndExam.gameObject.SetActive(false); //操作记录 OperateStep.OperateLogBtn.gameObject.SetActive(false); //播放暂停 StudyPanel.gameObject.SetActive(true); //关闭自动播放 if (ProcessManagement.Instance.autoEnterNextProcess) { OperateStep.OnAutoPlayBtnClick(); } break; case OperationMode.Practice: operateName = "操作步骤"; OperateStep.HelpBtn.gameObject.SetActive(true); OperateStep.AutoPlayBtn.gameObject.SetActive(false); OperateStep.ToolLibraryBtn.gameObject.SetActive(true); OperateStep.EndExam.gameObject.SetActive(false); break; case OperationMode.Exam: operateName = "操作步骤"; TitleTextLayoutGroup.gameObject.SetActive(false); OperateStep.HelpBtn.gameObject.SetActive(false); OperateStep.AutoPlayBtn.gameObject.SetActive(false); OperateStep.ToolLibraryBtn.gameObject.SetActive(true); OperateStep.EndExam.gameObject.SetActive(true); OperateStep.SubtitleBg.gameObject.SetActive(false); break; case OperationMode.Challenge: operateName = "操作步骤"; OperateStep.HelpBtn.gameObject.SetActive(false); break; } tmpStepListInfos = m_StepListProxy.ReadStepMsgInfoFromTable(mData.courseName); Dictionary> tmpDicStepMsgInfos = m_StepListProxy.ProcessingData(tmpStepListInfos); OperateStep.gameObject.SetActive(true); //OperateStep.SetTitle(operateName); OperateStep.GenerateFirstStepItemList(tmpDicStepMsgInfos); if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Learn) { OperateStep.ExpandAllFirstStepItem(); } } public void UpdateTitleText(string info) { TitleText.text = info; Mark.Init(); if (TitleText.preferredWidth < 750) { Mark.GetComponent().SetWidth(TitleText.preferredWidth); Mark.m_ParentWidth = 750; } else { Mark.GetComponent().SetWidth(750); Mark.m_ParentWidth = 750; } LayoutRebuilder.ForceRebuildLayoutImmediate(TitleTextLayoutGroup); } public void RefrushOperationTitleUISize() { float width = OperationTitle.preferredWidth; TitleClampMask.Init(); if (width < 450) { TitleClampMask.GetComponent().SetWidth(width); TitleClampMask.m_ParentWidth = 450; } else { width = 450; TitleClampMask.GetComponent().SetWidth(450); TitleClampMask.m_ParentWidth = 450; } TitleMask.rectTransform.SetWidth(width + 98); LeftLine.rectTransform.SetWidth(width + 100); RightLine.rectTransform.SetWidth(1920 - width - 75); } public void StartExam(int examTime) { ExamInfo.gameObject.SetActive(true); StartCoroutine(StartTime(examTime)); OperateStep.StartOperation() ; } public void StartGame() { TitleTextLayoutGroup.gameObject.SetActive(true); OperateStep.StartOperation(); } /// /// 计时器 /// /// public IEnumerator StartTime(int totolTime) { int sceond = totolTime * 60; while (sceond > 0) { yield return new WaitForSeconds(1); sceond--; ExamInfo.SetExamTime(sceond); } // 超时,弹出成绩单 ExamManagerForPC.instance.ExamFinish(); } OperationStepDataInfo tmpInfo; /// /// 据传进来的步骤ID处理展示具体的步骤名称 /// /// public void OnEnterProcessByStepID(int stepID) { //当前步骤ID CurrentStepID = stepID + 1; //刷新工具列表 if (UIKit.GetPanel() == null) { UIKit.OpenPanel().Hide(); } //流程进度 OperateStep.ScheduleText.text = "" + CurrentStepID + "" + "/" + ProcessManagement.Instance.processes.Count + ""; UIKit.GetPanel().RefrushAllChoseTool(); //刷新列表 if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Learn) { OperateStep.ShowSecondStepItemByStepId(stepID + 1); } else { //学习模式 OperateStep.SetSecondStepItemSelectByStepId(stepID + 1); if (StudyPanel.isPause) { StudyPanel.Play(); } } //考核模式不显示字幕 if (OperateSetting.Instance.m_CurrentOperationMode != OperationMode.Exam) { tmpInfo = tmpStepListInfos.Find(info => int.Parse(info.id) == (stepID + 1)); if (tmpInfo != null) { OperateStep.SubtitleBg.gameObject.SetActive(true); OperateStep.SubtitleText.text = tmpInfo.stepDescr; } } #region if (LocalizationConfig.localization) { RefrushLocalization(); } #endregion } public void OnPrcessElementDisActive(ProcessElement processElement) { OperateStep.SubtitleBg.gameObject.SetActive(false); } /// /// 练习结束弹窗 /// public void PracticeEnd() { PracticeResult.gameObject.SetActive(true); } /// /// 考核结束成绩表 /// public void ExamEnd(List elements, float score, int useTime) { StopAllCoroutines(); int index = ScoreInfo.transform.GetSiblingIndex(); TitleBG.transform.SetSiblingIndex(index - 1); ScoreInfo.gameObject.SetActive(true); ScoreInfo.SetInfo(elements, score, useTime); } ///// ///// 设置练习模式提示按钮状态 ///// ///// //public void SetHelpBtnState(bool select) //{ // OperateStep.SetHelpBtnState(select); //} protected override void OnOpen(IUIData uiData = null) { mData = uiData as PC_OperatePanelData ?? new PC_OperatePanelData(); TitleBG.gameObject.SetActive(mData.OpenTitleBg); } protected override void OnShow() { } protected override void OnHide() { } protected override void OnClose() { if (UIKit.GetPanel() != null) UIKit.ClosePanel(); } IEnumerator PlayAudioDelay(float duration, Action callBack) { yield return new WaitForSeconds(duration); callBack?.Invoke(); } private void Update() { //打开设置相机位置 if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F1)) { if (UIKit.GetPanel() == null) UIKit.OpenPanel(); } //题库设置单选/多选/判断 else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F2)) { } //题库设置图文 else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.F3)) { } } } }