Skip to content

Commit 5df47d4

Browse files
committed
Swapped Selector to RX
1 parent 3b24f9c commit 5df47d4

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

Assets/Scripts/AI/BehaviorManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ IEnumerator Start()
8181
{
8282
yield return Runner.Tick()
8383
.ToObservable(true)
84-
.Subscribe(xr => Debug.Log("Starting Tick on Runner"), e => Debug.LogError("Error: " + e)).AddTo(this);
84+
.Subscribe(xr => { }, e => Debug.LogError("Error: " + e)).AddTo(this);
8585
yield return new WaitForSeconds(SecondsBetweenTicks);
8686
if (TimesToTick > 1) --TimesToTick;
8787
}

Assets/Scripts/AI/Components/Selector.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,17 @@ public override IEnumerator Tick(WaitForSeconds delayStart = null)
2626
CurrentState = (BehaviorState.Running);
2727
foreach (BehaviorTreeElement behavior in Children)
2828
{
29-
yield return behavior.Tick().ToObservable().Subscribe(_ =>
30-
{
31-
32-
});
29+
if (CurrentState != BehaviorState.Running) yield break;
3330

34-
if (behavior.CurrentState != BehaviorState.Fail)
31+
yield return behavior.Tick().ToObservable().Subscribe(_ =>
3532
{
36-
this.CurrentState = behavior.CurrentState;
37-
38-
if (this.CurrentState == BehaviorState.Success)
33+
if (behavior.CurrentState == BehaviorState.Success)
3934
{
40-
UnityEngine.Debug.LogError("Selector is success");
41-
//This selector has completed, break out of the operation
42-
yield break;
35+
this.CurrentState = behavior.CurrentState;
36+
return;
4337
}
44-
}
45-
Debug.LogError("Selector is fail");
38+
});
39+
4640
}
4741
//if it gets here, it went through all subbehaviors and had no successes
4842
CurrentState = BehaviorState.Fail;

0 commit comments

Comments
 (0)