Skip to content

Commit 1bb8cac

Browse files
authored
Merge branch 'develop' into all-contributors/add-Ownez
2 parents 2c88df2 + 244a9ed commit 1bb8cac

File tree

3 files changed

+48
-39
lines changed

3 files changed

+48
-39
lines changed

Assets/com.fluid.behavior-tree/Editor/BehaviorTree/Printer/GraphNode/GraphNodePrinter.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
using System.Linq;
22
using CleverCrow.Fluid.BTs.TaskParents;
3+
using UnityEditor;
34
using UnityEngine;
45

56
namespace CleverCrow.Fluid.BTs.Trees.Editors {
67
public interface IGraphNodePrinter {
78
void Print (GraphNode node);
89
}
9-
10+
1011
public class GraphNodePrinter : IGraphNodePrinter {
1112
private Texture2D _verticalBottom;
1213
private Texture2D _verticalTop;
1314

15+
private static Color LineColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
16+
1417
public void Print (GraphNode node) {
1518
var rect = new Rect(node.Position, node.Size);
1619
GUI.Box(rect, node.Task.Name);
17-
20+
1821
PaintVerticalBottom(node, rect);
1922

2023
if (!(node.Task is TaskRoot)) {
@@ -23,15 +26,15 @@ public void Print (GraphNode node) {
2326
}
2427

2528
private void PaintVerticalBottom (GraphNode node, Rect nodeRect) {
26-
if (_verticalBottom == null) _verticalBottom = CreateTexture(1, node.VerticalConnectorBottomHeight, Color.black);
29+
if (_verticalBottom == null) _verticalBottom = CreateTexture(1, node.VerticalConnectorBottomHeight, LineColor);
2730
var verticalBottomRect = new Rect(nodeRect);
2831
verticalBottomRect.x += node.Size.x / 2 - 0.5f;
2932
verticalBottomRect.y += node.Size.y;
3033
GUI.Label(verticalBottomRect, _verticalBottom);
3134
}
3235

3336
private void PaintVerticalTop (GraphNode node, Rect nodeRect) {
34-
if (_verticalTop == null) _verticalTop = CreateTexture(1, node.VerticalConnectorTopHeight, Color.black);
37+
if (_verticalTop == null) _verticalTop = CreateTexture(1, node.VerticalConnectorTopHeight, LineColor);
3538
var verticalTopRect = new Rect(nodeRect);
3639
verticalTopRect.x += node.Size.x / 2 - 0.5f;
3740
verticalTopRect.y -= node.VerticalConnectorTopHeight;
@@ -42,7 +45,7 @@ private Texture2D CreateTexture (int width, int height, Color color) {
4245
var texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
4346
texture.SetPixels(Enumerable.Repeat(color, width * height).ToArray());
4447
texture.Apply();
45-
48+
4649
return texture;
4750
}
4851
}

Assets/com.fluid.behavior-tree/Editor/BehaviorTree/Printer/Graphics/NodeBoxStyle.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ public NodeBoxStyle (Color32 border, Color background) {
1010
texture.SetPixels(1, 1, 17, 17,
1111
Enumerable.Repeat(background, 17 * 17).ToArray());
1212
texture.Apply();
13-
14-
Style = new GUIStyle(GUI.skin.box) {
13+
14+
Style = new GUIStyle {
1515
border = new RectOffset(1, 1, 1, 1),
1616
normal = {
1717
background = texture,
18+
textColor = Color.white,
1819
},
20+
alignment = TextAnchor.MiddleCenter,
21+
fontSize = 12,
22+
padding = new RectOffset(5, 5, 5, 5),
1923
};
2024
}
2125

2226
private static Texture2D CreateTexture (int width, int height, Color color) {
2327
var texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
2428
texture.SetPixels(Enumerable.Repeat(color, width * height).ToArray());
2529
texture.Apply();
26-
30+
2731
return texture;
2832
}
2933
}
30-
}
34+
}

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

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Linq;
22
using CleverCrow.Fluid.BTs.TaskParents;
3+
using UnityEditor;
34
using UnityEngine;
45

56
namespace CleverCrow.Fluid.BTs.Trees.Editors {
@@ -16,20 +17,21 @@ public class NodePrintController {
1617
private Texture2D _verticalTop;
1718

1819
private static GuiStyleCollection Styles => BehaviorTreePrinter.SharedStyles;
20+
private static Color LineColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
1921

2022
public NodePrintController (VisualTask node) {
2123
_node = node;
2224
_box = node.Box;
2325
_divider = node.Divider;
2426
_iconMain = new TextureLoader(_node.Task.IconPath);
2527
}
26-
28+
2729
public void Print (bool taskIsActive) {
2830
if (!(_node.Task is TaskRoot)) PaintVerticalTop();
2931
_faders.Update(taskIsActive);
30-
32+
3133
PaintBody();
32-
34+
3335
if (_node.Children.Count > 0) {
3436
PaintDivider();
3537
PaintVerticalBottom();
@@ -38,23 +40,23 @@ public void Print (bool taskIsActive) {
3840

3941
private void PaintBody () {
4042
var prevBackgroundColor = GUI.backgroundColor;
41-
43+
4244
var rect = new Rect(
43-
_box.GlobalPositionX + _box.PaddingX,
45+
_box.GlobalPositionX + _box.PaddingX,
4446
_box.GlobalPositionY + _box.PaddingY,
45-
_box.Width - _box.PaddingX,
47+
_box.Width - _box.PaddingX,
4648
_box.Height - _box.PaddingY);
4749

4850
if (_node.Task.HasBeenActive) {
4951
GUI.backgroundColor = _faders.BackgroundFader.CurrentColor;
5052
GUI.Box(rect, GUIContent.none, Styles.BoxActive.Style);
5153
GUI.backgroundColor = prevBackgroundColor;
52-
54+
5355
PrintLastStatus(rect);
5456
} else {
5557
GUI.Box(rect, GUIContent.none, Styles.BoxInactive.Style);
5658
}
57-
59+
5860
PrintIcon();
5961

6062
Styles.Title.normal.textColor = _faders.TextFader.CurrentColor;
@@ -87,57 +89,57 @@ private void PrintIcon () {
8789

8890
private void PaintDivider () {
8991
const int graphicSizeIncrease = 5;
90-
92+
9193
if (_dividerGraphic == null) {
9294
_dividerGraphic = CreateTexture(
93-
(int)_divider.Width + graphicSizeIncrease,
94-
1,
95-
Color.black);
95+
(int)_divider.Width + graphicSizeIncrease,
96+
1,
97+
LineColor);
9698
}
9799

98100
var position = new Rect(
99-
_divider.GlobalPositionX + _box.PaddingY / 2 + _node.DividerLeftOffset - 2,
100-
// @TODO Should not need to offset this
101+
_divider.GlobalPositionX + _box.PaddingX / 2 + _node.DividerLeftOffset - 2,
101102
_divider.GlobalPositionY + _box.PaddingY / 2,
102-
_divider.Width + graphicSizeIncrease,
103-
10);
104-
103+
_divider.Width + graphicSizeIncrease,
104+
// @NOTE I have no clue why 3 works here...
105+
3);
106+
105107
GUI.Label(position, _dividerGraphic);
106108
}
107109

108110
private void PaintVerticalBottom () {
109111
if (_verticalBottom == null) {
110-
_verticalBottom = CreateTexture(1, (int)_box.PaddingY, Color.black);
112+
_verticalBottom = CreateTexture(1, (int)_box.PaddingY, LineColor);
111113
}
112114

113115
var position = new Rect(
114-
_box.GlobalPositionX + _node.Width / 2 + _box.PaddingX - 2,
116+
_box.GlobalPositionX + _node.Width / 2 + _box.PaddingX - 2,
115117
_box.GlobalPositionY + _node.Height + _box.PaddingY - 1,
116-
100,
117-
_box.PaddingY - 1);
118-
118+
100,
119+
_box.PaddingY);
120+
119121
GUI.Label(position, _verticalBottom);
120122
}
121-
123+
122124
private void PaintVerticalTop () {
123125
if (_verticalTop == null) {
124-
_verticalTop = CreateTexture(1, Mathf.RoundToInt(_box.PaddingY / 2), Color.black);
126+
_verticalTop = CreateTexture(1, Mathf.RoundToInt(_box.PaddingY / 2), LineColor);
125127
}
126128

127129
var position = new Rect(
128-
_box.GlobalPositionX + _node.Width / 2 + _box.PaddingX - 2,
130+
_box.GlobalPositionX + _node.Width / 2 + _box.PaddingX - 2,
129131
_box.GlobalPositionY + _box.PaddingY / 2,
130-
100,
131-
10);
132-
132+
100,
133+
_box.PaddingY / 2);
134+
133135
GUI.Label(position, _verticalTop);
134136
}
135-
137+
136138
private static Texture2D CreateTexture (int width, int height, Color color) {
137139
var texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
138140
texture.SetPixels(Enumerable.Repeat(color, width * height).ToArray());
139141
texture.Apply();
140-
142+
141143
return texture;
142144
}
143145
}

0 commit comments

Comments
 (0)