68 lines
1.1 KiB
C#
68 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public abstract class GuardedValueNodeBehavior : NodeBehavior
|
|
{
|
|
private bool evaluating;
|
|
|
|
protected virtual void Start()
|
|
{
|
|
RecomputeIfAuthoritative();
|
|
}
|
|
|
|
public override void OnInputValueChanged(string inputPortName, BSValue value)
|
|
{
|
|
RecomputeIfAuthoritative();
|
|
}
|
|
|
|
protected void RecomputeIfAuthoritative()
|
|
{
|
|
if (!base.IsAuthoritative || Node == null)
|
|
{
|
|
return;
|
|
}
|
|
if (evaluating)
|
|
{
|
|
HandleEvaluationLoop();
|
|
return;
|
|
}
|
|
evaluating = true;
|
|
try
|
|
{
|
|
RecomputeCore();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Debug.LogException(exception, this);
|
|
HandleEvaluationLoop();
|
|
}
|
|
finally
|
|
{
|
|
evaluating = false;
|
|
}
|
|
}
|
|
|
|
protected abstract void RecomputeCore();
|
|
|
|
protected virtual void HandleEvaluationLoop()
|
|
{
|
|
ClearAllValueOutputs();
|
|
}
|
|
|
|
protected void ClearAllValueOutputs()
|
|
{
|
|
if (Node == null)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < Node.OutputPorts.Count; i++)
|
|
{
|
|
NodePort nodePort = Node.OutputPorts[i];
|
|
if (nodePort != null && nodePort.Kind == PortKind.Value)
|
|
{
|
|
SetOutputValueIfChanged(nodePort.Name, BSValue.None);
|
|
}
|
|
}
|
|
}
|
|
}
|