ShowXunJian_UIItem.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System.Collections;
  2. using TMPro;
  3. using Blue;
  4. using GHZLangChao;
  5. using SC.XR.Unity;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using System.Collections.Generic;
  9. public class ShowXunJian_UIItem : MonoBehaviour, IController
  10. {
  11. [SerializeField] private Button mNormal_Btn; //正常
  12. [SerializeField] private Button Warning_Btn; //异常
  13. [SerializeField] private GameObject NormalBG1_go;
  14. [SerializeField] private GameObject NormalBG2_go;
  15. [SerializeField] private GameObject WarningBG1_go;
  16. [SerializeField] private GameObject WarningBG2_go;
  17. [SerializeField] private GameObject NormalPanel_go;
  18. [SerializeField] private GameObject WarningPanel_go;
  19. [SerializeField] private SCInputField LabelText_Input;
  20. [SerializeField] private GameObject mErrorBtn_go;
  21. [SerializeField] private List<XunJianUIItem_Texture> XunJianUIItemTexture_List;
  22. private void Start()
  23. {
  24. mNormal_Btn.onClick.AddListener(NormalClick);
  25. Warning_Btn.onClick.AddListener(WarningClick);
  26. LabelText_Input.onValueChanged.AddListener(NewStr => mOutliers = NewStr);
  27. }
  28. private void OnEnable()
  29. {
  30. StartCoroutine(SetCurrentUIItem());
  31. }
  32. private IEnumerator SetCurrentUIItem()
  33. {
  34. yield return new WaitForSeconds(0.01f);
  35. StartXunJian.Instance.currentUIItem = this;
  36. PlayerPrefs.SetInt("ShowXunJianStep", mItemID);
  37. }
  38. private int mItemID = 1; // 检查项目的编号 1-12
  39. private bool mNormal = true; //是否正常
  40. private string mOutliers = ""; // 标签
  41. private int mInspectionId; // 巡检编号,巡检开始时返回的id
  42. public void Set()
  43. {
  44. this.GetService<IInspectionService>().Set(mItemID, mNormal, mOutliers, mInspectionId, new int[3] { 1, 2, 3 });
  45. foreach (var ByteClass in byteDic)
  46. {
  47. //Debug.LogError($"是否上传:{ByteClass.Value.upload}");
  48. if (ByteClass.Value.upload)
  49. {
  50. byteDic[ByteClass.Key].upload = false;
  51. LangChaoMinIo.Instance.saveFile(ByteClass.Value.bytes,
  52. this.GetService<IInspectionService>().InspectionInfo.id,
  53. mItemID.ToString(),
  54. ByteClass.Key,
  55. msg =>
  56. {
  57. Debug.LogError("Set:" + msg);
  58. });
  59. }
  60. }
  61. }
  62. private Dictionary<int, ByteClass> byteDic = new Dictionary<int, ByteClass>();
  63. public void ChangeSprite(int id, Texture2D Texture2D)
  64. {
  65. if (byteDic.ContainsKey(id))
  66. byteDic[id] = new ByteClass() { upload = true, bytes = Texture2D.EncodeToPNG() };
  67. else
  68. byteDic.Add(id, new ByteClass() { upload = true, bytes = Texture2D.EncodeToPNG() });
  69. }
  70. public void InitData(int ItemID, int InspectionId, InspectionStep InspectionStep = null)
  71. {
  72. mItemID = ItemID;
  73. mInspectionId = InspectionId;
  74. if (InspectionStep != null)
  75. {
  76. if (InspectionStep.normal)
  77. NormalClick();
  78. else
  79. WarningClick();
  80. if (!string.IsNullOrWhiteSpace(InspectionStep.outliers))
  81. {
  82. LabelText_Input.text = InspectionStep.outliers;
  83. mOutliers = InspectionStep.outliers;
  84. }
  85. for (int i = 0; i < 3; i++)
  86. {
  87. XunJianUIItemTexture_List[i].GetSprite(byteDic, mItemID, i);
  88. }
  89. }
  90. }
  91. private float mErrorBtn_go_offset = 319;
  92. public void SetlabelBtnCount(string[] labelList)
  93. {
  94. foreach (string label in labelList)
  95. {
  96. GameObject go = Instantiate(mErrorBtn_go, mErrorBtn_go.transform.parent);
  97. go.GetComponentInChildren<TMP_Text>().text = label;
  98. go.name = label;
  99. Vector3 v3 = mErrorBtn_go.transform.localPosition;
  100. v3.x += mErrorBtn_go_offset;
  101. go.transform.localPosition = v3;
  102. go.SetActive(true);
  103. go.GetComponent<Button>().onClick.AddListener(() =>
  104. {
  105. LabelText_Input.text += go.name;
  106. mOutliers = LabelText_Input.text;
  107. });
  108. }
  109. }
  110. public void SetLabel(string Label)
  111. {
  112. mOutliers = Label;
  113. }
  114. private void NormalClick()
  115. {
  116. NormalBG1_go.SetActive(true);
  117. NormalBG2_go.SetActive(false);
  118. WarningBG1_go.SetActive(false);
  119. WarningBG2_go.SetActive(true);
  120. NormalPanel_go.SetActive(true);
  121. WarningPanel_go.SetActive(false);
  122. mNormal = true;
  123. }
  124. private void WarningClick()
  125. {
  126. NormalBG1_go.SetActive(false);
  127. NormalBG2_go.SetActive(true);
  128. WarningBG1_go.SetActive(true);
  129. WarningBG2_go.SetActive(false);
  130. NormalPanel_go.SetActive(false);
  131. WarningPanel_go.SetActive(true);
  132. mNormal = false;
  133. }
  134. }
  135. public static class CurrentStep
  136. {
  137. public static int step;
  138. }
  139. public class ByteClass
  140. {
  141. public bool upload;
  142. public byte[] bytes;
  143. }