123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- 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<GameObject> treeItemList = new List<GameObject>();
- private Dictionary<int, List<object>> stepMsgDic;
- private AudioSource audioSource;
- protected override void OnInit(IUIData uiData = null)
- {
- mData = uiData as OperationPanelData ?? new OperationPanelData();
- audioSource = FindObjectOfType<AudioSource>();
- if(audioSource == null)
- {
- GameObject gameObject = new GameObject("AudioSource");
- audioSource = gameObject.AddComponent<AudioSource>();
- }
- 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
- /// <summary>
- /// 步骤树形表隐藏
- /// </summary>
- 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
- /// <summary>
- /// 根据传进来的步骤ID处理展示具体的步骤名称及注意事项
- /// </summary>
- /// <param name="stepID"></param>
- public void EnterProcessByStepID(int stepID)
- {
- RefreshUITree(stepID);
- InitilTip(stepID);
- Canvas.ForceUpdateCanvases();
- ScrollView.verticalNormalizedPosition = 0;
- }
- /// <summary>
- /// 刷新树形列表
- /// </summary>
- 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>();
- text.color = Color.white;
- }
- }
- }
- }
- }
- /// <summary>
- /// 实例化注意事项
- /// </summary>
- 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<Image>().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));
- }
- }
- }
- /// <summary>
- /// 实例化树形列表
- /// </summary>
- 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<Text>();
- if (text == null)
- {
- text = tempItem.AddComponent<Text>();
- }
- 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("树形步骤表为空!!!");
- }
- }
- /// <summary>
- /// 设置TreeItem的字体颜色
- /// </summary>
- private void SetTreeItemColor()
- {
- if (treeItemList.Count > 0)
- {
- for (int i = 0; i < treeItemList.Count; i++)
- {
- Text text = treeItemList[i].GetComponent<Text>();
- text.color = new Color(163f / 255f, 163f / 255f, 163f / 255f);
- }
- }
- }
- /// <summary>
- /// 加载音频回调
- /// </summary>
- /// <param name="obj"></param>
- private void LoadAudioCallBack(AudioClip obj)
- {
- audioSource.clip = obj;
- audioSource.Play();
- }
- /// <summary>
- /// 获取指定项的音频名称
- /// </summary>
- /// <param name="_stepID"></param>
- /// <returns></returns>
- 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
- }
- }
|