using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DeviceInfo : MonoBehaviour { public static DeviceInfo Instance; public GameObject infoItem; public Transform infoParent; public Text infoName; public Button CloseBtn; public DeviceList bindInfo; private void Awake() { Instance = this; gameObject.SetActive(false); } private void Start() { CloseBtn.onClick.AddListener(() => { gameObject.SetActive(false); }); } public void OnShow(DeviceList info) { infoName.text = "设备信息"; bindInfo = info; foreach (Transform item in DevicePanelManager.Instance.transform) { if (item.GetComponent() && item.gameObject.activeSelf) { foreach (Transform child in item.GetComponent().BindParent) { if (child.GetComponent()) if (child.GetComponent().BindData.deviceNo == info.deviceNo) { child.GetComponent().Selected.SetActive(true); } else { child.GetComponent().Selected.SetActive(false); } } } } foreach (Transform item in infoParent) { if (item.name != "None") { Destroy(item.gameObject); } } Debug.Log("数据:" + info.timelyData); /* 设备类型code (136-用户信息传输装置, 258-消防水泵状态, 401-消防水箱水位, 302-消防主管网压力, 305-消火栓末端压力, 256-喷淋泵, 301-喷淋主管网压力, 304-喷淋末端压力, 451-正压送风机, 452-防火排烟风机, 453-补风机) */ InfoBase infobase = JsonConvert.DeserializeObject(info.timelyData.ToString()); { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("名称 : " + infobase.deviceName); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("类型 : " + infobase.deviceTypeName); } if (info.deviceType == (int)DeviceType.水泵 || info.deviceType == (int)DeviceType.喷淋泵) { PLInfo pinfo = JsonConvert.DeserializeObject(info.timelyData.ToString()); { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("手自动状态 : " + (pinfo.manualAutomaticState == "0" ? "自动" : "手动")); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("电源状态 : " + (pinfo.powerState == "0" ? "已上电" : "未上电")); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("故障信息 : " + (pinfo.faultStatus == "0" ? "正常" : "故障")); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("启停状态 : " + (pinfo.startStopStatus == "0" ? "停止" : "启动")); } } else if (info.deviceType == (int)DeviceType.水箱) { SXInfo pinfo = JsonConvert.DeserializeObject(info.timelyData.ToString()); { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("水位 : " + pinfo.level); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("预警状态 : " + (pinfo.alarmStatus == "0" ? "正常" : "告警")); } } else if (info.deviceType == (int)DeviceType.消火栓末端 || info.deviceType == (int)DeviceType.消防主管网 || info.deviceType == (int)DeviceType.喷淋末端 || info.deviceType == (int)DeviceType.喷淋主管网) { XHSMDInfo pinfo = JsonConvert.DeserializeObject(info.timelyData.ToString()); { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("压力 : " + pinfo.pressure); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("预警状态 : " + (pinfo.alarmStatus == "0" ? "正常" : "告警")); } } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("楼层 : " + infobase.floor); } { GameObject go = Instantiate(infoItem, infoParent); go.GetComponent().Bind("描述 : " + infobase.descript); } gameObject.SetActive(true); StopAllCoroutines(); StartCoroutine(Refresh()); } IEnumerator Refresh() { DevicePanelManager.Instance.RefreshData(); yield return new WaitForSeconds(5); Debug.Log("刷新"); var data = DevicePanelManager.Instance.GetDeviceData(bindInfo); OnShow(data); } } public class InfoBase { public string deviceType;//类型例如"256" public string devInterface;//"spraypump" public string openProjectId;//"1150" public string deviceTypeName;//"喷淋泵" public string ulogtime;// "1712793073050" public int isOnline;//1 在线状态 public string deviceNo;//"2020000006461" public string deviceName; //"水泵控制柜6461" public string logTime;//"2024-04-11 07:51:12" public string devSystem;// "sprinkler" public string appKey;// "849248896159842305" public string descript;//描述 public string floor;//楼层 } //manualAutomaticState 手自动状态(0 自动,1 手动) TRUE string //powerState 电源状态(0 已上电,1 未上电) TRUE string //faultStatus 故障信息(0 正常,1 故障) TRUE string //startStopStatus 启停状态(0 停止,1 启动) TRUE string public class PLInfo : InfoBase { public string startStopStatus; public string faultStatus; public string powerState; public string manualAutomaticState; } public class XHSMDInfo : InfoBase { public string pressure; public string alarmStatus; } public class SXInfo : InfoBase { public string level; public string alarmStatus; }