DeviceInfo_Item.cs 2.9 KB

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