123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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<RectTransform>();
-
- }
- 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
- {
- /// <summary>
- /// 告警等级
- /// </summary>
- public string level { get; set; }
- /// <summary>
- /// 告警时间
- /// </summary>
- public long times { get; set; }
- /// <summary>
- /// 设备名称
- /// </summary>
- public string deviceName { get; set; }
- /// <summary>
- /// 报警描述
- /// </summary>
- public string describe { get; set; }
- /// <summary>
- /// 持续时间
- /// </summary>
- public string duarationTimer { get; set; }
- }
|