ShowXunJian_UIItem.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. public class ShowXunJian_UIItem : MonoBehaviour, IController
  9. {
  10. [SerializeField] private Button mNormal_Btn; //正常
  11. [SerializeField] private Button Warning_Btn; //异常
  12. [SerializeField] private GameObject NormalBG1_go;
  13. [SerializeField] private GameObject NormalBG2_go;
  14. [SerializeField] private GameObject WarningBG1_go;
  15. [SerializeField] private GameObject WarningBG2_go;
  16. [SerializeField] private GameObject NormalPanel_go;
  17. [SerializeField] private GameObject WarningPanel_go;
  18. [SerializeField] private SCInputField LabelText_Input;
  19. [SerializeField] private GameObject mErrorBtn_go;
  20. private void Start()
  21. {
  22. mNormal_Btn.onClick.AddListener(NormalClick);
  23. Warning_Btn.onClick.AddListener(WarningClick);
  24. LabelText_Input.onValueChanged.AddListener(NewStr => mOutliers = NewStr);
  25. }
  26. private void OnEnable()
  27. {
  28. StartCoroutine(SetCurrentUIItem());
  29. }
  30. private IEnumerator SetCurrentUIItem()
  31. {
  32. yield return new WaitForSeconds(0.01f);
  33. StartXunJian.Instance.currentUIItem = this;
  34. }
  35. private int mItemID; // 检查项目的编号 1-12
  36. private bool mNormal = true; //是否正常
  37. private string mOutliers = ""; // 标签
  38. private int mInspectionId; // 巡检编号,巡检开始时返回的id
  39. public void Set()
  40. {
  41. this.GetService<IInspectionService>().Set(mItemID, mNormal, mOutliers, mInspectionId, new string[3] { "1", "2", "3" });
  42. }
  43. public void InitData(int ItemID, int InspectionId, InspectionStep InspectionStep = null)
  44. {
  45. mItemID = ItemID;
  46. mInspectionId = InspectionId;
  47. if (InspectionStep != null)
  48. {
  49. if (InspectionStep.normal)
  50. NormalClick();
  51. else
  52. WarningClick();
  53. if (!string.IsNullOrWhiteSpace(InspectionStep.outliers))
  54. {
  55. LabelText_Input.text = InspectionStep.outliers;
  56. mOutliers = InspectionStep.outliers;
  57. }
  58. }
  59. }
  60. private float mErrorBtn_go_offset = 319;
  61. public void SetlabelBtnCount(string[] labelList)
  62. {
  63. foreach (string label in labelList)
  64. {
  65. GameObject go = Instantiate(mErrorBtn_go, mErrorBtn_go.transform.parent);
  66. go.GetComponentInChildren<TMP_Text>().text = label;
  67. go.name = label;
  68. Vector3 v3 = mErrorBtn_go.transform.localPosition;
  69. v3.x += mErrorBtn_go_offset;
  70. go.transform.localPosition = v3;
  71. go.SetActive(true);
  72. go.GetComponent<Button>().onClick.AddListener(() =>
  73. {
  74. LabelText_Input.text += go.name;
  75. mOutliers = LabelText_Input.text;
  76. });
  77. }
  78. }
  79. public void SetLabel(string Label)
  80. {
  81. mOutliers = Label;
  82. }
  83. private void NormalClick()
  84. {
  85. NormalBG1_go.SetActive(true);
  86. NormalBG2_go.SetActive(false);
  87. WarningBG1_go.SetActive(false);
  88. WarningBG2_go.SetActive(true);
  89. NormalPanel_go.SetActive(true);
  90. WarningPanel_go.SetActive(false);
  91. mNormal = true;
  92. }
  93. private void WarningClick()
  94. {
  95. NormalBG1_go.SetActive(false);
  96. NormalBG2_go.SetActive(true);
  97. WarningBG1_go.SetActive(true);
  98. WarningBG2_go.SetActive(false);
  99. NormalPanel_go.SetActive(false);
  100. WarningPanel_go.SetActive(true);
  101. mNormal = false;
  102. }
  103. }