StartXunJian.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 + "接口";
  93. ItemUIList[int.Parse(item.Key) - 1].text = item.Key + "、" + item.Value + "是否正常" + "接口";
  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. }
  103. foreach (var step in InspectionInfo.steps)
  104. {
  105. BGList[int.Parse(step.Key) - 1].SetActive(true);
  106. if (!step.Value.normal)
  107. ErrorList[int.Parse(step.Key) - 1].SetActive(true);
  108. }
  109. }
  110. #region 按钮点击
  111. [SerializeField] private Sprite mScreenshotSprite;
  112. private void ClickScreenshot()
  113. {
  114. if (!ShowRaw_go.activeSelf)
  115. {
  116. ShowRaw_go.SetActive(true);
  117. XRRGBCamera.Instance.playCamera(1280, 720);
  118. ShowRawImage.texture = XRRGBCamera.Instance.CaptureImage;
  119. }
  120. }
  121. private void ClickSave()
  122. {
  123. var sprite = this.GetUtility<IRawImageForSpriteUtility>().SwitchSprite(ShowRawImage);
  124. //ScreenshotImage.gameObject.SetActive(true);
  125. //ScreenshotImage.sprite = sprite;
  126. arrayImage[arrayImageIndex].sprite = sprite;
  127. arrayImageIndex++;
  128. if (arrayImageIndex % 3 == 0)
  129. {
  130. arrayImageIndex -= 3;
  131. }
  132. }
  133. public void SetIndex(int index)
  134. {
  135. this.arrayImageIndex = index;
  136. }
  137. private void ClickCancel()
  138. {
  139. /*
  140. arrayImageIndex--;
  141. if (arrayImageIndex < 0)
  142. arrayImageIndex = arrayImage.Length - 1;
  143. arrayImage[arrayImageIndex].sprite = mScreenshotSprite;
  144. */
  145. }
  146. public void End()
  147. {
  148. foreach (bool isOn in toggleBoolList)
  149. {
  150. if (!isOn)
  151. {
  152. DefaultUI_go.SetActive(true);
  153. return;
  154. }
  155. }
  156. EndUI_go.SetActive(true);
  157. //ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  158. }
  159. public void HomeEnd()
  160. {
  161. currentUIItem.Set();
  162. foreach (bool isOn in toggleBoolList)
  163. {
  164. if (!isOn)
  165. {
  166. HomeEndUI_go.SetActive(true);
  167. return;
  168. }
  169. }
  170. back();
  171. }
  172. public void SetToogleBool(int index)
  173. {
  174. toggleBoolList[index] = true;
  175. }
  176. private bool isRetract = false;
  177. private void ClickTitle()
  178. {
  179. isRetract = !isRetract;
  180. if (isRetract)
  181. OnRetract?.Invoke();
  182. else
  183. OnExpand?.Invoke();
  184. }
  185. #endregion
  186. }
  187. }