DeviceInfo_Item.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Blue;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. using Agora.Rtc.LitJson;
  8. namespace GHZLangChao
  9. {
  10. public class DeviceInfo_Item : AbstractController
  11. {
  12. private DeviceParameters DeviceParameter;
  13. public Transform currentPos;
  14. public DataItem item;
  15. public TMP_Text deviceName;
  16. public TMP_Text type;
  17. public TMP_Text model;
  18. public TMP_Text ip;
  19. [SerializeField] private Button DetailsBtn;
  20. private IQueueSystem mQueueSystem;
  21. private void Start()
  22. {
  23. DetailsBtn.onClick.AddListener(ClickDetails);
  24. }
  25. int i;
  26. public void Init(DeviceParameters DeviceParameter, int i, DataItem item)
  27. {
  28. this.DeviceParameter = DeviceParameter;
  29. this.i = i;
  30. this.item = item;
  31. deviceName.text = DeviceParameter.cabinetNumber;
  32. type.text = DeviceParameter.deviceType;
  33. model.text = DeviceParameter.deviceBrand;
  34. ip.text = DeviceParameter.managementIP;
  35. }
  36. public void InitNull()
  37. {
  38. SettingNull();
  39. }
  40. private void ClickDetails()
  41. {
  42. // DeviceParameter.deviceModel = "NetView400" + i;
  43. // Vector3 currentPos = transform.position; // 为了将详情面板移动到面前
  44. // 从后台获取UI详情
  45. JsonData data = new JsonData();
  46. data["cabinetNumber"] = DeviceParameter.cabinetNumber;
  47. data["u"] = DeviceParameter.u;
  48. // string jsondata = JsonConvert.SerializeObject(data);
  49. Debug.Log(data.ToJson());
  50. StartCoroutine(HttpTool.Instance.SendHttp(HttpActionLang.bladeServer, data.ToJson(), BladeServerCallBack));
  51. // HttpLangChaoTool.Instance.Post(HttpLangChaoAction.bladeServer, jsondata, BladeServerCallBack);
  52. // item.gameObject.SetActive(false);
  53. }
  54. private void SettingNull()
  55. {
  56. DetailsBtn.interactable = false;
  57. transform.GetComponent<Image>().enabled = false;
  58. for (int i = 0; i < transform.childCount; i++)
  59. {
  60. transform.GetChild(i).gameObject.SetActive(false);
  61. }
  62. }
  63. private void BladeServerCallBack(string msg)
  64. {
  65. Debug.Log(msg);
  66. JObject json = JObject.Parse(msg);
  67. if (json["code"].ToString() == "200")
  68. {
  69. string data = json["data"]["list"][0].ToString();
  70. Debug.Log(data);
  71. this.DeviceParameter = JsonConvert.DeserializeObject<DeviceParameters>(data);
  72. Debug.Log(JsonConvert.SerializeObject(this.DeviceParameter));
  73. this.SendCommand(new DeviceDetailsUpdataDataCommand(DeviceParameter, currentPos, item)); // 触发事件,打开面板,更新数据
  74. }
  75. else
  76. {
  77. Debug.LogError(" 请求刀片机详情参数出错 !!! " + HttpActionLang.bladeServer);
  78. }
  79. }
  80. private void OnEnable()
  81. {
  82. if (mQueueSystem == null)
  83. mQueueSystem = this.GetService<IQueueSystem>();
  84. mQueueSystem.Add(gameObject);
  85. }
  86. private void OnDestroy()
  87. {
  88. mQueueSystem.Remove(gameObject);
  89. }
  90. }
  91. }