using UnityEngine; using UnityEngine.UI; using QFramework; using ChivaXR; using System; using DG.Tweening; using System.Collections.Generic; using System.Text.RegularExpressions; namespace QFramework { public class OperationPanelData : UIPanelData { public string operationName = string.Empty; public string courseName = string.Empty; public ToolPackConfig toolPackConfig; } public partial class OperationPanel : UIPanel { protected override void ProcessMsg(int eventId, QMsg msg) { throw new System.NotImplementedException(); } private List treeItemList = new List(); private Dictionary> stepMsgDic; private AudioSource audioSource; protected override void OnInit(IUIData uiData = null) { mData = uiData as OperationPanelData ?? new OperationPanelData(); audioSource = FindObjectOfType(); if(audioSource == null) { GameObject gameObject = new GameObject("AudioSource"); audioSource = gameObject.AddComponent(); } if (!string.IsNullOrEmpty(mData.operationName)) Title.text = mData.operationName; UITreeHideBtn.onClick.AddListener(UITreeHideBtnClick); //stepMsgDic = DataManager.GetStepMsg(mData.courseName, mData.toolPackConfig); InitilAllUITree(); NextBtn.onClick.AddListener(() => { ProcessManagement.Instance.NextProcessState(); ProcessManagement.Instance.ActiveCurrentProcess(); }); LastBtn.onClick.AddListener(() => { ProcessManagement.Instance.PreProcessState(); ProcessManagement.Instance.ActiveCurrentProcess(); }); //BackBtn.onClick.AddListener(() => //{ // Application.Quit(); //}); } #region ButtonClick /// /// 步骤树形表隐藏 /// private void UITreeHideBtnClick() { UITree.transform.DOMoveX(-10.4f, 1).OnComplete(() => { UITreeShowBtn.gameObject.SetActive(true); UITreeShowBtn.onClick.AddListener(() => { UITreeShowBtn.gameObject.SetActive(false); UITree.transform.DOMoveX(-7.1f, 1); }); }); } #endregion /// /// 根据传进来的步骤ID处理展示具体的步骤名称及注意事项 /// /// public void EnterProcessByStepID(int stepID) { RefreshUITree(stepID); InitilTip(stepID); Canvas.ForceUpdateCanvases(); ScrollView.verticalNormalizedPosition = 0; } /// /// 刷新树形列表 /// private void RefreshUITree(int stepID) { //步骤 if (treeItemList.Count > 0 && stepID < treeItemList.Count) { for (int i = 0; i < treeItemList.Count; i++) { treeItemList[i].SetActive(false); if (i <= stepID) { treeItemList[i].SetActive(true); SetTreeItemColor(); if (i == stepID) { var text = treeItemList[i].GetComponent(); text.color = Color.white; } } } } } /// /// 实例化注意事项 /// private void InitilTip(int stepID) { if (stepMsgDic.Count > 0 && stepID < stepMsgDic.Count) { var tips = stepMsgDic[stepID + 1]; var matter = tips[1].ToString(); var step = tips[2].ToString(); var toolName = tips[3].ToString(); var clipName = tips[tips.Count - 1].ToString(); if (!string.IsNullOrEmpty(matter)) AttentionContent.text = matter; else AttentionContent.text = string.Empty; if (!string.IsNullOrEmpty(toolName)) { ToolConfig tmpToolConfig = mData.toolPackConfig.GetToolConfigByName(toolName); ToolName.text = toolName; ToolImage.gameObject.SetActive(true); ToolImage.GetComponent().sprite = tmpToolConfig.toolImg; } else { ToolName.text = string.Empty; ToolImage.gameObject.SetActive(false); } if (!string.IsNullOrEmpty(step)) StepContent.text = step; else StepContent.text = string.Empty; if(!string.IsNullOrEmpty(clipName)) { //StartCoroutine(DataManager.LoadAudioClip(mData.courseName, clipName, AudioType.MPEG, LoadAudioCallBack)); } } } /// /// 实例化树形列表 /// private void InitilAllUITree() { if (stepMsgDic.Count > 0) { foreach (var key in stepMsgDic.Keys) { var tempItem = Instantiate(TreeItem.gameObject, TreeItem.transform.parent); tempItem.SetActive(false); treeItemList.Add(tempItem); Text text = tempItem.GetComponent(); if (text == null) { text = tempItem.AddComponent(); } var step = stepMsgDic[key][0].ToString(); string stepName; if (Regex.Split(step, @"^\d+").Length >= 2) stepName = Regex.Split(step, @"^\d+")[1]; else stepName = step; text.text = key.ToString("000") + " " + stepName; SetTreeItemColor(); } } else { Debug.LogError("树形步骤表为空!!!"); } } /// /// 设置TreeItem的字体颜色 /// private void SetTreeItemColor() { if (treeItemList.Count > 0) { for (int i = 0; i < treeItemList.Count; i++) { Text text = treeItemList[i].GetComponent(); text.color = new Color(163f / 255f, 163f / 255f, 163f / 255f); } } } /// /// 加载音频回调 /// /// private void LoadAudioCallBack(AudioClip obj) { audioSource.clip = obj; audioSource.Play(); } /// /// 获取指定项的音频名称 /// /// /// public string GetAudioNameOfSpecifiedItem(int _stepID) { if (stepMsgDic.Count <= 0) { return String.Empty; } return (string)stepMsgDic[_stepID + 1][5]; } #region QFramework protected override void OnOpen(IUIData uiData = null) { } protected override void OnShow() { } protected override void OnHide() { treeItemList.Clear(); } protected override void OnClose() { treeItemList.Clear(); } #endregion } }