2
2
using UnityEngine ;
3
3
using System . Linq ;
4
4
using System ;
5
+ using System . Reflection ;
5
6
using Object = UnityEngine . Object ;
6
7
7
8
namespace Coffee . UIEffects . Editors
@@ -13,6 +14,17 @@ namespace Coffee.UIEffects.Editors
13
14
[ CanEditMultipleObjects ]
14
15
public class UIEffect2Editor : Editor
15
16
{
17
+ private static readonly PropertyInfo s_PiGradient = typeof ( SerializedProperty )
18
+ . GetProperty ( "gradientValue" , BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
19
+
20
+ private static readonly Func < SerializedProperty , Gradient > s_GetGradient =
21
+ ( Func < SerializedProperty , Gradient > ) Delegate . CreateDelegate ( typeof ( Func < SerializedProperty , Gradient > ) ,
22
+ s_PiGradient . GetMethod ) ;
23
+
24
+ private static readonly Action < SerializedProperty , Gradient > s_SetGradient =
25
+ ( Action < SerializedProperty , Gradient > ) Delegate . CreateDelegate ( typeof ( Action < SerializedProperty , Gradient > ) ,
26
+ s_PiGradient . SetMethod ) ;
27
+
16
28
private SerializedProperty _toneFilter ;
17
29
private SerializedProperty _toneIntensity ;
18
30
@@ -162,7 +174,7 @@ public void DrawProperties()
162
174
{
163
175
EditorGUI . indentLevel ++ ;
164
176
EditorGUILayout . PropertyField ( _colorIntensity ) ;
165
- DrawColor ( _colorFilter , _color , prevColorFilter ) ;
177
+ DrawColor ( _colorFilter , _color , prevColorFilter , false ) ;
166
178
EditorGUILayout . PropertyField ( _colorGlow ) ;
167
179
EditorGUI . indentLevel -- ;
168
180
}
@@ -260,7 +272,7 @@ public void DrawProperties()
260
272
}
261
273
262
274
EditorGUILayout . PropertyField ( _shadowColorFilter ) ;
263
- EditorGUILayout . PropertyField ( _shadowColor ) ;
275
+ DrawColorPickerField ( _shadowColor , false ) ;
264
276
EditorGUILayout . PropertyField ( _shadowColorGlow ) ;
265
277
EditorGUILayout . PropertyField ( _shadowFade ) ;
266
278
@@ -286,15 +298,16 @@ public void DrawProperties()
286
298
case GradationMode . HorizontalGradient :
287
299
case GradationMode . VerticalGradient :
288
300
case GradationMode . AngleGradient :
289
- EditorGUILayout . PropertyField ( _gradationGradient ) ;
301
+ DrawGradientField ( _gradationGradient ) ;
290
302
break ;
291
303
default :
292
- EditorGUILayout . PropertyField ( _gradationColor1 ) ;
304
+ DrawColorPickerField ( _gradationColor1 ) ;
293
305
var r = EditorGUILayout . GetControlRect ( ) ;
294
- r . width -= 20 ;
295
- EditorGUI . PropertyField ( r , _gradationColor2 ) ;
306
+ r . width -= 24 ;
307
+ r . height = EditorGUIUtility . singleLineHeight ;
308
+ DrawColorPickerField ( r , _gradationColor2 ) ;
296
309
297
- r . x += r . width ;
310
+ r . x += r . width + 4 ;
298
311
r . width = 20 ;
299
312
// Swap colors
300
313
if ( GUI . Button ( r , EditorGUIUtility . IconContent ( "preaudioloopoff" ) , "iconbutton" ) )
@@ -326,7 +339,48 @@ public void DrawProperties()
326
339
}
327
340
}
328
341
329
- private static void DrawColor ( SerializedProperty filter , SerializedProperty color , ColorFilter prevFilter )
342
+ private static void DrawColorPickerField ( SerializedProperty color , bool showAlpha = true )
343
+ {
344
+ var r = EditorGUILayout . GetControlRect ( ) ;
345
+ r . height = EditorGUIUtility . singleLineHeight ;
346
+ DrawColorPickerField ( r , color , showAlpha ) ;
347
+ }
348
+
349
+ private static void DrawColorPickerField ( Rect rect , SerializedProperty color , bool showAlpha = true )
350
+ {
351
+ var label = EditorGUIUtility . TrTempContent ( color . displayName ) ;
352
+ label . tooltip = color . tooltip ;
353
+ var hdr = UIEffectProjectSettings . useHdrColorPicker ;
354
+ EditorGUI . showMixedValue = color . hasMultipleDifferentValues ;
355
+
356
+ EditorGUI . BeginChangeCheck ( ) ;
357
+ var colorValue = EditorGUI . ColorField ( rect , label , color . colorValue , true , showAlpha , hdr ) ;
358
+ if ( EditorGUI . EndChangeCheck ( ) )
359
+ {
360
+ color . colorValue = colorValue ;
361
+ }
362
+ }
363
+
364
+ private static void DrawGradientField ( SerializedProperty gradient )
365
+ {
366
+ var r = EditorGUILayout . GetControlRect ( ) ;
367
+ r . height = EditorGUIUtility . singleLineHeight ;
368
+
369
+ var label = EditorGUIUtility . TrTempContent ( gradient . displayName ) ;
370
+ label . tooltip = gradient . tooltip ;
371
+ var hdr = UIEffectProjectSettings . useHdrColorPicker ;
372
+ EditorGUI . showMixedValue = gradient . hasMultipleDifferentValues ;
373
+
374
+ EditorGUI . BeginChangeCheck ( ) ;
375
+ var gradientValue = EditorGUI . GradientField ( r , label , s_GetGradient ( gradient ) , hdr ) ;
376
+ if ( EditorGUI . EndChangeCheck ( ) )
377
+ {
378
+ s_SetGradient ( gradient , gradientValue ) ;
379
+ }
380
+ }
381
+
382
+ private static void DrawColor ( SerializedProperty filter , SerializedProperty color , ColorFilter prevFilter ,
383
+ bool showAlpha = true )
330
384
{
331
385
if ( filter . intValue == ( int ) ColorFilter . None )
332
386
{
@@ -361,7 +415,7 @@ private static void DrawColor(SerializedProperty filter, SerializedProperty colo
361
415
color . colorValue = Color . white ;
362
416
}
363
417
364
- EditorGUILayout . PropertyField ( color ) ;
418
+ DrawColorPickerField ( color , showAlpha ) ;
365
419
}
366
420
}
367
421
0 commit comments