using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class AIDeviceAlarmItem : MonoBehaviour { public Image alarmImage; public Text alamText; public Text timeText; public Text deviceText; public Text describeText; public Text durationText; public AIDeviceAlarm aIDeviceAlarm; private RectTransform rectTransform; private void OnEnable() { if (rectTransform == null) rectTransform = this.GetComponent(); } private void Update() { if (rectTransform.localPosition.z != 0) rectTransform.localPosition = new Vector3(rectTransform.localPosition.x, rectTransform.localPosition.y, 0); if (rectTransform.localEulerAngles.y != 0) rectTransform.localEulerAngles = new Vector3(rectTransform.localEulerAngles.x, 0, rectTransform.localEulerAngles.z); } public void DataUpdate(AIDeviceAlarm data) { Debug.Log(data.level); this.aIDeviceAlarm = data; switch (data.level) { case "低": alarmImage.color = new Color32(18, 142, 255, 255); alamText.text = "低"; break; case "一般": break; case "中": alarmImage.color = new Color32(255, 123, 58, 255); alamText.text = "中"; break; case "高": alarmImage.color = new Color32(255, 0, 0,255); alamText.text = "高"; break; default: break; } deviceText.text = data.deviceName; describeText.text = data.describe; DateTime timer = UnixTimeStampToDateTime(data.times); string month = timer.Month < 10 ? "0" + timer.Month.ToString() : timer.Month.ToString(); string day = timer.Day < 10 ? "0" + timer.Day.ToString() : timer.Day.ToString(); string hour = timer.Hour < 10 ? "0" + timer.Hour.ToString() : timer.Hour.ToString(); string minute = timer.Minute < 10 ? "0" + timer.Minute.ToString() : timer.Minute.ToString(); string second = timer.Second < 10 ? "0" + timer.Second.ToString() : timer.Second.ToString(); timeText.text = timer.Year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; durationText.text = data.duarationTimer; } // 时间戳转换成时间 // 持续时长转换 // 将Unix时间戳转换为DateTime public DateTime UnixTimeStampToDateTime(long unixTimeStamp) { // string times = unixTimeStamp.ToString() + "000"; // long timestamp = long.Parse(times); // Unix起始时间 // DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.); DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));//获取时间戳 DateTime dt = startTime.AddSeconds(unixTimeStamp); // 将时间戳转换为DateTime return dt; } } public class AIDeviceAlarm { /// /// 告警等级 /// public string level { get; set; } /// /// 告警时间 /// public long times { get; set; } /// /// 设备名称 /// public string deviceName { get; set; } /// /// 报警描述 /// public string describe { get; set; } /// /// 持续时间 /// public string duarationTimer { get; set; } }