StartXunJian.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. public Image imageTest;
  33. private void Awake()
  34. {
  35. Instance = this;
  36. imageTest.sprite = this.GetUtility<IRawImageForSpriteUtility>().PngToSprite(Application.persistentDataPath+"/0.png",500,500);
  37. }
  38. void Start()
  39. {
  40. foreach (Button btn in ScreenshotBtnList)
  41. {
  42. btn.onClick.AddListener(ClickScreenshot);
  43. }
  44. foreach (Toggle toggle in ToggleList)
  45. {
  46. toggle.onValueChanged.AddListener(isOn =>
  47. {
  48. if (isOn)
  49. {
  50. currentUIItem.Set();
  51. }
  52. });
  53. }
  54. SaveBtn.onClick.AddListener(ClickSave);
  55. Titile_Btn.onClick.AddListener(ClickTitle);
  56. //CancelBtn.onClick.AddListener(ClickCancel);
  57. if (mInspectionService == null)
  58. mInspectionService = this.GetService<IInspectionService>();
  59. Init(mInspectionService.InspectionInfo);
  60. }
  61. private void Update()
  62. {
  63. if (Test) return;
  64. #if UNITY_EDITOR
  65. return;
  66. #endif
  67. OnReset?.Invoke();
  68. }
  69. public void Next()
  70. {
  71. ShowXunJian.Instance.gotoWindow(ScenesManager.SceneType.ShowDH);
  72. }
  73. public void back()
  74. {
  75. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  76. }
  77. public void ShowDeviceInfo()
  78. {
  79. ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowDevice);
  80. }
  81. [SerializeField] private List<TMP_Text> ItemNameTextList = new List<TMP_Text>(); // 步骤名
  82. [SerializeField] private List<TMP_Text> ItemUIList = new List<TMP_Text>(); // 步骤内+“是否正常”
  83. [SerializeField] private List<ShowXunJian_UIItem> ItemList = new List<ShowXunJian_UIItem>(); // 每个步骤内的数据
  84. [SerializeField] private List<GameObject> ErrorList = new List<GameObject>(); // 错误图标
  85. [SerializeField] private List<GameObject> BGList = new List<GameObject>(); // 选中后图标
  86. [SerializeField] private List<Toggle> ToggleList = new List<Toggle>();
  87. /// <summary>
  88. /// 初始化界面数据
  89. /// </summary>
  90. public void Init(InspectionInfo InspectionInfo)
  91. {
  92. foreach (var item in InspectionInfo.items)
  93. {
  94. ItemNameTextList[int.Parse(item.Key) - 1].text = item.Value.name + "接口";
  95. ItemUIList[int.Parse(item.Key) - 1].text = item.Key + "、" + item.Value.question;
  96. if (InspectionInfo.steps.ContainsKey(item.Key)) //是否执行到此步骤
  97. {
  98. ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id, InspectionInfo.steps[item.Key]);
  99. }
  100. else
  101. {
  102. ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id);
  103. }
  104. ItemList[int.Parse(item.Key) - 1].SetlabelBtnCount(item.Value.label);
  105. }
  106. foreach (var step in InspectionInfo.steps)
  107. {
  108. BGList[int.Parse(step.Key) - 1].SetActive(true);
  109. if (!step.Value.normal)
  110. ErrorList[int.Parse(step.Key) - 1].SetActive(true);
  111. }
  112. }
  113. #region 按钮点击
  114. [SerializeField] private Sprite mScreenshotSprite;
  115. private void ClickScreenshot()
  116. {
  117. if (!ShowRaw_go.activeSelf)
  118. {
  119. ShowRaw_go.SetActive(true);
  120. XRRGBCamera.Instance.playCamera(1280, 720);
  121. ShowRawImage.texture = XRRGBCamera.Instance.CaptureImage;
  122. }
  123. }
  124. private void ClickSave()
  125. {
  126. var sprite = this.GetUtility<IRawImageForSpriteUtility>().SwitchSprite(ShowRawImage);
  127. //ScreenshotImage.gameObject.SetActive(true);
  128. //ScreenshotImage.sprite = sprite;
  129. arrayImage[arrayImageIndex].sprite = sprite;
  130. arrayImageIndex++;
  131. if (arrayImageIndex % 3 == 0)
  132. {
  133. arrayImageIndex -= 3;
  134. }
  135. }
  136. public void SetIndex(int index)
  137. {
  138. this.arrayImageIndex = index;
  139. }
  140. private void ClickCancel()
  141. {
  142. /*
  143. arrayImageIndex--;
  144. if (arrayImageIndex < 0)
  145. arrayImageIndex = arrayImage.Length - 1;
  146. arrayImage[arrayImageIndex].sprite = mScreenshotSprite;
  147. */
  148. }
  149. public void End()
  150. {
  151. currentUIItem.Set();
  152. foreach (bool isOn in toggleBoolList)
  153. {
  154. if (!isOn)
  155. {
  156. DefaultUI_go.SetActive(true);
  157. return;
  158. }
  159. }
  160. EndUI_go.SetActive(true);
  161. //ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
  162. }
  163. public void HomeEnd()
  164. {
  165. currentUIItem.Set();
  166. foreach (bool isOn in toggleBoolList)
  167. {
  168. if (!isOn)
  169. {
  170. HomeEndUI_go.SetActive(true);
  171. return;
  172. }
  173. }
  174. back();
  175. }
  176. public void SetToogleBool(int index)
  177. {
  178. toggleBoolList[index] = true;
  179. }
  180. private bool isRetract = false;
  181. private void ClickTitle()
  182. {
  183. isRetract = !isRetract;
  184. if (isRetract)
  185. OnRetract?.Invoke();
  186. else
  187. OnExpand?.Invoke();
  188. }
  189. #endregion
  190. }
  191. }