Skip to content

Commit a556135

Browse files
committed
Refactored abort self into composite base class
1 parent 304fdf1 commit a556135

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

Assets/FluidBehaviorTree/Scripts/TaskParents/Composites/CompositeBase.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,20 @@ public override void Reset (bool hardReset = false) {
2828

2929
base.Reset(hardReset);
3030
}
31+
32+
protected bool AbortSelf (TaskStatus requiredStatus) {
33+
if (!AbortType.HasFlag(AbortType.Self)
34+
|| ChildIndex <= 0
35+
|| SelfAbortTask == null
36+
|| SelfAbortTask.Update() != requiredStatus) {
37+
return false;
38+
}
39+
40+
children[ChildIndex].End();
41+
Reset();
42+
43+
return true;
44+
45+
}
3146
}
3247
}

Assets/FluidBehaviorTree/Scripts/TaskParents/Composites/Selector.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
namespace Adnc.FluidBT.TaskParents {
44
public class Selector : CompositeBase {
55
protected override TaskStatus OnUpdate () {
6-
if (AbortType.HasFlag(AbortType.Self)
7-
&& ChildIndex > 0
8-
&& SelfAbortTask != null
9-
&& SelfAbortTask.Update() == TaskStatus.Success) {
10-
children[ChildIndex].End();
11-
Reset();
6+
if (AbortSelf(TaskStatus.Success)) {
127
return Update();
138
}
149

Assets/FluidBehaviorTree/Scripts/TaskParents/Composites/Sequence.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
namespace Adnc.FluidBT.TaskParents {
44
public class Sequence : CompositeBase {
55
protected override TaskStatus OnUpdate () {
6-
if (AbortType.HasFlag(AbortType.Self)
7-
&& ChildIndex > 0
8-
&& SelfAbortTask != null
9-
&& SelfAbortTask.Update() == TaskStatus.Failure) {
10-
children[ChildIndex].End();
11-
Reset();
6+
if (AbortSelf(TaskStatus.Failure)) {
127
return TaskStatus.Failure;
138
}
149

0 commit comments

Comments
 (0)