83 lines
2.1 KiB
C#
83 lines
2.1 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using TMPro;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 报警记录列表项组件
|
||
|
|
/// </summary>
|
||
|
|
public class AlarmRecordItem : ScrollableListItem
|
||
|
|
{
|
||
|
|
[Header("报警信息显示")]
|
||
|
|
public TextMeshProUGUI IndexText;
|
||
|
|
public TextMeshProUGUI PriorityText;
|
||
|
|
public TextMeshProUGUI ReasonText;
|
||
|
|
public TextMeshProUGUI TimeText;
|
||
|
|
|
||
|
|
private AlarmEvent _alarmEvent;
|
||
|
|
private int _displayIndex;
|
||
|
|
|
||
|
|
public void Initialize(AlarmEvent alarmEvent, int displayIndex)
|
||
|
|
{
|
||
|
|
_alarmEvent = alarmEvent;
|
||
|
|
_displayIndex = displayIndex;
|
||
|
|
|
||
|
|
// 获取UI组件
|
||
|
|
var tmps = GetComponentsInChildren<TextMeshProUGUI>(true);
|
||
|
|
if (tmps.Length >= 4)
|
||
|
|
{
|
||
|
|
IndexText = tmps[0];
|
||
|
|
PriorityText = tmps[1];
|
||
|
|
ReasonText = tmps[2];
|
||
|
|
TimeText = tmps[3];
|
||
|
|
}
|
||
|
|
|
||
|
|
UpdateDisplay();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateDisplay()
|
||
|
|
{
|
||
|
|
if (_alarmEvent == null) return;
|
||
|
|
|
||
|
|
if (IndexText != null)
|
||
|
|
{
|
||
|
|
IndexText.text = _displayIndex.ToString();
|
||
|
|
}
|
||
|
|
|
||
|
|
if (PriorityText != null)
|
||
|
|
{
|
||
|
|
PriorityText.text = _alarmEvent.Priority.ToString();
|
||
|
|
// 根据优先级设置颜色
|
||
|
|
switch (_alarmEvent.Priority)
|
||
|
|
{
|
||
|
|
case AlarmPriority.High:
|
||
|
|
PriorityText.color = Color.red;
|
||
|
|
break;
|
||
|
|
case AlarmPriority.Medium:
|
||
|
|
PriorityText.color = Color.yellow;
|
||
|
|
break;
|
||
|
|
case AlarmPriority.Low:
|
||
|
|
PriorityText.color = Color.green;
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
PriorityText.color = Color.white;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ReasonText != null)
|
||
|
|
{
|
||
|
|
ReasonText.text = _alarmEvent.Reason;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (TimeText != null)
|
||
|
|
{
|
||
|
|
TimeText.text = _alarmEvent.Time.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void UpdateUI()
|
||
|
|
{
|
||
|
|
UpdateDisplay();
|
||
|
|
}
|
||
|
|
}
|