ShowXunJian_UIItem.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections;
  2. using System.Collections.Generic;
  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. private void Start()
  20. {
  21. mNormal_Btn.onClick.AddListener(NormalClick);
  22. Warning_Btn.onClick.AddListener(WarningClick);
  23. LabelText_Input.onValueChanged.AddListener(NewStr => mLabel = NewStr);
  24. }
  25. private void OnEnable()
  26. {
  27. StartCoroutine(SetCurrentUIItem());
  28. }
  29. private IEnumerator SetCurrentUIItem()
  30. {
  31. yield return new WaitForSeconds(0.01f);
  32. StartXunJian.Instance.currentUIItem = this;
  33. }
  34. private int mItemID; // 检查项目的编号 1-12
  35. private bool mNormal = true; //是否正常
  36. private string mLabel = ""; // 标签
  37. private int mInspectionId; // 巡检编号,巡检开始时返回的id
  38. public void Set()
  39. {
  40. this.GetService<IInspectionService>().Set(mItemID, mNormal, mLabel, mInspectionId);
  41. }
  42. public void InitData(int ItemID, int InspectionId, InspectionStep InspectionStep = null)
  43. {
  44. mItemID = ItemID;
  45. mInspectionId = InspectionId;
  46. if (InspectionStep != null)
  47. {
  48. if (InspectionStep.normal)
  49. NormalClick();
  50. else
  51. WarningClick();
  52. if (!string.IsNullOrWhiteSpace(InspectionStep.label))
  53. {
  54. LabelText_Input.text = InspectionStep.label;
  55. mLabel = InspectionStep.label;
  56. }
  57. }
  58. }
  59. public void SetLabel(string Label)
  60. {
  61. mLabel = Label;
  62. }
  63. private void NormalClick()
  64. {
  65. NormalBG1_go.SetActive(true);
  66. NormalBG2_go.SetActive(false);
  67. WarningBG1_go.SetActive(false);
  68. WarningBG2_go.SetActive(true);
  69. NormalPanel_go.SetActive(true);
  70. WarningPanel_go.SetActive(false);
  71. mNormal = true;
  72. }
  73. private void WarningClick()
  74. {
  75. NormalBG1_go.SetActive(false);
  76. NormalBG2_go.SetActive(true);
  77. WarningBG1_go.SetActive(true);
  78. WarningBG2_go.SetActive(false);
  79. NormalPanel_go.SetActive(false);
  80. WarningPanel_go.SetActive(true);
  81. mNormal = false;
  82. }
  83. }