123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using System.Collections;
- using TMPro;
- using Blue;
- using GHZLangChao;
- using SC.XR.Unity;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections.Generic;
- public class ShowXunJian_UIItem : MonoBehaviour, IController
- {
- [SerializeField] private Button mNormal_Btn; //正常
- [SerializeField] private Button Warning_Btn; //异常
- [SerializeField] private GameObject NormalBG1_go;
- [SerializeField] private GameObject NormalBG2_go;
- [SerializeField] private GameObject WarningBG1_go;
- [SerializeField] private GameObject WarningBG2_go;
- [SerializeField] private GameObject NormalPanel_go;
- [SerializeField] private GameObject WarningPanel_go;
- [SerializeField] private SCInputField LabelText_Input;
- [SerializeField] private GameObject mErrorBtn_go;
- [SerializeField] private List<XunJianUIItem_Texture> XunJianUIItemTexture_List;
- private void Start()
- {
- mNormal_Btn.onClick.AddListener(NormalClick);
- Warning_Btn.onClick.AddListener(WarningClick);
- LabelText_Input.onValueChanged.AddListener(NewStr => mOutliers = NewStr);
- }
- private void OnEnable()
- {
- StartCoroutine(SetCurrentUIItem());
- }
- private IEnumerator SetCurrentUIItem()
- {
- yield return new WaitForSeconds(0.01f);
- StartXunJian.Instance.currentUIItem = this;
- PlayerPrefs.SetInt("ShowXunJianStep", mItemID);
- }
- private int mItemID = 1; // 检查项目的编号 1-12
- private bool mNormal = true; //是否正常
- private string mOutliers = ""; // 标签
- private int mInspectionId; // 巡检编号,巡检开始时返回的id
- public void Set()
- {
- this.GetService<IInspectionService>().Set(mItemID, mNormal, mOutliers, mInspectionId, new int[3] { 1, 2, 3 });
- foreach (var ByteClass in byteDic)
- {
- //Debug.LogError($"是否上传:{ByteClass.Value.upload}");
- if (ByteClass.Value.upload)
- {
- byteDic[ByteClass.Key].upload = false;
- LangChaoMinIo.Instance.saveFile(ByteClass.Value.bytes,
- this.GetService<IInspectionService>().InspectionInfo.id,
- mItemID.ToString(),
- ByteClass.Key,
- msg =>
- {
- Debug.LogError("Set:" + msg);
- });
- }
- }
- }
-
- private Dictionary<int, ByteClass> byteDic = new Dictionary<int, ByteClass>();
- public void ChangeSprite(int id, Texture2D Texture2D)
- {
- if (byteDic.ContainsKey(id))
- byteDic[id] = new ByteClass() { upload = true, bytes = Texture2D.EncodeToPNG() };
- else
- byteDic.Add(id, new ByteClass() { upload = true, bytes = Texture2D.EncodeToPNG() });
- }
- public void InitData(int ItemID, int InspectionId, InspectionStep InspectionStep = null)
- {
- mItemID = ItemID;
- mInspectionId = InspectionId;
- if (InspectionStep != null)
- {
- if (InspectionStep.normal)
- NormalClick();
- else
- WarningClick();
- if (!string.IsNullOrWhiteSpace(InspectionStep.outliers))
- {
- LabelText_Input.text = InspectionStep.outliers;
- mOutliers = InspectionStep.outliers;
- }
- for (int i = 0; i < 3; i++)
- {
- XunJianUIItemTexture_List[i].GetSprite(byteDic, mItemID, i);
- }
- }
- }
- private float mErrorBtn_go_offset = 319;
- public void SetlabelBtnCount(string[] labelList)
- {
- foreach (string label in labelList)
- {
- GameObject go = Instantiate(mErrorBtn_go, mErrorBtn_go.transform.parent);
- go.GetComponentInChildren<TMP_Text>().text = label;
- go.name = label;
- Vector3 v3 = mErrorBtn_go.transform.localPosition;
- v3.x += mErrorBtn_go_offset;
- go.transform.localPosition = v3;
- go.SetActive(true);
- go.GetComponent<Button>().onClick.AddListener(() =>
- {
- LabelText_Input.text += go.name;
- mOutliers = LabelText_Input.text;
- });
- }
- }
- public void SetLabel(string Label)
- {
- mOutliers = Label;
- }
- private void NormalClick()
- {
- NormalBG1_go.SetActive(true);
- NormalBG2_go.SetActive(false);
- WarningBG1_go.SetActive(false);
- WarningBG2_go.SetActive(true);
- NormalPanel_go.SetActive(true);
- WarningPanel_go.SetActive(false);
- mNormal = true;
- }
- private void WarningClick()
- {
- NormalBG1_go.SetActive(false);
- NormalBG2_go.SetActive(true);
- WarningBG1_go.SetActive(true);
- WarningBG2_go.SetActive(false);
- NormalPanel_go.SetActive(false);
- WarningPanel_go.SetActive(true);
- mNormal = false;
- }
- }
- public static class CurrentStep
- {
- public static int step;
- }
- public class ByteClass
- {
- public bool upload;
- public byte[] bytes;
- }
|