Skip to content

Commit 9fb50d0

Browse files
authored
Merge pull request #103 from ashblue/feature/keep-visualizer-alive-on-pause
feat(visualizer): pausing the game now keeps active node highlighting
2 parents a97f7c0 + b031653 commit 9fb50d0

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

‎Assets/com.fluid.behavior-tree/Editor/BehaviorTree/BehaviorTreeWindow.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private void OnGUI () {
2222
if (!Application.isPlaying) {
2323
ClearView();
2424
}
25-
25+
2626
GUILayout.Label($"Behavior Tree: {_name}", EditorStyles.boldLabel);
2727
_printer?.Print(position.size);
2828
}
@@ -37,5 +37,19 @@ private void Update () {
3737
Repaint();
3838
}
3939
}
40+
41+
void OnEnable() {
42+
EditorApplication.update += OnEditorUpdate;
43+
}
44+
45+
void OnDisable() {
46+
EditorApplication.update -= OnEditorUpdate;
47+
}
48+
49+
private void OnEditorUpdate() {
50+
// Update faders separately so the current state is maintained when the game is paused
51+
if (!EditorApplication.isPaused)
52+
_printer?.UpdateFaders();
53+
}
4054
}
4155
}

‎Assets/com.fluid.behavior-tree/Editor/BehaviorTree/Printer/BehaviorTreePrinter.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ public class BehaviorTreePrinter {
88
private readonly Rect _containerSize;
99

1010
private Vector2 _scrollPosition;
11-
11+
1212
public static StatusIcons StatusIcons { get; private set; }
1313
public static GuiStyleCollection SharedStyles { get; private set; }
1414

1515

1616
public BehaviorTreePrinter (IBehaviorTree tree, Vector2 windowSize) {
1717
StatusIcons = new StatusIcons();
1818
SharedStyles = new GuiStyleCollection();
19-
19+
2020
var container = new GraphContainerVertical();
2121
container.SetGlobalPosition(SCROLL_PADDING, SCROLL_PADDING);
2222
_root = new VisualTask(tree.Root, container);
2323
container.CenterAlignChildren();
24-
25-
_containerSize = new Rect(0, 0,
26-
container.Width + SCROLL_PADDING * 2,
24+
25+
_containerSize = new Rect(0, 0,
26+
container.Width + SCROLL_PADDING * 2,
2727
container.Height + SCROLL_PADDING * 2);
2828

2929
CenterScrollView(windowSize, container);
@@ -37,8 +37,8 @@ private void CenterScrollView (Vector2 windowSize, GraphContainerVertical contai
3737

3838
public void Print (Vector2 windowSize) {
3939
_scrollPosition = GUI.BeginScrollView(
40-
new Rect(0, 0, windowSize.x, windowSize.y),
41-
_scrollPosition,
40+
new Rect(0, 0, windowSize.x, windowSize.y),
41+
_scrollPosition,
4242
_containerSize);
4343
_root.Print();
4444
GUI.EndScrollView();
@@ -47,5 +47,9 @@ public void Print (Vector2 windowSize) {
4747
public void Unbind () {
4848
_root.RecursiveTaskUnbind();
4949
}
50+
51+
public void UpdateFaders () {
52+
_root.UpdateFaders();
53+
}
5054
}
51-
}
55+
}

‎Assets/com.fluid.behavior-tree/Editor/BehaviorTree/Printer/NodePrintController.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public NodePrintController (VisualTask node) {
2828

2929
public void Print (bool taskIsActive) {
3030
if (!(_node.Task is TaskRoot)) PaintVerticalTop();
31-
_faders.Update(taskIsActive);
3231

3332
PaintBody();
3433

@@ -142,5 +141,9 @@ private static Texture2D CreateTexture (int width, int height, Color color) {
142141

143142
return texture;
144143
}
144+
145+
public void SyncFade (bool taskIsActive) {
146+
_faders.Update(taskIsActive);
147+
}
145148
}
146149
}

‎Assets/com.fluid.behavior-tree/Editor/BehaviorTree/Printer/VisualTask.cs

+15-7
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ public class VisualTask {
99

1010
public ITask Task { get; }
1111
public IReadOnlyList<VisualTask> Children => _children;
12-
12+
1313
public float Width { get; } = 70;
1414
public float Height { get; } = 50;
15-
15+
1616
public IGraphBox Box { get; private set; }
1717
public IGraphBox Divider { get; private set; }
1818
public float DividerLeftOffset { get; private set; }
1919

2020
public VisualTask (ITask task, IGraphContainer parentContainer) {
2121
Task = task;
2222
BindTask();
23-
23+
2424
var container = new GraphContainerVertical();
2525

2626
AddBox(container);
@@ -30,13 +30,13 @@ public VisualTask (ITask task, IGraphContainer parentContainer) {
3030
foreach (var child in task.Children) {
3131
_children.Add(new VisualTask(child, childContainer));
3232
}
33-
33+
3434
AddDivider(container, childContainer);
3535
container.AddBox(childContainer);
3636
}
3737

3838
parentContainer.AddBox(container);
39-
39+
4040
_printer = new NodePrintController(this);
4141
}
4242

@@ -46,7 +46,7 @@ private void BindTask () {
4646

4747
public void RecursiveTaskUnbind () {
4848
Task.EditorUtils.EventActive.RemoveListener(UpdateTaskActiveStatus);
49-
49+
5050
foreach (var child in _children) {
5151
child.RecursiveTaskUnbind();
5252
}
@@ -79,11 +79,19 @@ private void AddBox (IGraphContainer parent) {
7979

8080
public void Print () {
8181
_printer.Print(_taskActive);
82-
_taskActive = false;
8382

8483
foreach (var child in _children) {
8584
child.Print();
8685
}
8786
}
87+
88+
public void UpdateFaders () {
89+
_printer.SyncFade(_taskActive);
90+
_taskActive = false;
91+
92+
foreach (var child in _children) {
93+
child.UpdateFaders();
94+
}
95+
}
8896
}
8997
}

0 commit comments

Comments
 (0)
X