Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73cef87

Browse filesBrowse files
author
Adam Sasine
committed
Added SequenceNode
1 parent 6c74787 commit 73cef87
Copy full SHA for 73cef87

4 files changed

+409Lines changed: 409 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Collections.Generic;
2+
3+
namespace BehaviorTree.NET.Nodes.Control
4+
{
5+
public class SequenceNode : ControlNode
6+
{
7+
private int currentRunningIndex;
8+
9+
public SequenceNode(IEnumerable<INode> children)
10+
: base(children)
11+
{
12+
this.currentRunningIndex = 0;
13+
}
14+
15+
public override NodeStatus Tick()
16+
{
17+
for (int i = 0; i < this.Children.Count; i++)
18+
{
19+
var child = this.Children[i];
20+
var status = child.Tick();
21+
switch (status)
22+
{
23+
case NodeStatus.SUCCESS:
24+
continue;
25+
case NodeStatus.FAILURE:
26+
this.Halt();
27+
return status;
28+
case NodeStatus.RUNNING:
29+
if (i != this.currentRunningIndex)
30+
{
31+
// a new child is running, all children after i, up to the previously running child (inclusive) should be halted
32+
for (int j = i + 1; j <= this.currentRunningIndex; j++)
33+
{
34+
this.HaltChild(j);
35+
}
36+
}
37+
38+
this.currentRunningIndex = i;
39+
return status;
40+
}
41+
}
42+
43+
this.Halt();
44+
return NodeStatus.SUCCESS;
45+
}
46+
47+
public override void Halt()
48+
{
49+
this.currentRunningIndex = 0;
50+
base.Halt();
51+
}
52+
}
53+
}
Collapse file

‎Runtime/Nodes/Control/SequenceNode.cs.meta‎

Copy file name to clipboardExpand all lines: Runtime/Nodes/Control/SequenceNode.cs.meta
+11Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.