You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRDebugger/Scripts/UI/Controls/Data/BoolControl.cs

45 lines
1022 B
C#

3 months ago
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using UnityEngine.UI;
public class BoolControl : DataBoundControl
{
[RequiredField] public Text Title;
[RequiredField] public Toggle Toggle;
protected override void Start()
{
base.Start();
Toggle.onValueChanged.AddListener(ToggleOnValueChanged);
}
private void ToggleOnValueChanged(bool isOn)
{
UpdateValue(isOn);
}
protected override void OnBind(string propertyName, Type t)
{
base.OnBind(propertyName, t);
Title.text = propertyName;
Toggle.interactable = !IsReadOnly;
}
protected override void OnValueUpdated(object newValue)
{
var value = (bool) newValue;
Toggle.isOn = value;
}
public override bool CanBind(Type type, bool isReadOnly)
{
return type == typeof (bool);
}
}
}