StartXunJian.cs 7.4 KB

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