AIDeviceAlarmItem.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class AIDeviceAlarmItem : MonoBehaviour
  7. {
  8. public Image alarmImage;
  9. public Text alamText;
  10. public Text timeText;
  11. public Text deviceText;
  12. public Text describeText;
  13. public Text durationText;
  14. public AIDeviceAlarm aIDeviceAlarm;
  15. private RectTransform rectTransform;
  16. private void OnEnable()
  17. {
  18. if (rectTransform == null)
  19. rectTransform = this.GetComponent<RectTransform>();
  20. }
  21. private void Update()
  22. {
  23. if (rectTransform.localPosition.z != 0)
  24. rectTransform.localPosition = new Vector3(rectTransform.localPosition.x, rectTransform.localPosition.y, 0);
  25. if (rectTransform.localEulerAngles.y != 0)
  26. rectTransform.localEulerAngles = new Vector3(rectTransform.localEulerAngles.x, 0, rectTransform.localEulerAngles.z);
  27. }
  28. public void DataUpdate(AIDeviceAlarm data)
  29. {
  30. Debug.Log(data.level);
  31. this.aIDeviceAlarm = data;
  32. switch (data.level)
  33. {
  34. case "低":
  35. alarmImage.color = new Color32(18, 142, 255, 255);
  36. alamText.text = "低";
  37. break;
  38. case "一般":
  39. break;
  40. case "中":
  41. alarmImage.color = new Color32(255, 123, 58, 255);
  42. alamText.text = "中";
  43. break;
  44. case "高":
  45. alarmImage.color = new Color32(255, 0, 0,255);
  46. alamText.text = "高";
  47. break;
  48. default:
  49. break;
  50. }
  51. deviceText.text = data.deviceName;
  52. describeText.text = data.describe;
  53. DateTime timer = UnixTimeStampToDateTime(data.times);
  54. string month = timer.Month < 10 ? "0" + timer.Month.ToString() : timer.Month.ToString();
  55. string day = timer.Day < 10 ? "0" + timer.Day.ToString() : timer.Day.ToString();
  56. string hour = timer.Hour < 10 ? "0" + timer.Hour.ToString() : timer.Hour.ToString();
  57. string minute = timer.Minute < 10 ? "0" + timer.Minute.ToString() : timer.Minute.ToString();
  58. string second = timer.Second < 10 ? "0" + timer.Second.ToString() : timer.Second.ToString();
  59. timeText.text = timer.Year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
  60. durationText.text = data.duarationTimer;
  61. }
  62. // 时间戳转换成时间
  63. // 持续时长转换
  64. // 将Unix时间戳转换为DateTime
  65. public DateTime UnixTimeStampToDateTime(long unixTimeStamp)
  66. {
  67. // string times = unixTimeStamp.ToString() + "000";
  68. // long timestamp = long.Parse(times);
  69. // Unix起始时间
  70. // DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.);
  71. DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));//获取时间戳
  72. DateTime dt = startTime.AddSeconds(unixTimeStamp);
  73. // 将时间戳转换为DateTime
  74. return dt;
  75. }
  76. }
  77. public class AIDeviceAlarm
  78. {
  79. /// <summary>
  80. /// 告警等级
  81. /// </summary>
  82. public string level { get; set; }
  83. /// <summary>
  84. /// 告警时间
  85. /// </summary>
  86. public long times { get; set; }
  87. /// <summary>
  88. /// 设备名称
  89. /// </summary>
  90. public string deviceName { get; set; }
  91. /// <summary>
  92. /// 报警描述
  93. /// </summary>
  94. public string describe { get; set; }
  95. /// <summary>
  96. /// 持续时间
  97. /// </summary>
  98. public string duarationTimer { get; set; }
  99. }