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; public RawImage ShowRawImage; // 显示的视频画面 [SerializeField] private GameObject ShowRaw_go; // 显示的视频画面父物体 public 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; void Start() { Instance = this; if (mInspectionService == null) mInspectionService = this.GetService(); if (mInspectionService.InspectionInfo.id == PlayerPrefs.GetInt("XunJianInspectionInfoID")) { var step = PlayerPrefs.GetInt("ShowXunJianStep"); if (step != 0) { ToggleList[step - 1].isOn = true; currentUIItem = ItemList[step - 1]; } } 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.InspectionInfo.id == PlayerPrefs.GetInt("XunJianInspectionInfoID")) { Init(mInspectionService.InspectionInfo); } } private void Update() { #if UNITY_EDITOR if (Test) return; 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)) //是否执行到此步骤 { toggleBoolList[int.Parse(item.Key) - 1] = true; 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 按钮点击 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; sprite.name = arrayImageIndex.ToString(); arrayImage[arrayImageIndex].sprite = sprite; ItemList[arrayImageIndex / 3].ChangeSprite(arrayImageIndex % 3, this.GetUtility().TextureToTexture2D(ShowRawImage.texture)); 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; } } EndUI_go.SetActive(true); //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 } }