namespace Unity.VisualScripting
{
///
/// Toggles between two values with on and off triggers.
///
[UnitCategory("Control")]
[UnitOrder(19)]
[UnitFooterPorts(ControlInputs = true, ControlOutputs = true)]
public sealed class ToggleValue : Unit, IGraphElementWithData
{
public class Data : IGraphElementData
{
public bool isOn;
}
///
/// Whether the toggle should start in the on state.
///
[Serialize]
[Inspectable]
[UnitHeaderInspectable("Start On")]
[InspectorToggleLeft]
public bool startOn { get; set; } = true;
///
/// Trigger to turn on the toggle.
///
[DoNotSerialize]
[PortLabel("On")]
public ControlInput turnOn { get; private set; }
///
/// Trigger to turn off the toggle.
///
[DoNotSerialize]
[PortLabel("Off")]
public ControlInput turnOff { get; private set; }
///
/// Trigger to toggle the state of the toggle.
///
[DoNotSerialize]
public ControlInput toggle { get; private set; }
///
/// The value to return if the toggle is on.
///
[DoNotSerialize]
public ValueInput onValue { get; private set; }
///
/// The value to return if the toggle is off.
///
[DoNotSerialize]
public ValueInput offValue { get; private set; }
///
/// Triggered when the flow gets turned on.
///
[DoNotSerialize]
public ControlOutput turnedOn { get; private set; }
///
/// Triggered when the flow gets turned off.
///
[DoNotSerialize]
public ControlOutput turnedOff { get; private set; }
///
/// Whether the flow is currently on.
///
[DoNotSerialize]
public ValueOutput isOn { get; private set; }
///
/// The value of the toggle selected depending on the state.
///
[DoNotSerialize]
public ValueOutput value { get; private set; }
protected override void Definition()
{
turnOn = ControlInput(nameof(turnOn), TurnOn);
turnOff = ControlInput(nameof(turnOff), TurnOff);
toggle = ControlInput(nameof(toggle), Toggle);
onValue = ValueInput