Skip to content

Commit 20a983c

Browse files
committed
Test Manager Reactive Code Works
1 parent f8bb9e4 commit 20a983c

File tree

6 files changed

+92
-9
lines changed

6 files changed

+92
-9
lines changed

Assets/Examples/test2.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ MonoBehaviour:
1818
\ \"Depth\": -1,\r\n \"HasChildren\": true,\r\n \"Name\": \"New Root\",\r\n
1919
\ \"ID\": -1\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Components.Selector\",\r\n
2020
\ \"Depth\": 0,\r\n \"HasChildren\": true,\r\n \"Name\": \"Selector 0\",\r\n
21-
\ \"ID\": 0\r\n },\r\n {\r\n \"MoveSpeed\": 10.0,\r\n \"UpdatePlayersTickInterval\":
21+
\ \"ID\": 0\r\n },\r\n {\r\n \"MoveSpeed\": 6.0,\r\n \"UpdatePlayersTickInterval\":
2222
6,\r\n \"UpdateSelfPositionTickInterval\": 3,\r\n \"ElementType\": \"Assets.Scripts.AI.Nodes.MoveEnemyIfCloseToPlayer\",\r\n
2323
\ \"Depth\": 1,\r\n \"HasChildren\": false,\r\n \"Name\": \"MoveEnemyIfCloseToPlayer
2424
3\",\r\n \"ID\": 3\r\n },\r\n {\r\n \"ElementType\": \"Assets.Scripts.AI.Decorators.Inverter\",\r\n

Assets/Scripts/AI/BehaviorManager.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Newtonsoft.Json;
77
using System.ComponentModel;
88
using UniRx.Triggers;
9+
using UniRx;
910

1011
namespace Assets.Scripts.AI
1112
{
@@ -78,16 +79,31 @@ public void Reinitialize()
7879
IEnumerator Start()
7980
{
8081
WaitForSeconds wfs = new WaitForSeconds(SecondsBetweenTicks);
81-
82+
8283
Debug.Log("Starting ticks on Runner: \n\t" + Runner.ToString());
83-
yield return Runner.Tick();
84-
while (Runner.CurrentState.Equals(BehaviorState.Running) && (TimesToTick != 0))
84+
var behaviors = Observable.EveryUpdate().DoOnSubscribe(() => Debug.Log("Subscribed!!!")).Subscribe().AddTo(this);
85+
86+
87+
Runner.ObserveEveryValueChanged(x => x.CurrentState).Subscribe(x => Debug.Log(x));
88+
89+
90+
while(TimesToTick > 0)
8591
{
86-
yield return StartCoroutine(Runner.Tick(wfs));
87-
if(TimesToTick > 0) --TimesToTick;
92+
Observable.FromCoroutine(() => Runner.Tick()).Subscribe(xr => Debug.Log("Subscribed to " + xr), xd => Debug.Log("Destroyed " + xd)).AddTo(this);
93+
--TimesToTick;
94+
yield return wfs;
8895
}
96+
97+
98+
99+
yield return null;
100+
101+
//yield return StartCoroutine(Runner.Tick(wfs));
102+
//if (TimesToTick > 0) --TimesToTick;
103+
104+
89105

90-
Debug.Log("All Coroutines Should be DONE now! Ending all to make sure....");
106+
//Debug.Log("All Coroutines Should be DONE now! Ending all to make sure....");
91107
StopAllCoroutines();
92108
}
93109

Assets/Scripts/AI/BehaviorTreeElement.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public BehaviorTreeElement(string name, int depth, int id)
5353
[Newtonsoft.Json.JsonIgnore]
5454
public BehaviorState CurrentState;
5555

56-
57-
5856
public virtual IEnumerator Tick(WaitForSeconds delayStart = null)
5957
{
6058
if (delayStart != null)

Assets/Scripts/AI/ReactiveTEST.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Assets.Scripts.AI.Tree;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using UnityEngine;
8+
9+
namespace Assets.Scripts.AI.ReactiveTEST
10+
{
11+
public class ReactiveBehaviorTreeElement : TreeElement
12+
{
13+
private string _ElementType;
14+
public string ElementType
15+
{
16+
get
17+
{
18+
return _ElementType;
19+
}
20+
21+
set
22+
{
23+
_ElementType = value;
24+
}
25+
}
26+
27+
[Newtonsoft.Json.JsonIgnore]
28+
[SerializeField]
29+
private BehaviorManager _BehaviorTreeManager;
30+
[Newtonsoft.Json.JsonIgnore]
31+
public BehaviorManager BehaviorTreeManager
32+
{
33+
get
34+
{
35+
return _BehaviorTreeManager;
36+
}
37+
38+
set
39+
{
40+
_BehaviorTreeManager = value;
41+
}
42+
}
43+
44+
45+
}
46+
}

Assets/Scripts/AI/ReactiveTEST/ReactiveBehaviorTreeElement.cs.meta

Lines changed: 13 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)