using UnityEngine.UI;
namespace UnityEngine.Rendering.UI
{
///
/// DebugUIHandler for toggle widget.
///
public class DebugUIHandlerToggle : DebugUIHandlerWidget
{
/// Name of the toggle.
public Text nameLabel;
/// Value of the toggle.
public Toggle valueToggle;
/// Checkermark image.
public Image checkmarkImage;
internal protected DebugUI.BoolField m_Field;
internal override void SetWidget(DebugUI.Widget widget)
{
base.SetWidget(widget);
m_Field = CastWidget();
nameLabel.text = m_Field.displayName;
UpdateValueLabel();
valueToggle.onValueChanged.AddListener(OnToggleValueChanged);
}
void OnToggleValueChanged(bool value)
{
m_Field.SetValue(value);
}
///
/// 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;
checkmarkImage.color = colorSelected;
return true;
}
///
/// OnDeselection implementation.
///
public override void OnDeselection()
{
nameLabel.color = colorDefault;
checkmarkImage.color = colorDefault;
}
///
/// OnAction implementation.
///
public override void OnAction()
{
bool value = !m_Field.GetValue();
m_Field.SetValue(value);
UpdateValueLabel();
}
///
/// Update the label.
///
internal protected virtual void UpdateValueLabel()
{
if (valueToggle != null)
valueToggle.isOn = m_Field.GetValue();
}
}
}