add unity behavior tree package & examples
add start of own implementation of a behavior tree
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace DefaultNamespace.BehaviorTree
|
||||
{
|
||||
public class Sequence : Composite
|
||||
{
|
||||
protected int _currentIndex;
|
||||
protected Node _currentNode;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
_currentIndex = 0;
|
||||
_currentNode = _currentIndex >= _nodes.Count ? null : _nodes[_currentIndex];
|
||||
_currentNode?.Start();
|
||||
}
|
||||
|
||||
public override Status Update()
|
||||
{
|
||||
if (_currentNode == null) return Status.Failure;
|
||||
|
||||
Status status = _currentNode.Update();
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case Status.Success:
|
||||
_currentNode.End();
|
||||
_currentIndex++;
|
||||
if (_currentIndex >= _nodes.Count) return Status.Success;
|
||||
_currentNode = _nodes[_currentIndex];
|
||||
_currentNode.Start();
|
||||
return Status.Running;
|
||||
case Status.Failure:
|
||||
_currentNode.End();
|
||||
return Status.Failure;
|
||||
case Status.Running:
|
||||
return Status.Running;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user