StartXunJian.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. public RawImage ShowRawImage; // 显示的视频画面
  13. [SerializeField] private GameObject ShowRaw_go; // 显示的视频画面父物体
  14. public 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. void Start()
  33. {
  34. Instance = this;
  35. if (mInspectionService == null)
  36. mInspectionService = this.GetService<IInspectionService>();
  37. var step = PlayerPrefs.GetInt("ShowXunJianStep");
  38. ToggleList[step - 1].isOn = true;
  39. currentUIItem = ItemList[step - 1];
  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. Init(mInspectionService.InspectionInfo);
  58. }
  59. private void Update()
  60. {
  61. #if UNITY_EDITOR
  62. if (Test) return;
  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. toggleBoolList[int.Parse(item.Key) - 1] = true;
  97. ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id, InspectionInfo.steps[item.Key]);
  98. }
  99. else
  100. {
  101. ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id);
  102. }
  103. ItemList[int.Parse(item.Key) - 1].SetlabelBtnCount(item.Value.label);
  104. }
  105. foreach (var step in InspectionInfo.steps)
  106. {
  107. BGList[int.Parse(step.Key) - 1].SetActive(true);
  108. if (!step.Value.normal)
  109. ErrorList[int.Parse(step.Key) - 1].SetActive(true);
  110. }
  111. }
  112. #region 按钮点击
  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. sprite.name = arrayImageIndex.ToString();
  128. arrayImage[arrayImageIndex].sprite = sprite;
  129. ItemList[arrayImageIndex / 3].ChangeSprite(arrayImageIndex % 3, this.GetUtility<IRawImageForSpriteUtility>().TextureToTexture2D(ShowRawImage.texture));
  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. EndUI_go.SetActive(true);
  175. //back();
  176. }
  177. public void SetToogleBool(int index)
  178. {
  179. toggleBoolList[index] = true;
  180. }
  181. private bool isRetract = false;
  182. private void ClickTitle()
  183. {
  184. isRetract = !isRetract;
  185. if (isRetract)
  186. OnRetract?.Invoke();
  187. else
  188. OnExpand?.Invoke();
  189. }
  190. #endregion
  191. }
  192. }