EVERYTHING
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user