ShuiWeiHistoryPanel.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class ShuiWeiHistoryPanel : MonoBehaviour
  7. {
  8. private Button closeButton;
  9. public ShuiWeiData currentData;
  10. public GameObject ShuiWeiHistoryItemPrefab;
  11. public Transform historyItemContent;
  12. public List<GameObject> historyItems=new List<GameObject>();
  13. public Text dangqianText;
  14. public Text dangriText;
  15. public Text historyMax;
  16. public Text historyAvg;
  17. public void Init()
  18. {
  19. closeButton = this.transform.Find("CloseButton").GetComponent<Button>();
  20. closeButton.onClick.AddListener(() =>
  21. {
  22. this.gameObject.SetActive(false);
  23. });
  24. dangqianText = this.transform.Find("DangQianZuiGaoShuiWei/value").GetComponent<Text>();
  25. dangriText = this.transform.Find("DangRiZuiGaoShuiWei/value").GetComponent<Text>();
  26. historyMax = this.transform.Find("LiShiZuiGaoShuiWei/value").GetComponent<Text>();
  27. historyAvg = this.transform.Find("LiShiPingJunShuiWei/value").GetComponent<Text>();
  28. historyItemContent = this.transform.Find("GongChengLieBiao/ScrollView/Viewport/Content").GetComponent<Transform>();
  29. }
  30. public void SetData(ShuiWeiData data)
  31. {
  32. for (int i = 0; i < historyItems.Count; i++)
  33. {
  34. Destroy(historyItems[i]);
  35. }
  36. historyItems.Clear();
  37. currentData = data;
  38. dangqianText.text = $"{currentData.datas[0].avgS1} <color=#A5BFE2>mm</color>";
  39. dangriText.text = $"{currentData.datas[0].avgS1} <color=#A5BFE2>mm</color>";
  40. historyMax.text = $"{currentData.datas[0].avgS1} <color=#A5BFE2>mm</color>";
  41. historyAvg.text = $"{currentData.datas[0].avgS1} <color=#A5BFE2>mm</color>";
  42. for (int i = 0; i < currentData.datas.Length; i++)
  43. {
  44. var temp = Instantiate(ShuiWeiHistoryItemPrefab, historyItemContent).GetComponent<ShuiWeiHistoryItem>();
  45. temp.Init();
  46. temp.SetData(currentData.datas[i],i+1);
  47. historyItems.Add(temp.gameObject);
  48. }
  49. }
  50. }