DianLiItem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. string zong = srd.zonggonglv.ToString("F2");
  24. string shangridl = srd.shangridl.ToString("F2");
  25. if (zong.Length > 5)
  26. {
  27. zgl.text = zong.Substring(0, 5) + "kW";
  28. }
  29. if (shangridl.Length > 5)
  30. {
  31. srdl.text = shangridl.Substring(0, 5) + "kWh";
  32. }
  33. if(index==0)
  34. {
  35. choose(true);
  36. }
  37. }
  38. public void choose(bool b)
  39. {
  40. if(b)
  41. {
  42. for (int i = 0; i < jiLongItems.Count; i++)
  43. {
  44. try
  45. {
  46. Destroy(jiLongItems[i].gameObject);
  47. }
  48. catch
  49. {
  50. }
  51. }
  52. jiLongItems = new List<JiLongItem>();
  53. DataManager.Instance.GetJL(this.srd.id, (data) =>
  54. {
  55. for (int i = 0; i < data.Count; i++)
  56. {
  57. JiLongItem fz;
  58. if (data[i].jiguilist.Count > 2)
  59. {
  60. fz = GameObject.Instantiate(item2, item2.transform.parent);
  61. }
  62. else
  63. {
  64. fz = GameObject.Instantiate(item1, item1.transform.parent);
  65. }
  66. fz.gameObject.SetActive(true);
  67. fz.updateData(data[i]);
  68. jiLongItems.Add(fz);
  69. }
  70. });
  71. }
  72. }
  73. }