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().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(); 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 ItemNameTextList = new List(); // 步骤名 [SerializeField] private List ItemUIList = new List(); // 步骤内+“是否正常” [SerializeField] private List ItemList = new List(); // 每个步骤内的数据 [SerializeField] private List ErrorList = new List(); // 错误图标 [SerializeField] private List BGList = new List(); // 选中后图标 [SerializeField] private List ToggleList = new List(); /// /// 初始化界面数据 /// 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().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 } }