DianLiItem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. zgl.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. for (int i = 0; i < this.srd.jilonglist.Count; i++)
  38. {
  39. JiLongItem fz;
  40. if (this.srd.jilonglist[i].jiguilist.Count>2)
  41. {
  42. fz= GameObject.Instantiate(item2,item2.transform.parent);
  43. }
  44. else
  45. {
  46. fz = GameObject.Instantiate(item1, item1.transform.parent);
  47. }
  48. fz.gameObject.SetActive(true);
  49. fz.updateData(this.srd.jilonglist[i]);
  50. jiLongItems.Add(fz);
  51. }
  52. }
  53. }
  54. }