25
25
26
26
namespace VisualPinball . Unity . VisualScripting . Editor
27
27
{
28
- public abstract class AttributedEnumInspector < TEnum > : Inspector
29
- {
30
- private List < TEnum > Enums ;
31
- private string [ ] EnumDescriptions ;
28
+ public abstract class AttributedEnumInspector < TEnum > : Inspector
29
+ {
30
+ private List < TEnum > Enums ;
31
+ private string [ ] EnumDescriptions ;
32
32
33
- public AttributedEnumInspector ( Metadata metadata ) : base ( metadata ) {
34
- }
33
+ public AttributedEnumInspector ( Metadata metadata ) : base ( metadata ) {
34
+ }
35
35
36
- public override void Initialize ( )
37
- {
38
- Enums = Enum . GetValues ( typeof ( TEnum ) ) . Cast < TEnum > ( ) . ToList ( ) ;
39
- EnumDescriptions = Enum . GetValues ( typeof ( TEnum ) ) . Cast < TEnum > ( ) . Select ( x => GetEnumDescription ( x ) ) . ToArray ( ) ;
36
+ public override void Initialize ( )
37
+ {
38
+ Enums = Enum . GetValues ( typeof ( TEnum ) ) . Cast < TEnum > ( ) . ToList ( ) ;
39
+ EnumDescriptions = Enum . GetValues ( typeof ( TEnum ) ) . Cast < TEnum > ( ) . Select ( x => GetEnumDescription ( x ) ) . ToArray ( ) ;
40
40
41
- metadata . instantiate = true ;
41
+ metadata . instantiate = true ;
42
42
43
- base . Initialize ( ) ;
44
- }
43
+ base . Initialize ( ) ;
44
+ }
45
45
46
- protected override float GetHeight ( float width , GUIContent label )
47
- {
48
- return HeightWithLabel ( metadata , width , EditorGUIUtility . singleLineHeight , label ) ;
49
- }
46
+ protected override float GetHeight ( float width , GUIContent label )
47
+ {
48
+ return HeightWithLabel ( metadata , width , EditorGUIUtility . singleLineHeight , label ) ;
49
+ }
50
50
51
- protected override void OnGUI ( Rect position , GUIContent label )
52
- {
53
- position = BeginLabeledBlock ( metadata , position , label ) ;
51
+ protected override void OnGUI ( Rect position , GUIContent label )
52
+ {
53
+ position = BeginLabeledBlock ( metadata , position , label ) ;
54
54
55
- var fieldPosition = new Rect
56
- (
57
- position . x ,
58
- position . y ,
59
- position . width ,
60
- EditorGUIUtility . singleLineHeight
61
- ) ;
55
+ var fieldPosition = new Rect (
56
+ position . x ,
57
+ position . y ,
58
+ position . width ,
59
+ EditorGUIUtility . singleLineHeight ) ;
62
60
63
- var index = Enums . FindIndex ( c => c . Equals ( metadata . value ) ) ;
64
- var newIndex = EditorGUI . Popup ( fieldPosition , index , EnumDescriptions ) ;
61
+ var index = Enums . FindIndex ( c => c . Equals ( metadata . value ) ) ;
62
+ var newIndex = EditorGUI . Popup ( fieldPosition , index , EnumDescriptions ) ;
65
63
66
- if ( EndBlock ( metadata ) )
67
- {
68
- metadata . RecordUndo ( ) ;
69
- metadata . value = Enums [ newIndex ] ;
70
- }
71
- }
64
+ if ( EndBlock ( metadata ) ) {
65
+ metadata . RecordUndo ( ) ;
66
+ metadata . value = Enums [ newIndex ] ;
67
+ }
68
+ }
72
69
73
- public override float GetAdaptiveWidth ( )
74
- {
75
- return Mathf . Max ( 18 , EditorStyles . popup . CalcSize ( new GUIContent ( GetEnumDescription ( ( TEnum ) metadata . value ) ) ) . x ) ;
76
- }
70
+ public override float GetAdaptiveWidth ( )
71
+ {
72
+ return Mathf . Max ( 18 , EditorStyles . popup . CalcSize ( new GUIContent ( GetEnumDescription ( ( TEnum ) metadata . value ) ) ) . x ) ;
73
+ }
77
74
78
- private string GetEnumDescription ( TEnum value )
79
- {
80
- FieldInfo field = value . GetType ( ) . GetField ( value . ToString ( ) ) ;
75
+ private string GetEnumDescription ( TEnum value )
76
+ {
77
+ FieldInfo field = value . GetType ( ) . GetField ( value . ToString ( ) ) ;
81
78
82
- DescriptionAttribute attribute
83
- = Attribute . GetCustomAttribute ( field , typeof ( DescriptionAttribute ) )
84
- as DescriptionAttribute ;
79
+ DescriptionAttribute attribute = Attribute . GetCustomAttribute ( field , typeof ( DescriptionAttribute ) ) as DescriptionAttribute ;
85
80
86
- return ( attribute == null ? value . ToString ( ) : attribute . Description ) . Replace ( '/' , '\u2215 ' ) ;
87
- }
88
- }
89
- }
81
+ return ( attribute == null ? value . ToString ( ) : attribute . Description ) . Replace ( '/' , '\u2215 ' ) ;
82
+ }
83
+ }
84
+ }
0 commit comments