6
6
7
7
namespace System . Drawing
8
8
{
9
- #if UNITY_EDITOR
10
9
public class Editor
11
10
{
12
11
private static float _width { get ; set ; }
13
12
private static float _nameWidth { get ; set ; }
14
13
private static float _contentWidth { get ; set ; }
15
14
15
+ public static bool WinFormsCompatible { get ; set ; }
16
+
16
17
public static void BeginGroup ( float width )
17
18
{
18
19
_width = width ;
@@ -49,7 +50,7 @@ public static EditorValue<bool> BooleanField(string name, bool value)
49
50
{
50
51
UnityEngine . GUILayout . BeginHorizontal ( ) ;
51
52
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
52
- var boolBuffer = UnityEngine . GUILayout . Toolbar ( value ? 0 : 1 , new string [ ] { "On" , "Off" } , UnityEngine . GUILayout . Width ( _contentWidth ) ) == 0 ? true : false ;
53
+ var boolBuffer = UnityEngine . GUILayout . Toolbar ( value ? 0 : 1 , new string [ ] { "On" , "Off" } , UnityEngine . GUILayout . Width ( _contentWidth - 48 ) ) == 0 ? true : false ;
53
54
UnityEngine . GUILayout . EndHorizontal ( ) ;
54
55
55
56
return new EditorValue < bool > ( boolBuffer , boolBuffer != value ) ;
@@ -71,11 +72,30 @@ public static bool Button(string text, int width)
71
72
{
72
73
return UnityEngine . GUILayout . Button ( text , UnityEngine . GUILayout . Width ( width ) ) ;
73
74
}
74
- public static EditorValue < Color > ColorField ( string name , Color value )
75
+ public static EditorValue < Color > ColorField ( string name , Color value , Action < Color > setColor = null )
75
76
{
76
77
UnityEngine . GUILayout . BeginHorizontal ( ) ;
77
78
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
78
- var colorBuffer = System . Drawing . Color . FromUColor ( UnityEditor . EditorGUILayout . ColorField ( value . ToUColor ( ) , UnityEngine . GUILayout . Width ( _contentWidth ) ) ) ;
79
+ Color colorBuffer = value ;
80
+ if ( WinFormsCompatible )
81
+ {
82
+ if ( Button ( value . ToString ( ) ) )
83
+ {
84
+ ColorPicker colorPicker = new ColorPicker ( ) ;
85
+ ColorPickerForm colorForm = new ColorPickerForm ( colorPicker ) ;
86
+ colorForm . Color = value ;
87
+ colorForm . Show ( ) ;
88
+ colorForm . ColorChanged += ( s , a ) =>
89
+ {
90
+ if ( setColor != null )
91
+ setColor . Invoke ( colorForm . Color ) ;
92
+ } ;
93
+ }
94
+ }
95
+ #if UNITY_EDITOR
96
+ else
97
+ colorBuffer = System . Drawing . Color . FromUColor ( UnityEditor . EditorGUILayout . ColorField ( value . ToUColor ( ) , UnityEngine . GUILayout . Width ( _contentWidth ) ) ) ;
98
+ #endif
79
99
UnityEngine . GUILayout . EndHorizontal ( ) ;
80
100
81
101
return new EditorValue < Color > ( colorBuffer , colorBuffer != value ) ;
@@ -84,14 +104,30 @@ public static EditorValue<Enum> EnumField(string name, Enum value)
84
104
{
85
105
UnityEngine . GUILayout . BeginHorizontal ( ) ;
86
106
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
87
- var enumBuffer = UnityEditor . EditorGUILayout . EnumPopup ( value , UnityEngine . GUILayout . Width ( _contentWidth ) ) ;
107
+ var enumBuffer = value ;
108
+ if ( WinFormsCompatible )
109
+ {
110
+
111
+ }
112
+ #if UNITY_EDITOR
113
+ else
114
+ enumBuffer = UnityEditor . EditorGUILayout . EnumPopup ( value , UnityEngine . GUILayout . Width ( _contentWidth ) ) ;
115
+ #endif
88
116
UnityEngine . GUILayout . EndHorizontal ( ) ;
89
117
90
118
return new EditorValue < Enum > ( enumBuffer , enumBuffer != value ) ;
91
119
}
92
120
public static bool Foldout ( string name , bool value )
93
121
{
94
- return UnityEditor . EditorGUILayout . Foldout ( value , name ) ;
122
+ if ( WinFormsCompatible )
123
+ {
124
+ return Toggle ( name , value ) ;
125
+ }
126
+ #if UNITY_EDITOR
127
+ else
128
+ return UnityEditor . EditorGUILayout . Foldout ( value , name ) ;
129
+ #endif
130
+ return false ;
95
131
}
96
132
public static void Header ( string text )
97
133
{
@@ -121,10 +157,18 @@ public static EditorValue<int[]> IntField(string name, params int[] value)
121
157
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
122
158
123
159
bool changed = false ;
124
- int [ ] intBuffer = new int [ value . Length ] ;
160
+ int [ ] intBuffer = value ;
125
161
for ( int i = 0 ; i < value . Length ; i ++ )
126
162
{
127
- intBuffer [ i ] = UnityEditor . EditorGUILayout . IntField ( value [ i ] , UnityEngine . GUILayout . Width ( _contentWidth / value . Length ) ) ;
163
+ if ( WinFormsCompatible )
164
+ {
165
+ var valueBuffer = UnityEngine . GUILayout . TextField ( value [ i ] . ToString ( ) , UnityEngine . GUILayout . Width ( _contentWidth / value . Length ) ) ;
166
+ int . TryParse ( valueBuffer , out intBuffer [ i ] ) ;
167
+ }
168
+ #if UNITY_EDITOR
169
+ else
170
+ intBuffer [ i ] = UnityEditor . EditorGUILayout . IntField ( value [ i ] , UnityEngine . GUILayout . Width ( _contentWidth / value . Length ) ) ;
171
+ #endif
128
172
if ( intBuffer [ i ] != value [ i ] )
129
173
changed = true ;
130
174
}
@@ -141,7 +185,15 @@ public static void NewLine(int cnt)
141
185
{
142
186
UnityEngine . GUILayout . BeginHorizontal ( ) ;
143
187
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
144
- var objectBuffer = UnityEditor . EditorGUILayout . ObjectField ( value , type , UnityEngine . GUILayout . Width ( _contentWidth ) ) ;
188
+ UnityEngine . Object objectBuffer = value ;
189
+ if ( WinFormsCompatible )
190
+ {
191
+
192
+ }
193
+ #if UNITY_EDITOR
194
+ else
195
+ objectBuffer = UnityEditor . EditorGUILayout . ObjectField ( value , type , UnityEngine . GUILayout . Width ( _contentWidth ) ) ;
196
+ #endif
145
197
UnityEngine . GUILayout . EndHorizontal ( ) ;
146
198
147
199
return new EditorValue < UnityEngine . Object > ( objectBuffer , objectBuffer != value ) ;
@@ -150,7 +202,15 @@ public static EditorValue<int> Popup(string name, int index, string[] values)
150
202
{
151
203
UnityEngine . GUILayout . BeginHorizontal ( ) ;
152
204
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
153
- var intBuffer = UnityEditor . EditorGUILayout . Popup ( index , values , UnityEngine . GUILayout . Width ( _contentWidth - 8 ) ) ;
205
+ int intBuffer = 0 ;
206
+ if ( WinFormsCompatible )
207
+ {
208
+
209
+ }
210
+ #if UNITY_EDITOR
211
+ else
212
+ intBuffer = UnityEditor . EditorGUILayout . Popup ( index , values , UnityEngine . GUILayout . Width ( _contentWidth - 8 ) ) ;
213
+ #endif
154
214
UnityEngine . GUILayout . EndHorizontal ( ) ;
155
215
156
216
return new EditorValue < int > ( intBuffer , intBuffer != index ) ;
@@ -159,7 +219,16 @@ public static EditorValue<float> Slider(string name, float value, float min, flo
159
219
{
160
220
UnityEngine . GUILayout . BeginHorizontal ( ) ;
161
221
UnityEngine . GUILayout . Label ( name + ":" , UnityEngine . GUILayout . Width ( _nameWidth ) ) ;
162
- var floatBuffer = UnityEditor . EditorGUILayout . Slider ( value , min , max , UnityEngine . GUILayout . Width ( _contentWidth - 8 ) ) ;
222
+ float floatBuffer = value ;
223
+ if ( WinFormsCompatible )
224
+ {
225
+ floatBuffer = UnityEngine . GUILayout . HorizontalSlider ( value , min , max , UnityEngine . GUILayout . Width ( _contentWidth - 96 ) ) ;
226
+ UnityEngine . GUILayout . TextField ( floatBuffer . ToString ( ) , UnityEngine . GUILayout . Width ( 32 ) ) ;
227
+ }
228
+ #if UNITY_EDITOR
229
+ else
230
+ floatBuffer = UnityEditor . EditorGUILayout . Slider ( value , min , max , UnityEngine . GUILayout . Width ( _contentWidth - 8 ) ) ;
231
+ #endif
163
232
UnityEngine . GUILayout . EndHorizontal ( ) ;
164
233
165
234
return new EditorValue < float > ( floatBuffer , floatBuffer != value ) ;
@@ -178,7 +247,6 @@ public static bool Toggle(string name, bool value)
178
247
return UnityEngine . GUILayout . Toggle ( value , name , UnityEngine . GUILayout . Width ( _width ) ) ;
179
248
}
180
249
}
181
- #endif
182
250
183
251
public struct EditorValue < T >
184
252
{
0 commit comments