DeviceInfo_Item.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. private void ClickDetails()
  27. {
  28. DeviceParameter.deviceModel = "NetView400" + i;
  29. // Vector3 currentPos = transform.position; // 为了将详情面板移动到面前
  30. // 从后台获取UI详情
  31. HttpLangChaoTool.Instance.Post(HttpLangChaoAction.bladeServer, "", BladeServerCallBack);
  32. item.gameObject.SetActive(false);
  33. }
  34. private void BladeServerCallBack(string msg)
  35. {
  36. Debug.Log(msg);
  37. JObject json = JObject.Parse(msg);
  38. if (json["code"].ToString() == "200")
  39. {
  40. string data = json["data"].ToString();
  41. this.DeviceParameter = JsonConvert.DeserializeObject<DeviceParameters>(data);
  42. this.SendCommand(new DeviceDetailsUpdataDataCommand(DeviceParameter, currentPos, item)); // 触发事件,打开面板,更新数据
  43. }
  44. else
  45. {
  46. Debug.LogError(" 请求刀片机详情参数出错 !!! " + HttpLangChaoAction.bladeServer);
  47. }
  48. }
  49. private void OnEnable()
  50. {
  51. if (mQueueSystem == null)
  52. mQueueSystem = this.GetService<IQueueSystem>();
  53. mQueueSystem.Add(gameObject);
  54. }
  55. private void OnDestroy()
  56. {
  57. mQueueSystem.Remove(gameObject);
  58. }
  59. }
  60. }