StartXunJian.cs 7.7 KB

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