Skip to content

Commit 43fd274

Browse files
committed
Started Swap to uniRx
1 parent 82650b5 commit 43fd274

23 files changed

+233
-379
lines changed

Assets/Editor/BehaviorTreeViewEditor/BehaviorExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static void SaveBehaviorAsset(this BehaviorManager behaviorManager, strin
7474

7575
if(behaviorManager != null)
7676
{
77-
behaviorManager.FileName = asset.name;
7877
behaviorManager.Reinitialize();
7978
asset.SecondsBetweenTicks = behaviorManager.SecondsBetweenTicks;
8079
asset.TimesToTick = behaviorManager.TimesToTick;

Assets/Examples/test2.asset

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,20 @@ MonoBehaviour:
1414
TimesToTick: 135
1515
SecondsBetweenTicks: 0.5
1616
RunnerElementsJSON: "[\r\n {\r\n \"NumberOfFailuresBeforeFail\": 0,\r\n \"NumberOfSuccessBeforeSucceed\":
17-
0,\r\n \"ElementType\": \"Assets.Scripts.AI.Components.ParallelRunner\",\r\n
17+
0,\r\n \"Initialized\": false,\r\n \"ElementType\": \"Assets.Scripts.AI.Components.ParallelRunner\",\r\n
1818
\ \"Depth\": -1,\r\n \"HasChildren\": true,\r\n \"Name\": \"New Root\",\r\n
19-
\ \"ID\": -1\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Components.Selector\",\r\n
19+
\ \"ID\": -1\r\n },\r\n {\r\n \"Initialized\": false,\r\n \"ElementType\":
20+
\"Assets.Scripts.AI.Nodes.DebugOutNode\",\r\n \"Depth\": 0,\r\n \"HasChildren\":
21+
false,\r\n \"Name\": \"DebugOutNode 9\",\r\n \"ID\": 9\r\n },\r\n {\r\n
22+
\ \"Initialized\": false,\r\n \"ElementType\": \"Assets.Scripts.AI.Decorators.Inverter\",\r\n
23+
\ \"Depth\": 0,\r\n \"HasChildren\": true,\r\n \"Name\": \"Inverter 4\",\r\n
24+
\ \"ID\": 4\r\n },\r\n {\r\n \"Initialized\": false,\r\n \"ElementType\":
25+
\"Assets.Scripts.AI.Nodes.DebugOutNode\",\r\n \"Depth\": 1,\r\n \"HasChildren\":
26+
false,\r\n \"Name\": \"DebugOutNode 2\",\r\n \"ID\": 2\r\n },\r\n {\r\n
27+
\ \"Initialized\": false,\r\n \"ElementType\": \"Assets.Scripts.AI.Components.Selector\",\r\n
2028
\ \"Depth\": 0,\r\n \"HasChildren\": true,\r\n \"Name\": \"Selector 0\",\r\n
2129
\ \"ID\": 0\r\n },\r\n {\r\n \"MoveSpeed\": 6.0,\r\n \"UpdatePlayersTickInterval\":
22-
6,\r\n \"UpdateSelfPositionTickInterval\": 3,\r\n \"ElementType\": \"Assets.Scripts.AI.Nodes.MoveEnemyIfCloseToPlayer\",\r\n
30+
6,\r\n \"UpdateSelfPositionTickInterval\": 3,\r\n \"Initialized\": false,\r\n
31+
\ \"ElementType\": \"Assets.Scripts.AI.Nodes.MoveEnemyIfCloseToPlayer\",\r\n
2332
\ \"Depth\": 1,\r\n \"HasChildren\": false,\r\n \"Name\": \"MoveEnemyIfCloseToPlayer
24-
3\",\r\n \"ID\": 3\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Decorators.Inverter\",\r\n
25-
\ \"Depth\": 1,\r\n \"HasChildren\": true,\r\n \"Name\": \"Inverter 4\",\r\n
26-
\ \"ID\": 4\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Decorators.Inverter\",\r\n
27-
\ \"Depth\": 2,\r\n \"HasChildren\": true,\r\n \"Name\": \"Inverter 8\",\r\n
28-
\ \"ID\": 8\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Components.Sequencer\",\r\n
29-
\ \"Depth\": 3,\r\n \"HasChildren\": true,\r\n \"Name\": \"Sequencer 5\",\r\n
30-
\ \"ID\": 5\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Decorators.Inverter\",\r\n
31-
\ \"Depth\": 4,\r\n \"HasChildren\": true,\r\n \"Name\": \"Inverter 1\",\r\n
32-
\ \"ID\": 1\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Nodes.DebugOutNode\",\r\n
33-
\ \"Depth\": 5,\r\n \"HasChildren\": false,\r\n \"Name\": \"DebugOutNode
34-
2\",\r\n \"ID\": 2\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Nodes.DebugOutNode\",\r\n
35-
\ \"Depth\": 4,\r\n \"HasChildren\": false,\r\n \"Name\": \"DebugOutNode
36-
7\",\r\n \"ID\": 7\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Nodes.DebugOutNode\",\r\n
37-
\ \"Depth\": 4,\r\n \"HasChildren\": false,\r\n \"Name\": \"DebugOutNode
38-
6\",\r\n \"ID\": 6\r\n }\r\n]"
33+
3\",\r\n \"ID\": 3\r\n }\r\n]"

Assets/Scripts/AI/BehaviorManager.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Assets.Scripts.AI
1212
{
1313
public class BehaviorManager : MonoBehaviour
1414
{
15-
public string FileName = "";
1615
/// <summary>
1716
/// The file to actually save/load to/from.
1817
/// </summary>
@@ -26,7 +25,7 @@ public class BehaviorManager : MonoBehaviour
2625
/// </summary>
2726
[SerializeField]
2827
[Description("Seconds between every tick. At 0 this will tick every frame")]
29-
public double SecondsBetweenTicks = 0.1f;
28+
public float SecondsBetweenTicks = 0.1f;
3029

3130
/// <summary>
3231
/// Number of times to tick the full trees. Set to a negative number to make an infinitely running behavior tree.
@@ -68,7 +67,7 @@ public void Reinitialize()
6867
initialized = true;
6968
}
7069

71-
//TODO: Add ILogger *(perhaps Observer pattern? This is our "singleton")*
70+
//TODO: Add ILogger *(perhaps Observer pattern?)*
7271
//Dispatch messages to observed classes and receive that information here...
7372
//How to store? List? Dictionary? My face? Cat Pictures?
7473

@@ -78,10 +77,14 @@ public void Reinitialize()
7877
/// <returns></returns>
7978
IEnumerator Start()
8079
{
81-
while(TimesToTick-- > 0)
80+
while(TimesToTick != 0)
81+
{
8282
yield return Runner.Tick()
83-
.ToObservable()
84-
.Subscribe(xr => Debug.Log("OnNxt called " + xr), xd => Debug.Log("Destroyed " + xd)).AddTo(this);
83+
.ToObservable(true)
84+
.Subscribe(xr => Debug.Log("Starting Tick on Runner"), e => Debug.LogError("Error: " + e)).AddTo(this);
85+
yield return new WaitForSeconds(SecondsBetweenTicks);
86+
if (TimesToTick > 1) --TimesToTick;
87+
}
8588
}
8689

8790
/// <summary>

Assets/Scripts/AI/BehaviorTreeElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ public virtual void Initialize()
7171

7272
foreach(var ch in allChildrenToRun)
7373
{
74+
//TODO: will be changed to an actual debugger instead of just unity logs. Issue #3
7475
ch.ObserveEveryValueChanged(x => x.CurrentState).Subscribe(x => Debug.Log(ElementType + " state changed: " + x));
7576
}
7677

7778
Initialized = true;
7879
}
7980

80-
8181
public override string ToString()
8282
{
8383
var depthPad = "";

Assets/Scripts/AI/BehaviorTreeManagerAsset.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Assets.Scripts.AI
1212
public class BehaviorTreeManagerAsset : ScriptableObject
1313
{
1414
public int TimesToTick;
15-
public double SecondsBetweenTicks = 10;
15+
public float SecondsBetweenTicks = 0.1f;
1616

1717
public string RunnerElementsJSON;
1818
}

Assets/Scripts/AI/BehaviorTrees.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

Assets/Scripts/AI/BehaviorTrees/MEow.asset

Lines changed: 0 additions & 80 deletions
This file was deleted.

Assets/Scripts/AI/BehaviorTrees/MEow.asset.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

Assets/Scripts/AI/BehaviorTrees/New BehaviorTreeAsset 3.asset

Lines changed: 0 additions & 34 deletions
This file was deleted.

Assets/Scripts/AI/BehaviorTrees/New BehaviorTreeAsset 3.asset.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)