123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using System.Collections.Generic;
- using Blue;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- using TMPro;
- namespace GHZLangChao
- {
- public class StartXunJian : AbstractController
- {
- public bool Test = false;
- [SerializeField] private RawImage ShowRawImage; // 显示的视频画面
- [SerializeField] private GameObject ShowRaw_go; // 显示的视频画面父物体
- [SerializeField] private Image[] arrayImage; // 截图显示的画面
- //[SerializeField] private Image ScreenshotImage; // 截图的画面
- private int arrayImageIndex = 0; // 截图显示时要显示在哪个Image上的下标
- [SerializeField] private Button[] ScreenshotBtnList;
- [SerializeField] private Button CancelBtn;
- [SerializeField] private Button SaveBtn;
- [SerializeField] private bool[] toggleBoolList;
- [SerializeField] private GameObject DefaultUI_go;
- [SerializeField] private GameObject EndUI_go;
- [SerializeField] private GameObject HomeEndUI_go;
- [SerializeField] private Button Titile_Btn;
- public UnityEvent OnReset = new UnityEvent(); // 重置事件
- public UnityEvent OnRetract = new UnityEvent(); // 收起时事件
- public UnityEvent OnExpand = new UnityEvent(); // 展开时事件
- public ShowXunJian_UIItem currentUIItem; // 当前选中的Item
- public ShowXunJian_UIItem LastUIItem; // 当前选中的Item
- private IInspectionService mInspectionService;
- public static StartXunJian Instance;
- public Image imageTest;
- private void Awake()
- {
- Instance = this;
- imageTest.sprite = this.GetUtility<IRawImageForSpriteUtility>().PngToSprite(Application.persistentDataPath+"/0.png",500,500);
- }
- void Start()
- {
- foreach (Button btn in ScreenshotBtnList)
- {
- btn.onClick.AddListener(ClickScreenshot);
- }
- foreach (Toggle toggle in ToggleList)
- {
- toggle.onValueChanged.AddListener(isOn =>
- {
- if (isOn)
- {
- currentUIItem.Set();
- }
- });
- }
- SaveBtn.onClick.AddListener(ClickSave);
- Titile_Btn.onClick.AddListener(ClickTitle);
- //CancelBtn.onClick.AddListener(ClickCancel);
- if (mInspectionService == null)
- mInspectionService = this.GetService<IInspectionService>();
- Init(mInspectionService.InspectionInfo);
- }
- private void Update()
- {
- if (Test) return;
- #if UNITY_EDITOR
- return;
- #endif
- OnReset?.Invoke();
- }
- public void Next()
- {
- ShowXunJian.Instance.gotoWindow(ScenesManager.SceneType.ShowDH);
- }
- public void back()
- {
- ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
- }
- public void ShowDeviceInfo()
- {
- ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowDevice);
- }
- [SerializeField] private List<TMP_Text> ItemNameTextList = new List<TMP_Text>(); // 步骤名
- [SerializeField] private List<TMP_Text> ItemUIList = new List<TMP_Text>(); // 步骤内+“是否正常”
- [SerializeField] private List<ShowXunJian_UIItem> ItemList = new List<ShowXunJian_UIItem>(); // 每个步骤内的数据
- [SerializeField] private List<GameObject> ErrorList = new List<GameObject>(); // 错误图标
- [SerializeField] private List<GameObject> BGList = new List<GameObject>(); // 选中后图标
- [SerializeField] private List<Toggle> ToggleList = new List<Toggle>();
- /// <summary>
- /// 初始化界面数据
- /// </summary>
- public void Init(InspectionInfo InspectionInfo)
- {
- foreach (var item in InspectionInfo.items)
- {
- ItemNameTextList[int.Parse(item.Key) - 1].text = item.Value.name + "接口";
- ItemUIList[int.Parse(item.Key) - 1].text = item.Key + "、" + item.Value.question;
- if (InspectionInfo.steps.ContainsKey(item.Key)) //是否执行到此步骤
- {
- ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id, InspectionInfo.steps[item.Key]);
- }
- else
- {
- ItemList[int.Parse(item.Key) - 1].InitData(int.Parse(item.Key), InspectionInfo.id);
- }
- ItemList[int.Parse(item.Key) - 1].SetlabelBtnCount(item.Value.label);
- }
- foreach (var step in InspectionInfo.steps)
- {
- BGList[int.Parse(step.Key) - 1].SetActive(true);
- if (!step.Value.normal)
- ErrorList[int.Parse(step.Key) - 1].SetActive(true);
- }
- }
- #region 按钮点击
- [SerializeField] private Sprite mScreenshotSprite;
- private void ClickScreenshot()
- {
- if (!ShowRaw_go.activeSelf)
- {
- ShowRaw_go.SetActive(true);
- XRRGBCamera.Instance.playCamera(1280, 720);
- ShowRawImage.texture = XRRGBCamera.Instance.CaptureImage;
- }
- }
- private void ClickSave()
- {
- var sprite = this.GetUtility<IRawImageForSpriteUtility>().SwitchSprite(ShowRawImage);
- //ScreenshotImage.gameObject.SetActive(true);
- //ScreenshotImage.sprite = sprite;
- arrayImage[arrayImageIndex].sprite = sprite;
- arrayImageIndex++;
- if (arrayImageIndex % 3 == 0)
- {
- arrayImageIndex -= 3;
- }
- }
- public void SetIndex(int index)
- {
- this.arrayImageIndex = index;
- }
- private void ClickCancel()
- {
- /*
- arrayImageIndex--;
- if (arrayImageIndex < 0)
- arrayImageIndex = arrayImage.Length - 1;
- arrayImage[arrayImageIndex].sprite = mScreenshotSprite;
- */
- }
- public void End()
- {
- currentUIItem.Set();
- foreach (bool isOn in toggleBoolList)
- {
- if (!isOn)
- {
- DefaultUI_go.SetActive(true);
- return;
- }
- }
- EndUI_go.SetActive(true);
- //ScenesManager.Instance.showWindow(ScenesManager.SceneType.ShowChoose);
- }
- public void HomeEnd()
- {
- currentUIItem.Set();
- foreach (bool isOn in toggleBoolList)
- {
- if (!isOn)
- {
- HomeEndUI_go.SetActive(true);
- return;
- }
- }
- back();
- }
- public void SetToogleBool(int index)
- {
- toggleBoolList[index] = true;
- }
- private bool isRetract = false;
- private void ClickTitle()
- {
- isRetract = !isRetract;
- if (isRetract)
- OnRetract?.Invoke();
- else
- OnExpand?.Invoke();
- }
- #endregion
- }
- }
|