ShowXunJian_UIItem.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. public Image Screenshot_0_Image;
  21. public Image Screenshot_1_Image;
  22. public Image Screenshot_2_Image;
  23. private void Start()
  24. {
  25. mNormal_Btn.onClick.AddListener(NormalClick);
  26. Warning_Btn.onClick.AddListener(WarningClick);
  27. LabelText_Input.onValueChanged.AddListener(NewStr => mOutliers = NewStr);
  28. }
  29. private void OnEnable()
  30. {
  31. StartCoroutine(SetCurrentUIItem());
  32. }
  33. private IEnumerator SetCurrentUIItem()
  34. {
  35. yield return new WaitForSeconds(0.01f);
  36. StartXunJian.Instance.currentUIItem = this;
  37. }
  38. private int mItemID; // 检查项目的编号 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 string[3] { "1", "2", "3" });
  45. }
  46. public void InitData(int ItemID, int InspectionId, InspectionStep InspectionStep = null)
  47. {
  48. mItemID = ItemID;
  49. mInspectionId = InspectionId;
  50. if (InspectionStep != null)
  51. {
  52. if (InspectionStep.normal)
  53. NormalClick();
  54. else
  55. WarningClick();
  56. if (!string.IsNullOrWhiteSpace(InspectionStep.outliers))
  57. {
  58. LabelText_Input.text = InspectionStep.outliers;
  59. mOutliers = InspectionStep.outliers;
  60. }
  61. foreach (var imageIndex in InspectionStep.images)
  62. {
  63. LangChaoMinIo.Instance.getFile(this.GetService<IInspectionService>().InspectionInfo.id , mItemID.ToString(), imageIndex, Texture2D =>
  64. {
  65. });
  66. }
  67. }
  68. }
  69. private float mErrorBtn_go_offset = 319;
  70. public void SetlabelBtnCount(string[] labelList)
  71. {
  72. foreach (string label in labelList)
  73. {
  74. GameObject go = Instantiate(mErrorBtn_go, mErrorBtn_go.transform.parent);
  75. go.GetComponentInChildren<TMP_Text>().text = label;
  76. go.name = label;
  77. Vector3 v3 = mErrorBtn_go.transform.localPosition;
  78. v3.x += mErrorBtn_go_offset;
  79. go.transform.localPosition = v3;
  80. go.SetActive(true);
  81. go.GetComponent<Button>().onClick.AddListener(() =>
  82. {
  83. LabelText_Input.text += go.name;
  84. mOutliers = LabelText_Input.text;
  85. });
  86. }
  87. }
  88. public void SetLabel(string Label)
  89. {
  90. mOutliers = Label;
  91. }
  92. private void NormalClick()
  93. {
  94. NormalBG1_go.SetActive(true);
  95. NormalBG2_go.SetActive(false);
  96. WarningBG1_go.SetActive(false);
  97. WarningBG2_go.SetActive(true);
  98. NormalPanel_go.SetActive(true);
  99. WarningPanel_go.SetActive(false);
  100. mNormal = true;
  101. }
  102. private void WarningClick()
  103. {
  104. NormalBG1_go.SetActive(false);
  105. NormalBG2_go.SetActive(true);
  106. WarningBG1_go.SetActive(true);
  107. WarningBG2_go.SetActive(false);
  108. NormalPanel_go.SetActive(false);
  109. WarningPanel_go.SetActive(true);
  110. mNormal = false;
  111. }
  112. }