using System;
using UnityEngine.UI;
namespace UnityEngine.Rendering.UI
{
///
/// DebugUIHandler for unsigned integer widget.
///
public class DebugUIHandlerUIntField : DebugUIHandlerWidget
{
/// Name of the indirect uint field.
public Text nameLabel;
/// Value of the indirect uint field.
public Text valueLabel;
DebugUI.UIntField m_Field;
internal override void SetWidget(DebugUI.Widget widget)
{
base.SetWidget(widget);
m_Field = CastWidget();
nameLabel.text = m_Field.displayName;
UpdateValueLabel();
}
///
/// 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;
}
///
/// OnIncrement implementation.
///
/// True if incrementing fast.
public override void OnIncrement(bool fast)
{
ChangeValue(fast, 1);
}
///
/// OnDecrement implementation.
///
/// Trye if decrementing fast.
public override void OnDecrement(bool fast)
{
ChangeValue(fast, -1);
}
void ChangeValue(bool fast, int multiplier)
{
long value = m_Field.GetValue();
if (value == 0 && multiplier < 0)
return;
value += m_Field.incStep * (fast ? m_Field.intStepMult : 1) * multiplier;
m_Field.SetValue((uint)value);
UpdateValueLabel();
}
void UpdateValueLabel()
{
if (valueLabel != null)
valueLabel.text = m_Field.GetValue().ToString("N0");
}
}
}