OperationPanel.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using QFramework;
  4. using ChivaXR;
  5. using System;
  6. using DG.Tweening;
  7. using System.Collections.Generic;
  8. using System.Text.RegularExpressions;
  9. namespace QFramework
  10. {
  11. public class OperationPanelData : UIPanelData
  12. {
  13. public string operationName = string.Empty;
  14. public string courseName = string.Empty;
  15. public ToolPackConfig toolPackConfig;
  16. }
  17. public partial class OperationPanel : UIPanel
  18. {
  19. protected override void ProcessMsg(int eventId, QMsg msg)
  20. {
  21. throw new System.NotImplementedException();
  22. }
  23. private List<GameObject> treeItemList = new List<GameObject>();
  24. private Dictionary<int, List<object>> stepMsgDic;
  25. private AudioSource audioSource;
  26. protected override void OnInit(IUIData uiData = null)
  27. {
  28. mData = uiData as OperationPanelData ?? new OperationPanelData();
  29. audioSource = FindObjectOfType<AudioSource>();
  30. if(audioSource == null)
  31. {
  32. GameObject gameObject = new GameObject("AudioSource");
  33. audioSource = gameObject.AddComponent<AudioSource>();
  34. }
  35. if (!string.IsNullOrEmpty(mData.operationName))
  36. Title.text = mData.operationName;
  37. UITreeHideBtn.onClick.AddListener(UITreeHideBtnClick);
  38. //stepMsgDic = DataManager.GetStepMsg(mData.courseName, mData.toolPackConfig);
  39. InitilAllUITree();
  40. NextBtn.onClick.AddListener(() =>
  41. {
  42. ProcessManagement.Instance.NextProcessState();
  43. ProcessManagement.Instance.ActiveCurrentProcess();
  44. });
  45. LastBtn.onClick.AddListener(() =>
  46. {
  47. ProcessManagement.Instance.PreProcessState();
  48. ProcessManagement.Instance.ActiveCurrentProcess();
  49. });
  50. //BackBtn.onClick.AddListener(() =>
  51. //{
  52. // Application.Quit();
  53. //});
  54. }
  55. #region ButtonClick
  56. /// <summary>
  57. /// 步骤树形表隐藏
  58. /// </summary>
  59. private void UITreeHideBtnClick()
  60. {
  61. UITree.transform.DOMoveX(-10.4f, 1).OnComplete(() =>
  62. {
  63. UITreeShowBtn.gameObject.SetActive(true);
  64. UITreeShowBtn.onClick.AddListener(() =>
  65. {
  66. UITreeShowBtn.gameObject.SetActive(false);
  67. UITree.transform.DOMoveX(-7.1f, 1);
  68. });
  69. });
  70. }
  71. #endregion
  72. /// <summary>
  73. /// 根据传进来的步骤ID处理展示具体的步骤名称及注意事项
  74. /// </summary>
  75. /// <param name="stepID"></param>
  76. public void EnterProcessByStepID(int stepID)
  77. {
  78. RefreshUITree(stepID);
  79. InitilTip(stepID);
  80. Canvas.ForceUpdateCanvases();
  81. ScrollView.verticalNormalizedPosition = 0;
  82. }
  83. /// <summary>
  84. /// 刷新树形列表
  85. /// </summary>
  86. private void RefreshUITree(int stepID)
  87. {
  88. //步骤
  89. if (treeItemList.Count > 0 && stepID < treeItemList.Count)
  90. {
  91. for (int i = 0; i < treeItemList.Count; i++)
  92. {
  93. treeItemList[i].SetActive(false);
  94. if (i <= stepID)
  95. {
  96. treeItemList[i].SetActive(true);
  97. SetTreeItemColor();
  98. if (i == stepID)
  99. {
  100. var text = treeItemList[i].GetComponent<Text>();
  101. text.color = Color.white;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 实例化注意事项
  109. /// </summary>
  110. private void InitilTip(int stepID)
  111. {
  112. if (stepMsgDic.Count > 0 && stepID < stepMsgDic.Count)
  113. {
  114. var tips = stepMsgDic[stepID + 1];
  115. var matter = tips[1].ToString();
  116. var step = tips[2].ToString();
  117. var toolName = tips[3].ToString();
  118. var clipName = tips[tips.Count - 1].ToString();
  119. if (!string.IsNullOrEmpty(matter))
  120. AttentionContent.text = matter;
  121. else
  122. AttentionContent.text = string.Empty;
  123. if (!string.IsNullOrEmpty(toolName))
  124. {
  125. ToolConfig tmpToolConfig = mData.toolPackConfig.GetToolConfigByName(toolName);
  126. ToolName.text = toolName;
  127. ToolImage.gameObject.SetActive(true);
  128. ToolImage.GetComponent<Image>().sprite = tmpToolConfig.toolImg;
  129. }
  130. else
  131. {
  132. ToolName.text = string.Empty;
  133. ToolImage.gameObject.SetActive(false);
  134. }
  135. if (!string.IsNullOrEmpty(step))
  136. StepContent.text = step;
  137. else
  138. StepContent.text = string.Empty;
  139. if(!string.IsNullOrEmpty(clipName))
  140. {
  141. //StartCoroutine(DataManager.LoadAudioClip(mData.courseName, clipName, AudioType.MPEG, LoadAudioCallBack));
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 实例化树形列表
  147. /// </summary>
  148. private void InitilAllUITree()
  149. {
  150. if (stepMsgDic.Count > 0)
  151. {
  152. foreach (var key in stepMsgDic.Keys)
  153. {
  154. var tempItem = Instantiate(TreeItem.gameObject, TreeItem.transform.parent);
  155. tempItem.SetActive(false);
  156. treeItemList.Add(tempItem);
  157. Text text = tempItem.GetComponent<Text>();
  158. if (text == null)
  159. {
  160. text = tempItem.AddComponent<Text>();
  161. }
  162. var step = stepMsgDic[key][0].ToString();
  163. string stepName;
  164. if (Regex.Split(step, @"^\d+").Length >= 2) stepName = Regex.Split(step, @"^\d+")[1];
  165. else stepName = step;
  166. text.text = key.ToString("000") + " " + stepName;
  167. SetTreeItemColor();
  168. }
  169. }
  170. else
  171. {
  172. Debug.LogError("树形步骤表为空!!!");
  173. }
  174. }
  175. /// <summary>
  176. /// 设置TreeItem的字体颜色
  177. /// </summary>
  178. private void SetTreeItemColor()
  179. {
  180. if (treeItemList.Count > 0)
  181. {
  182. for (int i = 0; i < treeItemList.Count; i++)
  183. {
  184. Text text = treeItemList[i].GetComponent<Text>();
  185. text.color = new Color(163f / 255f, 163f / 255f, 163f / 255f);
  186. }
  187. }
  188. }
  189. /// <summary>
  190. /// 加载音频回调
  191. /// </summary>
  192. /// <param name="obj"></param>
  193. private void LoadAudioCallBack(AudioClip obj)
  194. {
  195. audioSource.clip = obj;
  196. audioSource.Play();
  197. }
  198. /// <summary>
  199. /// 获取指定项的音频名称
  200. /// </summary>
  201. /// <param name="_stepID"></param>
  202. /// <returns></returns>
  203. public string GetAudioNameOfSpecifiedItem(int _stepID)
  204. {
  205. if (stepMsgDic.Count <= 0)
  206. {
  207. return String.Empty;
  208. }
  209. return (string)stepMsgDic[_stepID + 1][5];
  210. }
  211. #region QFramework
  212. protected override void OnOpen(IUIData uiData = null)
  213. {
  214. }
  215. protected override void OnShow()
  216. {
  217. }
  218. protected override void OnHide()
  219. {
  220. treeItemList.Clear();
  221. }
  222. protected override void OnClose()
  223. {
  224. treeItemList.Clear();
  225. }
  226. #endregion
  227. }
  228. }