Skip to content

Commit b123f35

Browse files
committed
Removed most debug statements in Rx code
1 parent 648b813 commit b123f35

File tree

8 files changed

+71
-51
lines changed

8 files changed

+71
-51
lines changed

Assets/Red.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_PrefabParentObject: {fileID: 0}
88
m_PrefabInternal: {fileID: 0}
99
m_Name: Red
10-
m_Shader: {fileID: 47, guid: 0000000000000000f000000000000000, type: 0}
10+
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
1111
m_ShaderKeywords: _SPECULARHIGHLIGHTS_OFF
1212
m_LightmapFlags: 4
1313
m_EnableInstancingVariants: 0

Assets/Scripts/AI/BehaviorManager.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BehaviorManager : MonoBehaviour
2828
public float SecondsBetweenTicks = 0.1f;
2929

3030
/// <summary>
31-
/// Number of times to tick the full trees. Set to a negative number to make an infinitely running behavior tree.
31+
/// Number of times to tick the full tree. Set to a negative number to make an infinitely running behavior tree.
3232
/// </summary>
3333
[SerializeField]
3434
[Description("Times to tick this tree before stopping. Negative values indicate infinitely running behavior.")]
@@ -37,7 +37,7 @@ public class BehaviorManager : MonoBehaviour
3737
[Description("Open a list to splice other trees into this tree.")]
3838
public bool spliceNewIntoTree = false;
3939
/// <summary>
40-
/// A list of trees to splice into the current tree. These trees are not directly editable.
40+
/// A list of trees to splice into the current tree. These trees are not directly editable from here.
4141
/// </summary>
4242
[JsonIgnore]
4343
public List<BehaviorTreeManagerAsset> SpliceList;
@@ -67,10 +67,6 @@ public void Reinitialize()
6767
initialized = true;
6868
}
6969

70-
//TODO: Add ILogger *(perhaps Observer pattern?)*
71-
//Dispatch messages to observed classes and receive that information here...
72-
//How to store? List? Dictionary? My face? Cat Pictures?
73-
7470
/// <summary>
7571
/// Ticks on the aggregate ParallelRunner then continues ticking for as long as the runner is in running state
7672
/// </summary>
@@ -81,7 +77,8 @@ IEnumerator Start()
8177
{
8278
yield return Runner.Tick()
8379
.ToObservable(true)
84-
.Subscribe(xr => { }, e => Debug.LogError("Error: " + e)).AddTo(this);
80+
.Subscribe(_ => { }, e => Debug.LogError("Error: " + e))
81+
.AddTo(this);
8582
yield return new WaitForSeconds(SecondsBetweenTicks);
8683
if (TimesToTick > 1) --TimesToTick;
8784
}

Assets/Scripts/AI/BehaviorTreeElement.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public virtual void Initialize()
6161
foreach(var ch in allChildrenToRun)
6262
{
6363
//TODO: will be changed to an actual debugger instead of just unity logs. Issue #3
64+
//Subscribes to updates to state changes from all children
6465
ch.ObserveEveryValueChanged(x => x.CurrentState)
65-
.Subscribe(x => BehaviorLogger.Log(ElementType + " state changed: " + x))
66+
//.Do(x => BehaviorLogger.Log(ElementType + " state changed: " + x))
67+
.Subscribe()
6668
.AddTo(Disposables);
6769
}
6870

Assets/Scripts/AI/Components/ParallelRunner.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,41 @@ public ParallelRunner(string name, int depth, int id)
3535
public override IEnumerator Tick(WaitForSeconds delayStart = null)
3636
{
3737
//Initialize and start tick
38-
base.Tick(delayStart).ToObservable().Subscribe(xb => Debug.Log("Subscribed to ParallelRunner at start (base.tick()"));
39-
CurrentState = (BehaviorState.Running);
38+
base.Tick().ToObservable()
39+
//.Do(_ => BehaviorLogger.Log("Subscribed to ParallelRunner at start (base.tick()"))
40+
.Subscribe();
41+
CurrentState = BehaviorState.Running;
42+
4043
if (Children == null || Children.Count == 0)
4144
{
4245
Debug.LogWarning("Children Null in parallel runner");
43-
CurrentState = (BehaviorState.Fail);
46+
CurrentState = BehaviorState.Fail;
4447
yield break;
4548
}
4649

4750
foreach(var ch in Children)
4851
{
49-
((BehaviorTreeElement)ch).Tick().ToObservable().Subscribe(_ =>
50-
{
51-
Debug.Log("parallel? Num Succeed: " + NumberOfSuccesses.Value);
52-
Debug.Log("parallel? Num Fail: " + NumberOfFailures.Value);
53-
if (NumberOfFailures.Value >= NumberOfFailuresBeforeFail && NumberOfFailuresBeforeFail > 0)
52+
((BehaviorTreeElement)ch).Tick()
53+
.ToObservable()
54+
.Do(_ =>
5455
{
55-
CurrentState = BehaviorState.Fail;
56-
return;
57-
}
56+
//BehaviorLogger.Log(Name + ": Num Succeed: " + NumberOfSuccesses.Value);
57+
//BehaviorLogger.Log(Name + ": Num Fail: " + NumberOfFailures.Value);
58+
if (NumberOfFailures.Value >= NumberOfFailuresBeforeFail && NumberOfFailuresBeforeFail > 0)
59+
{
60+
CurrentState = BehaviorState.Fail;
61+
return;
62+
}
5863

59-
if (NumberOfSuccesses.Value >= NumberOfSuccessBeforeSucceed && NumberOfSuccessBeforeSucceed > 0)
60-
{
61-
CurrentState = BehaviorState.Success;
62-
return;
63-
}
64-
});
64+
if (NumberOfSuccesses.Value >= NumberOfSuccessBeforeSucceed && NumberOfSuccessBeforeSucceed > 0)
65+
{
66+
CurrentState = BehaviorState.Success;
67+
return;
68+
}
69+
})
70+
.Subscribe().AddTo(Disposables);
6571
}
66-
CurrentState = BehaviorState.Success;
72+
if (CurrentState == BehaviorState.Running) CurrentState = BehaviorState.Success;
6773
}
6874

6975
public override void Initialize()
@@ -78,7 +84,7 @@ public override void Initialize()
7884
//TODO: will be changed to an actual debugger instead of just unity logs. Issue #3
7985
ch.ObserveEveryValueChanged(x => x.CurrentState).Subscribe(x =>
8086
{
81-
BehaviorLogger.Warning(ElementType + " state changed: " + x);
87+
//BehaviorLogger.Warning(ElementType + " state changed: " + x);
8288
if (x == BehaviorState.Fail)
8389
{
8490
NumberOfFailures.SetValueAndForceNotify(NumberOfFailures.Value + 1);

Assets/Scripts/AI/Components/Selector.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,30 @@ public Selector(string name, int depth, int id)
2121

2222
public override IEnumerator Tick(WaitForSeconds delayStart = null)
2323
{
24-
base.Tick().ToObservable().Subscribe(xb => Debug.Log("Subscribed to Selector at start (base.tick()"));
24+
base.Tick().ToObservable()
25+
//.Do(_ => BehaviorLogger.Log("Subscribed to Selector at start (base.tick()"))
26+
.Subscribe();
2527

2628
CurrentState = (BehaviorState.Running);
2729
foreach (BehaviorTreeElement behavior in Children)
2830
{
2931
if (CurrentState != BehaviorState.Running) yield break;
3032

31-
yield return behavior.Tick().ToObservable().Subscribe(_ =>
32-
{
33-
if (behavior.CurrentState == BehaviorState.Success)
33+
yield return
34+
behavior.Tick().ToObservable()
35+
.Do(_ =>
3436
{
35-
this.CurrentState = behavior.CurrentState;
36-
return;
37-
}
38-
});
37+
if (behavior.CurrentState == BehaviorState.Success)
38+
{
39+
CurrentState = BehaviorState.Success;
40+
return;
41+
}
42+
})
43+
.Subscribe()
44+
.AddTo(Disposables);
3945
}
4046
//if it gets here, it went through all subbehaviors and had no successes
41-
CurrentState = BehaviorState.Fail;
47+
if (CurrentState == BehaviorState.Running) CurrentState = BehaviorState.Fail;
4248
yield break;
4349
}
4450
}

Assets/Scripts/AI/Components/Sequencer.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,30 @@ public Sequencer(string name, int depth, int id)
1919

2020
public override IEnumerator Tick(WaitForSeconds delayStart = null)
2121
{
22+
base.Tick().ToObservable()
23+
//.Do(_ => BehaviorLogger.Log("Subscribed to Sequencer at start (base.tick()"))
24+
.Subscribe();
25+
2226
yield return delayStart;
2327
CurrentState = (BehaviorState.Running);
2428
foreach (BehaviorTreeElement behavior in Children)
2529
{
2630
if (CurrentState != BehaviorState.Running) yield break;
2731

28-
yield return behavior.Tick().ToObservable().Subscribe(_ =>
29-
{
30-
if (behavior.CurrentState == BehaviorState.Fail)
32+
yield return behavior.Tick().ToObservable()
33+
.Do(_ =>
3134
{
32-
this.CurrentState = BehaviorState.Fail;
33-
return;
34-
}
35-
}).AddTo(Disposables);
35+
if (behavior.CurrentState == BehaviorState.Fail)
36+
{
37+
CurrentState = BehaviorState.Fail;
38+
return;
39+
}
40+
})
41+
.Subscribe()
42+
.AddTo(Disposables);
3643
}
3744
//if it gets here, it went through all subbehaviors and had no failures
38-
CurrentState = BehaviorState.Success;
45+
if (CurrentState == BehaviorState.Running) CurrentState = BehaviorState.Success;
3946
yield break;
4047
}
4148
}

Assets/Scripts/AI/Decorators/Inverter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public Inverter(string name, int depth, int id)
1313

1414
public override IEnumerator Tick(WaitForSeconds delayStart = null)
1515
{
16-
base.Tick(delayStart).ToObservable().Subscribe(xb => Debug.Log("OnNext Inverter at start (base.tick()"));
16+
base.Tick(delayStart).ToObservable()
17+
//.Do(_ => Debug.Log("OnNext Inverter at start (base.tick()"))
18+
.Subscribe();
1719

1820
CurrentState = BehaviorState.Null;
1921
if (Children == null) yield return null;
@@ -22,17 +24,16 @@ public override IEnumerator Tick(WaitForSeconds delayStart = null)
2224

2325
yield return behavior.Tick().ToObservable().Subscribe(_ =>
2426
{
25-
Debug.LogError("Inverting " + behavior);
2627
switch (behavior.CurrentState)
2728
{
2829
case BehaviorState.Fail:
29-
this.CurrentState = BehaviorState.Success;
30+
CurrentState = BehaviorState.Success;
3031
break;
3132
case BehaviorState.Success:
3233
CurrentState = BehaviorState.Fail;
3334
break;
3435
case BehaviorState.Running:
35-
this.CurrentState = BehaviorState.Running;
36+
CurrentState = BehaviorState.Running;
3637
break;
3738
default:
3839
Debug.LogError("Something went wrong in an inverter.");

Assets/Scripts/AI/Nodes/DebugOutNode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ public DebugOutNode(string name, int depth, int id)
1414

1515
public override IEnumerator Tick(WaitForSeconds delayStart = null)
1616
{
17+
CurrentState = BehaviorState.Running; //Forces an update on the state between succeeds.
1718
yield return delayStart;
18-
Debug.Log("BEHAVIOR NODE DOIN THE THANG!");
19-
CurrentState = (BehaviorState.Success);
19+
Debug.Log("Debug Out Node " + Name + " Doing stuff");
20+
CurrentState = BehaviorState.Success;
2021
yield return null;
2122
}
2223
}

0 commit comments

Comments
 (0)