2525
2626namespace VisualPinball . Unity . VisualScripting . Editor
2727{
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 ;
3232
33- public AttributedEnumInspector ( Metadata metadata ) : base ( metadata ) {
34- }
33+ public AttributedEnumInspector ( Metadata metadata ) : base ( metadata ) {
34+ }
3535
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 ( ) ;
4040
41- metadata . instantiate = true ;
41+ metadata . instantiate = true ;
4242
43- base . Initialize ( ) ;
44- }
43+ base . Initialize ( ) ;
44+ }
4545
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+ }
5050
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 ) ;
5454
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 ) ;
6260
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 ) ;
6563
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+ }
7269
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+ }
7774
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 ( ) ) ;
8178
82- DescriptionAttribute attribute
83- = Attribute . GetCustomAttribute ( field , typeof ( DescriptionAttribute ) )
84- as DescriptionAttribute ;
79+ DescriptionAttribute attribute = Attribute . GetCustomAttribute ( field , typeof ( DescriptionAttribute ) ) as DescriptionAttribute ;
8580
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