using UnityEngine.UI; namespace UnityEngine.Rendering.UI { /// /// DebugUIHandler for value widgets. /// public class DebugUIHandlerValue : DebugUIHandlerWidget { /// Name of the value field. public Text nameLabel; /// Value of the value field. public Text valueLabel; DebugUI.Value m_Field; /// /// An internal timer used by the value widget to determine when to refresh the displayed value. /// protected internal float m_Timer; static readonly Color k_ZeroColor = Color.gray; /// /// OnEnable implementation. /// protected override void OnEnable() { m_Timer = 0f; } internal override void SetWidget(DebugUI.Widget widget) { base.SetWidget(widget); m_Field = CastWidget(); nameLabel.text = m_Field.displayName; } /// /// OnSelection implementation. /// /// True if the selection wrapped around. /// Previous widget. /// True if the selection is allowed. public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous) { nameLabel.color = colorSelected; valueLabel.color = colorSelected; return true; } /// /// OnDeselection implementation. /// public override void OnDeselection() { nameLabel.color = colorDefault; valueLabel.color = colorDefault; } void Update() { if (m_Timer >= m_Field.refreshRate) { var value = m_Field.GetValue(); valueLabel.text = m_Field.FormatString(value); // De-emphasize zero values by switching to dark gray color if (value is float) valueLabel.color = (float)value == 0f ? k_ZeroColor : colorDefault; m_Timer -= m_Field.refreshRate; } m_Timer += Time.deltaTime; } } }