27 lines
529 B
C#
27 lines
529 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[DisallowMultipleComponent]
|
|
public sealed class ToggleBehavior : NodeBehavior
|
|
{
|
|
private bool state;
|
|
|
|
private void Start()
|
|
{
|
|
if (base.IsAuthoritative)
|
|
{
|
|
SetOutputValueIfChanged("On", BSValue.FromBool(state));
|
|
}
|
|
}
|
|
|
|
public override void OnRun(string inputPortName)
|
|
{
|
|
if (base.IsAuthoritative && string.Equals(inputPortName, "Toggle", StringComparison.Ordinal))
|
|
{
|
|
state = !state;
|
|
SetOutputValueIfChanged("On", BSValue.FromBool(state));
|
|
TriggerOutput("Toggled");
|
|
}
|
|
}
|
|
}
|