AI/ActionSystem/BehaviorTree/Node.cs
namespace HC3;
/// <summary>
/// A node in a <see cref="BehaviorTreeAction"/>.
/// </summary>
public abstract class Node
{
/// <summary>
/// The status of the node.
/// </summary>
public enum Status
{
Running,
Success,
Failure
}
private bool _started;
public Status TickInternal()
{
if ( !_started )
{
OnStart();
_started = true;
}
var result = Tick();
if ( result != Status.Running )
{
_started = false;
OnStop();
}
return result;
}
public abstract Status Tick();
/// <summary>
/// Called once when the node starts ticking.
/// </summary>
protected virtual void OnStart() { }
/// <summary>
/// Called once when the node stops ticking.
/// </summary>
protected virtual void OnStop() { }
/// <summary>
/// Optional UI/debug info for this node.
/// </summary>
public virtual ActionDisplayInfo? GetDisplay() => null;
}