DianLiItem.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using static Manager;
  6. public class DianLiItem : MonoBehaviour
  7. {
  8. public JiLongItem item1;
  9. public JiLongItem item2;
  10. public Text sname;
  11. public Text zgl;
  12. public Text srdl;
  13. public int index;
  14. ServerRoomData srd;
  15. public static List<JiLongItem> jiLongItems = new List<JiLongItem>();
  16. public void updateData(ServerRoomData srd,int i)
  17. {
  18. this.srd = srd;
  19. index = i;
  20. sname.text = srd.name;
  21. zgl.text = srd.zonggonglv.ToString("F2")+"kW";
  22. srdl.text = srd.shangridl.ToString("F2") + "kWh";
  23. if(index==0)
  24. {
  25. choose(true);
  26. }
  27. }
  28. public void choose(bool b)
  29. {
  30. if(b)
  31. {
  32. for (int i = 0; i < jiLongItems.Count; i++)
  33. {
  34. Destroy(jiLongItems[i].gameObject);
  35. }
  36. jiLongItems = new List<JiLongItem>();
  37. DataManager.Instance.GetJL(this.srd.id, (data) =>
  38. {
  39. for (int i = 0; i < data.Count; i++)
  40. {
  41. JiLongItem fz;
  42. if (data[i].jiguilist.Count > 2)
  43. {
  44. fz = GameObject.Instantiate(item2, item2.transform.parent);
  45. }
  46. else
  47. {
  48. fz = GameObject.Instantiate(item1, item1.transform.parent);
  49. }
  50. fz.gameObject.SetActive(true);
  51. fz.updateData(data[i]);
  52. jiLongItems.Add(fz);
  53. }
  54. });
  55. }
  56. }
  57. }