40 lines
824 B
C#
40 lines
824 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[DisallowMultipleComponent]
|
|
public sealed class CounterBehavior : NodeBehavior
|
|
{
|
|
private int count;
|
|
|
|
private void Start()
|
|
{
|
|
if (base.IsAuthoritative)
|
|
{
|
|
SetOutputValueIfChanged("Count", BSValue.FromNumber(count));
|
|
}
|
|
}
|
|
|
|
public override void OnRun(string inputPortName)
|
|
{
|
|
if (!base.IsAuthoritative)
|
|
{
|
|
return;
|
|
}
|
|
if (string.Equals(inputPortName, "Reset", StringComparison.Ordinal))
|
|
{
|
|
count = 0;
|
|
SetOutputValueIfChanged("Count", BSValue.FromNumber(count));
|
|
}
|
|
else if (string.Equals(inputPortName, "In", StringComparison.Ordinal))
|
|
{
|
|
count++;
|
|
SetOutputValueIfChanged("Count", BSValue.FromNumber(count));
|
|
int num = Mathf.Max(1, Mathf.RoundToInt((float)GetInputNumber("Target")));
|
|
if (count >= num)
|
|
{
|
|
TriggerOutput("Reached");
|
|
}
|
|
}
|
|
}
|
|
}
|