StartXunJian.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using System.Collections.Generic;
  2. using Blue;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. namespace GHZLangChao
  8. {
  9. public class StartXunJian : AbstractController
  10. {
  11. public bool Test = false;
  12. [SerializeField] private RawImage ShowRawImage; // 显示的视频画面
  13. [SerializeField] private GameObject ShowRaw_go; // 显示的视频画面父物体
  14. [SerializeField] private Image[] arrayImage; // 截图显示的画面
  15. //[SerializeField] private Image ScreenshotImage; // 截图的画面
  16. private int arrayImageIndex = 0; // 截图显示时要显示在哪个Image上的下标
  17. [SerializeField] private Button[] ScreenshotBtnList;
  18. [SerializeField] private Button CancelBtn;
  19. [SerializeField] private Button SaveBtn;
  20. [SerializeField] private bool[] toggleBoolList;
  21. [SerializeField] private GameObject DefaultUI_go;
  22. [SerializeField] private GameObject EndUI_go;
  23. [SerializeField] private GameObject HomeEndUI_go;
  24. [SerializeField] private Button Titile_Btn;
  25. public UnityEvent OnReset = new UnityEvent(); // 重置事件
  26. public UnityEvent OnRetract = new UnityEvent(); // 收起时事件
  27. public UnityEvent OnExpand = new UnityEvent(); // 展开时事件
  28. public ShowXunJian_UIItem currentUIItem; // 当前选中的Item
  29. public ShowXunJian_UIItem LastUIItem; // 当前选中的Item
  30. private IInspectionService mInspectionService;
  31. public static StartXunJian Instance;
  32. private void Awake()
  33. {
  34. Instance = this;
  35. }
  36. void Start()
  37. {
  38. foreach (Button btn in ScreenshotBtnList)
  39. {
  40. btn.onClick.AddListener(ClickScreenshot);
  41. }
  42. foreach (Toggle toggle in ToggleList)
  43. {
  44. toggle.onValueChanged.AddListener(isOn =>
  45. {
  46. if (isOn)
  47. {
  48. currentUIItem.Set();
  49. }
  50. });
  51. }
  52. SaveBtn.onClick.AddListener(ClickSave);
  53. Titile_Btn.onClick.AddListener(ClickTitle);
  54. //CancelBtn.onClick.AddListener(ClickCancel);
  55. if (mInspectionService == null)
  56. mInspectionService = this.GetService<IInspectionService>();
  57. Init(mInspectionService.InspectionInfo);
  58. }
  59. private void Update()
  60. {
  61. if (Test) return;
  62. #if UNITY_EDITOR
  63. return;
  64. #endif
  65. OnReset?.Invoke();
  66. }
  67. public void Next()
  68. {
  69. ShowXunJian.Instance.gotoWindow(ScenesManager.SceneType.ShowDH);
  70. }
  71. public void back()
  72. {
  73. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  74. }
  75. public void ShowDeviceInfo()
  76. {
  77. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowDevice);
  78. }
  79. [SerializeField] private List<TMP_Text> ItemNameTextList = new List<TMP_Text>(); // 步骤名
  80. [SerializeField] private List<TMP_Text> ItemUIList = new List<TMP_Text>(); // 步骤内+“是否正常”
  81. [SerializeField] private List<ShowXunJian_UIItem> ItemList = new List<ShowXunJian_UIItem>(); // 每个步骤内的数据
  82. [SerializeField] private List<GameObject> ErrorList = new List<GameObject>(); // 错误图标
  83. [SerializeField] private List<GameObject> BGList = new List<GameObject>(); // 选中后图标
  84. [SerializeField] private List<Toggle> ToggleList = new List<Toggle>();
  85. /// <summary>
  86. /// 初始化界面数据
  87. /// </summary>
  88. public void Init(InspectionInfo InspectionInfo)
  89. {
  90. foreach (var item in InspectionInfo.items)
  91. {
  92. ItemNameTextList[int.Parse(item.Key) - 1].text = item.Value.name + "接口";
  93. ItemUIList[int.Parse(item.Key) - 1].text = item.Key + "、" + item.Value.question;
  94. if (InspectionInfo.steps.ContainsKey(item.Key)) //是否执行到此步骤
  95. {
  96. ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id, InspectionInfo.steps[item.Key]);
  97. }
  98. else
  99. {
  100. ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id);
  101. }
  102. ItemList[int.Parse(item.Key) - 1].SetlabelBtnCount(item.Value.label);
  103. }
  104. foreach (var step in InspectionInfo.steps)
  105. {
  106. BGList[int.Parse(step.Key) - 1].SetActive(true);
  107. if (!step.Value.normal)
  108. ErrorList[int.Parse(step.Key) - 1].SetActive(true);
  109. }
  110. }
  111. #region 按钮点击
  112. [SerializeField] private Sprite mScreenshotSprite;
  113. private void ClickScreenshot()
  114. {
  115. if (!ShowRaw_go.activeSelf)
  116. {
  117. ShowRaw_go.SetActive(true);
  118. XRRGBCamera.Instance.playCamera(1280, 720);
  119. ShowRawImage.texture = XRRGBCamera.Instance.CaptureImage;
  120. }
  121. }
  122. private void ClickSave()
  123. {
  124. var sprite = this.GetUtility<IRawImageForSpriteUtility>().SwitchSprite(ShowRawImage);
  125. //ScreenshotImage.gameObject.SetActive(true);
  126. //ScreenshotImage.sprite = sprite;
  127. arrayImage[arrayImageIndex].sprite = sprite;
  128. arrayImageIndex++;
  129. if (arrayImageIndex % 3 == 0)
  130. {
  131. arrayImageIndex -= 3;
  132. }
  133. }
  134. public void SetIndex(int index)
  135. {
  136. this.arrayImageIndex = index;
  137. }
  138. private void ClickCancel()
  139. {
  140. /*
  141. arrayImageIndex--;
  142. if (arrayImageIndex < 0)
  143. arrayImageIndex = arrayImage.Length - 1;
  144. arrayImage[arrayImageIndex].sprite = mScreenshotSprite;
  145. */
  146. }
  147. public void End()
  148. {
  149. currentUIItem.Set();
  150. foreach (bool isOn in toggleBoolList)
  151. {
  152. if (!isOn)
  153. {
  154. DefaultUI_go.SetActive(true);
  155. return;
  156. }
  157. }
  158. EndUI_go.SetActive(true);
  159. //ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  160. }
  161. public void HomeEnd()
  162. {
  163. currentUIItem.Set();
  164. foreach (bool isOn in toggleBoolList)
  165. {
  166. if (!isOn)
  167. {
  168. HomeEndUI_go.SetActive(true);
  169. return;
  170. }
  171. }
  172. back();
  173. }
  174. public void SetToogleBool(int index)
  175. {
  176. toggleBoolList[index] = true;
  177. }
  178. private bool isRetract = false;
  179. private void ClickTitle()
  180. {
  181. isRetract = !isRetract;
  182. if (isRetract)
  183. OnRetract?.Invoke();
  184. else
  185. OnExpand?.Invoke();
  186. }
  187. #endregion
  188. }
  189. }