1
1
using System . Linq ;
2
2
using CleverCrow . Fluid . BTs . TaskParents ;
3
+ using UnityEditor ;
3
4
using UnityEngine ;
4
5
5
6
namespace CleverCrow . Fluid . BTs . Trees . Editors {
@@ -16,20 +17,21 @@ public class NodePrintController {
16
17
private Texture2D _verticalTop ;
17
18
18
19
private static GuiStyleCollection Styles => BehaviorTreePrinter . SharedStyles ;
20
+ private static Color LineColor => EditorGUIUtility . isProSkin ? Color . white : Color . black ;
19
21
20
22
public NodePrintController ( VisualTask node ) {
21
23
_node = node ;
22
24
_box = node . Box ;
23
25
_divider = node . Divider ;
24
26
_iconMain = new TextureLoader ( _node . Task . IconPath ) ;
25
27
}
26
-
28
+
27
29
public void Print ( bool taskIsActive ) {
28
30
if ( ! ( _node . Task is TaskRoot ) ) PaintVerticalTop ( ) ;
29
31
_faders . Update ( taskIsActive ) ;
30
-
32
+
31
33
PaintBody ( ) ;
32
-
34
+
33
35
if ( _node . Children . Count > 0 ) {
34
36
PaintDivider ( ) ;
35
37
PaintVerticalBottom ( ) ;
@@ -38,23 +40,23 @@ public void Print (bool taskIsActive) {
38
40
39
41
private void PaintBody ( ) {
40
42
var prevBackgroundColor = GUI . backgroundColor ;
41
-
43
+
42
44
var rect = new Rect (
43
- _box . GlobalPositionX + _box . PaddingX ,
45
+ _box . GlobalPositionX + _box . PaddingX ,
44
46
_box . GlobalPositionY + _box . PaddingY ,
45
- _box . Width - _box . PaddingX ,
47
+ _box . Width - _box . PaddingX ,
46
48
_box . Height - _box . PaddingY ) ;
47
49
48
50
if ( _node . Task . HasBeenActive ) {
49
51
GUI . backgroundColor = _faders . BackgroundFader . CurrentColor ;
50
52
GUI . Box ( rect , GUIContent . none , Styles . BoxActive . Style ) ;
51
53
GUI . backgroundColor = prevBackgroundColor ;
52
-
54
+
53
55
PrintLastStatus ( rect ) ;
54
56
} else {
55
57
GUI . Box ( rect , GUIContent . none , Styles . BoxInactive . Style ) ;
56
58
}
57
-
59
+
58
60
PrintIcon ( ) ;
59
61
60
62
Styles . Title . normal . textColor = _faders . TextFader . CurrentColor ;
@@ -87,57 +89,57 @@ private void PrintIcon () {
87
89
88
90
private void PaintDivider ( ) {
89
91
const int graphicSizeIncrease = 5 ;
90
-
92
+
91
93
if ( _dividerGraphic == null ) {
92
94
_dividerGraphic = CreateTexture (
93
- ( int ) _divider . Width + graphicSizeIncrease ,
94
- 1 ,
95
- Color . black ) ;
95
+ ( int ) _divider . Width + graphicSizeIncrease ,
96
+ 1 ,
97
+ LineColor ) ;
96
98
}
97
99
98
100
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 ,
101
102
_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
+
105
107
GUI . Label ( position , _dividerGraphic ) ;
106
108
}
107
109
108
110
private void PaintVerticalBottom ( ) {
109
111
if ( _verticalBottom == null ) {
110
- _verticalBottom = CreateTexture ( 1 , ( int ) _box . PaddingY , Color . black ) ;
112
+ _verticalBottom = CreateTexture ( 1 , ( int ) _box . PaddingY , LineColor ) ;
111
113
}
112
114
113
115
var position = new Rect (
114
- _box . GlobalPositionX + _node . Width / 2 + _box . PaddingX - 2 ,
116
+ _box . GlobalPositionX + _node . Width / 2 + _box . PaddingX - 2 ,
115
117
_box . GlobalPositionY + _node . Height + _box . PaddingY - 1 ,
116
- 100 ,
117
- _box . PaddingY - 1 ) ;
118
-
118
+ 100 ,
119
+ _box . PaddingY ) ;
120
+
119
121
GUI . Label ( position , _verticalBottom ) ;
120
122
}
121
-
123
+
122
124
private void PaintVerticalTop ( ) {
123
125
if ( _verticalTop == null ) {
124
- _verticalTop = CreateTexture ( 1 , Mathf . RoundToInt ( _box . PaddingY / 2 ) , Color . black ) ;
126
+ _verticalTop = CreateTexture ( 1 , Mathf . RoundToInt ( _box . PaddingY / 2 ) , LineColor ) ;
125
127
}
126
128
127
129
var position = new Rect (
128
- _box . GlobalPositionX + _node . Width / 2 + _box . PaddingX - 2 ,
130
+ _box . GlobalPositionX + _node . Width / 2 + _box . PaddingX - 2 ,
129
131
_box . GlobalPositionY + _box . PaddingY / 2 ,
130
- 100 ,
131
- 10 ) ;
132
-
132
+ 100 ,
133
+ _box . PaddingY / 2 ) ;
134
+
133
135
GUI . Label ( position , _verticalTop ) ;
134
136
}
135
-
137
+
136
138
private static Texture2D CreateTexture ( int width , int height , Color color ) {
137
139
var texture = new Texture2D ( width , height , TextureFormat . ARGB32 , false ) ;
138
140
texture . SetPixels ( Enumerable . Repeat ( color , width * height ) . ToArray ( ) ) ;
139
141
texture . Apply ( ) ;
140
-
142
+
141
143
return texture ;
142
144
}
143
145
}
0 commit comments