using LitJson; using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ModelDataManager : MonoSingleton { public HumitdlyPanel humityObj; public NoisePanel NoiseObj; public OccPanel OccObj; public bool isLoadModel = false; private void Start() { GetPanelState(); } // 获取三个设备的基础状态 public void GetPanelState() { JsonData data = new JsonData(); data["deviceClassification"] = "TEMPERATURE_HUMIDITY"; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/statisticsEquipmentStatus", data.ToJson(), (msg) => { Debug.Log("DGJ ===> TEMPERATURE_HUMIDITY " + msg); if (msg == "Request Timeout") return; JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { string state = data["data"]["alarm"].ToString(); humityObj.state = state; } }); data["deviceClassification"] = "VIBRATE"; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/statisticsEquipmentStatus", data.ToJson(), (msg) => { Debug.Log("DGJ ===> TEMPERATURE_HUMIDITY " + msg); if (msg == "Request Timeout") return; JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { string state = data["data"]["alarm"].ToString(); OccObj.state = state; } }); data["deviceClassification"] = "VOICE"; PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/statisticsEquipmentStatus", data.ToJson(), (msg) => { Debug.Log("DGJ ===> TEMPERATURE_HUMIDITY " + msg); if (msg == "Request Timeout") return; JsonData data = JsonMapper.ToObject(msg); if (data["code"].ToString() == "200") { string state = data["data"]["alarm"].ToString(); NoiseObj.state = state; } }); } /// /// 1. 温湿度 2. 噪声 3. 振动 /// /// /// public void ShowDataObj(int num) { if (isLoadModel == false) return; switch (num) { case 1: humityObj.gameObject.SetActive(true); NoiseObj.gameObject.SetActive(false); OccObj.gameObject.SetActive(false); break; case 2: humityObj.gameObject.SetActive(false); NoiseObj.gameObject.SetActive(true); OccObj.gameObject.SetActive(false); break; case 3: humityObj.gameObject.SetActive(false); NoiseObj.gameObject.SetActive(false); OccObj.gameObject.SetActive(true); break; case -1: humityObj.gameObject.SetActive(false); NoiseObj.gameObject.SetActive(false); OccObj.gameObject.SetActive(false); break; default: break; } } public void SetHumitdlyData(string Msg) { HumitureMqttData humitureData = JsonConvert.DeserializeObject(Msg); humityObj.SetData(humitureData); } public void SetOscData(string Msg) { OscillateMqttData oscillateData = JsonConvert.DeserializeObject(Msg); OccObj.SetData(oscillateData); } public void SetNoiseData(string Msg) { NoiseMqttData Noise = JsonConvert.DeserializeObject(Msg); NoiseObj.SetData(Noise); } } public class HumitureMqttData { public AIDeviceData device { get; set; } public DeviceValueData temperature { get; set; } public DeviceValueData humidity { get; set; } } public class OscillateMqttData { public AIDeviceData device { get; set; } public DeviceValueData disp { get; set; } public DeviceValueData speed { get; set; } public DeviceValueData temp { get; set; } } public class NoiseMqttData { public AIDeviceData device { get; set; } public float value { get; set; } public string unit { get; set; } } public class AIDeviceData { public string deviceCode { get; set; } public string deviceName { get; set; } public string deviceClassification { get; set; } public long unixTimestamp { get; set; } } public class DeviceValueData { public float value { get; set; } public string unit { get; set; } }