Skip to content

Commit 8fc4cbc

Browse files
committed
ctx
1 parent 3dde388 commit 8fc4cbc

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

BehaviourTree/BehaviourContext/ContextRevamped.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,37 @@
22
{
33
internal class ContextBlock
44
{
5-
public TreeBaseNode contextSubject;
5+
public ContextBlock parentBlock;
6+
public TreeBaseNode contextRoot;
7+
8+
public ContextBlock(ContextBlock parentBlock, TreeBaseNode contextRoot)
9+
{
10+
this.parentBlock = parentBlock;
11+
this.contextRoot = contextRoot;
12+
}
613
}
714

815
internal class Context
916
{
10-
private ContextBlock parentBlock;
1117
private ContextBlock currentBlock;
18+
19+
public void SetContextPointer(ContextBlock block)
20+
{
21+
currentBlock = block;
22+
}
23+
24+
public bool Unwind()
25+
{
26+
if (currentBlock.parentBlock == null)
27+
return false;
28+
29+
currentBlock = currentBlock.parentBlock;
30+
return true;
31+
}
32+
33+
public TreeBaseNode GetContextNode()
34+
{
35+
return currentBlock?.contextRoot;
36+
}
1237
}
1338
}

BehaviourTree/Nodes/TreeBaseNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Coffee.BehaviourTree.Context;
2+
using Coffee.BehaviourTree.Ctx;
23
using UnityEngine;
34

45
namespace Coffee.BehaviourTree
@@ -7,6 +8,7 @@ internal abstract class TreeBaseNode : ITreeBehaviourNode
78
{
89
[HideInInspector]
910
public BehaviourTree parentTree;
11+
//public ContextBlock contextBlock;
1012

1113
public enum Result
1214
{

CodeLinks/Services/RuntimeService.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Reflection;
43
using Sirenix.Utilities;
54
using UnityEngine;
@@ -8,9 +7,7 @@ namespace BehaviourGraph.Services
87
{
98
public class RuntimeService
109
{
11-
private readonly CoroutineController controller;
12-
private readonly MonoBehaviour targetCtx;
13-
public readonly Func<ServiceState> executable;
10+
private readonly Func<ServiceState> executable;
1411
public RuntimeService(MethodInfo targetMethod, GameObject targetGameObject)
1512
{
1613
Type declType = targetMethod.DeclaringType;
@@ -21,8 +18,6 @@ public RuntimeService(MethodInfo targetMethod, GameObject targetGameObject)
2118
}
2219

2320
executable = ServiceCreator.CreateServiceFunction(targetMethod, component);
24-
controller = new CoroutineController();
25-
targetCtx = component as MonoBehaviour;
2621
}
2722

2823
public bool Execute()

Examples/ThingyController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public ServiceState ChasePlayer()
9999
[Service]
100100
public ServiceState ColorRed()
101101
{
102+
//Not a compiler error, ;P
102103
img.color = Color.red;
103104
return ServiceState.Complete;
104105
}

0 commit comments

Comments
 (0)