@@ -17,10 +17,12 @@ public class BitmapFontCreatorEditor : EditorWindow
17
17
private Vector2 _mainScrollPos = Vector2 . zero ;
18
18
private int _selectedCharacterSetIndex = 0 ;
19
19
20
+ private static Vector2Int _guessCache ;
21
+
20
22
[ MenuItem ( MenuItemPath ) ]
21
23
public static void ShowWindow ( )
22
24
{
23
- var size = new Vector2 ( 300 , 550 ) ;
25
+ var size = new Vector2 ( 300 , 580 ) ;
24
26
var window = GetWindowWithRect < BitmapFontCreatorEditor > (
25
27
new Rect ( ( Screen . width - size . x ) * 0.5f , ( Screen . height - size . y ) * 0.5f , size . x , size . y ) ,
26
28
false ,
@@ -52,11 +54,18 @@ private void OnGUI()
52
54
_mainScrollPos = GUILayout . BeginScrollView ( _mainScrollPos , false , false , GUIStyle . none , GUI . skin . verticalScrollbar , GUILayout . ExpandHeight ( true ) ) ;
53
55
GUILayout . BeginVertical ( ) ;
54
56
55
- _data . Texture = EditorGUILayout . ObjectField ( UI . Texture , _data . Texture , typeof ( Texture2D ) , false ) as Texture2D ;
56
- _data . Orientation = ( Orientation ) EditorGUILayout . EnumPopup ( UI . Orientation , _data . Orientation ) ;
57
+ DrawTextureField ( ) ;
57
58
58
59
_data . Cols = EditorGUILayout . IntField ( UI . Cols , _data . Cols ) ;
59
60
_data . Rows = EditorGUILayout . IntField ( UI . Rows , _data . Rows ) ;
61
+
62
+ GUILayout . BeginHorizontal ( ) ;
63
+ GUILayout . Space ( EditorGUIUtility . labelWidth ) ;
64
+ if ( GUILayout . Button ( UI . GuessButton ) ) GuessRowsAndCols ( ) ;
65
+ GUILayout . EndHorizontal ( ) ;
66
+
67
+ EditorGUILayout . Space ( ) ;
68
+ _data . Orientation = ( Orientation ) EditorGUILayout . EnumPopup ( UI . Orientation , _data . Orientation ) ;
60
69
_data . AlphaThreshold = EditorGUILayout . Slider ( UI . AlphaThreshold , _data . AlphaThreshold , 0f , 1f ) ;
61
70
_data . Monospaced = EditorGUILayout . Toggle ( UI . Monospaced , _data . Monospaced ) ;
62
71
@@ -82,6 +91,14 @@ private void OnGUI()
82
91
DrawBottomMenu ( ) ;
83
92
}
84
93
94
+ private void DrawTextureField ( )
95
+ {
96
+ EditorGUI . BeginChangeCheck ( ) ;
97
+ _data . Texture = EditorGUILayout . ObjectField ( UI . Texture , _data . Texture , typeof ( Texture2D ) , false ) as Texture2D ;
98
+ if ( EditorGUI . EndChangeCheck ( ) )
99
+ _guessCache = Vector2Int . zero ;
100
+ }
101
+
85
102
private void DrawCharacterSetDropDown ( )
86
103
{
87
104
_selectedCharacterSetIndex = EditorGUILayout . Popup ( UI . CharacterSet , _selectedCharacterSetIndex , CharacterSets . Names ) ;
@@ -140,5 +157,21 @@ private void RollbackSettings()
140
157
var profile = ( BitmapFontCreatorData ) _settings . Profiles . Selected ?? ExecutionData . Default ;
141
158
profile . CopyTo ( _data ) ;
142
159
}
160
+
161
+ private void GuessRowsAndCols ( )
162
+ {
163
+ if ( _data . Texture == null )
164
+ {
165
+ Debug . LogWarning ( "Texture cannot be null" ) ;
166
+ return ;
167
+ }
168
+
169
+ _guessCache = _guessCache . x == 0 || _guessCache . y == 0
170
+ ? BitmapFontCreator . GuessRowsAndCols ( _data . Texture )
171
+ : _guessCache ;
172
+
173
+ _data . Cols = _guessCache . y ;
174
+ _data . Rows = _guessCache . x ;
175
+ }
143
176
}
144
177
}
0 commit comments