@@ -8,9 +8,12 @@ namespace MToon
8
8
{
9
9
public class MToonInspector : ShaderGUI
10
10
{
11
- private static bool isAdvancedLightingPanelFoldout = false ;
12
- private static MToon . RotationUnit ofUvRotationUnit = MToon . RotationUnit . Rounds ;
11
+ private const float RoundsToDegree = 360f ;
12
+ private const float RoundsToRadian = ( float ) Math . PI * 2f ;
13
13
14
+ private static bool isAdvancedLightingPanelFoldout = false ;
15
+ private static EditorRotationUnit editorRotationUnit = EditorRotationUnit . Rounds ;
16
+
14
17
private MaterialProperty _version ;
15
18
private MaterialProperty _blendMode ;
16
19
private MaterialProperty _bumpMap ;
@@ -318,26 +321,27 @@ private void Draw(MaterialEditor materialEditor, Material[] materials)
318
321
materialEditor . ShaderProperty ( _uvAnimScrollX , "Scroll X (per second)" ) ;
319
322
materialEditor . ShaderProperty ( _uvAnimScrollY , "Scroll Y (per second)" ) ;
320
323
321
- switch ( EditorGUILayout . EnumPopup ( "Rotation Unit" , ofUvRotationUnit ) )
322
324
{
323
- case MToon . RotationUnit . Rounds :
324
- ofUvRotationUnit = MToon . RotationUnit . Rounds ;
325
- break ;
326
- case MToon . RotationUnit . Degrees :
327
- ofUvRotationUnit = MToon . RotationUnit . Degrees ;
328
- break ;
329
- case MToon . RotationUnit . Radians :
330
- ofUvRotationUnit = MToon . RotationUnit . Radians ;
331
- break ;
332
- default :
333
- ofUvRotationUnit = MToon . RotationUnit . Rounds ;
334
- break ;
335
- } ;
336
- var uvRotation = GetUvRotationValue ( ofUvRotationUnit , _uvAnimRotation . floatValue ) ;
337
-
338
- uvRotation = EditorGUILayout . DelayedFloatField ( "Rotation value (per second)" , uvRotation ) ;
339
- _uvAnimRotation . floatValue = GetUvRoundValue ( ofUvRotationUnit , uvRotation ) ;
340
-
325
+ var control = EditorGUILayout . GetControlRect ( hasLabel : true ) ;
326
+ const int popupMargin = 5 ;
327
+ const int popupWidth = 80 ;
328
+
329
+ var floatControl = new Rect ( control ) ;
330
+ floatControl . width -= popupMargin + popupWidth ;
331
+ var popupControl = new Rect ( control ) ;
332
+ popupControl . x = floatControl . x + floatControl . width + popupMargin ;
333
+ popupControl . width = popupWidth ;
334
+
335
+ EditorGUI . BeginChangeCheck ( ) ;
336
+ var inspectorRotationValue = GetInspectorRotationValue ( editorRotationUnit , _uvAnimRotation . floatValue ) ;
337
+ inspectorRotationValue = EditorGUI . FloatField ( floatControl , "Rotation value (per second)" , inspectorRotationValue ) ;
338
+ if ( EditorGUI . EndChangeCheck ( ) )
339
+ {
340
+ materialEditor . RegisterPropertyChangeUndo ( "UvAnimRotationValueChanged" ) ;
341
+ _uvAnimRotation . floatValue = GetRawRotationValue ( editorRotationUnit , inspectorRotationValue ) ;
342
+ }
343
+ editorRotationUnit = ( EditorRotationUnit ) EditorGUI . EnumPopup ( popupControl , editorRotationUnit ) ;
344
+ }
341
345
}
342
346
}
343
347
EditorGUILayout . EndVertical ( ) ;
@@ -422,44 +426,33 @@ private static void TextureWithHdrColor(MaterialEditor materialEditor, string la
422
426
423
427
}
424
428
425
- private float GetUvRoundValue ( MToon . RotationUnit unit , float val )
429
+ private static float GetRawRotationValue ( EditorRotationUnit unit , float inspectorValue )
426
430
{
427
431
switch ( unit )
428
432
{
429
- case MToon . RotationUnit . Rounds :
430
- {
431
- return val ;
432
- }
433
- case MToon . RotationUnit . Degrees :
434
- {
435
- return val / 360.0f ;
436
- }
437
- case MToon . RotationUnit . Radians :
438
- {
439
- return val / ( 2.0f * 3.14159265359f ) ;
440
- }
433
+ case EditorRotationUnit . Rounds :
434
+ return inspectorValue ;
435
+ case EditorRotationUnit . Degrees :
436
+ return inspectorValue / RoundsToDegree ;
437
+ case EditorRotationUnit . Radians :
438
+ return inspectorValue / RoundsToRadian ;
441
439
default :
442
- return val ;
440
+ throw new ArgumentOutOfRangeException ( ) ;
443
441
}
444
442
}
445
- private float GetUvRotationValue ( MToon . RotationUnit unit , float val )
443
+
444
+ private static float GetInspectorRotationValue ( EditorRotationUnit unit , float rawValue )
446
445
{
447
446
switch ( unit )
448
447
{
449
- case MToon . RotationUnit . Rounds :
450
- {
451
- return val ;
452
- }
453
- case MToon . RotationUnit . Degrees :
454
- {
455
- return val * 360.0f ;
456
- }
457
- case MToon . RotationUnit . Radians :
458
- {
459
- return val * ( 2.0f * 3.14159265359f ) ;
460
- }
448
+ case EditorRotationUnit . Rounds :
449
+ return rawValue ;
450
+ case EditorRotationUnit . Degrees :
451
+ return rawValue * RoundsToDegree ;
452
+ case EditorRotationUnit . Radians :
453
+ return rawValue * RoundsToRadian ;
461
454
default :
462
- return val ;
455
+ throw new ArgumentOutOfRangeException ( ) ;
463
456
}
464
457
}
465
458
}
0 commit comments