@@ -13,52 +13,74 @@ public class AutoAttributeDrawer : PropertyDrawer
13
13
14
14
public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label )
15
15
{
16
- var attr = attribute as AutoAttribute ;
17
-
18
- // Null, so lets assign it
19
- if ( AutoAttributeEditor . AutoRefreshInspector )
20
- AutoAttributeEditor . ApplyAttributeToSerializedProperty ( property , attr ) ;
16
+ try
17
+ {
21
18
22
- var optionalError = AutoAttributeEditor . Validate ( property ) ;
19
+ var attr = attribute as AutoAttribute ;
20
+ // Null, so lets assign it
21
+ if ( AutoAttributeEditor . AutoRefreshInspector )
22
+ AutoAttributeEditor . ApplyAttributeToSerializedProperty ( property , attr ) ;
23
23
24
+ var optionalError = AutoAttributeEditor . Validate ( property ) ;
24
25
26
+ if ( ! attr . Hidden || optionalError . HasValue )
27
+ PropertyGUI ( position , property , label ) ;
25
28
26
- if ( ! attr . Hidden || optionalError . HasValue )
27
- PropertyGUI ( position , property , label ) ;
29
+ // If we have an error, render the error stuff
30
+ if ( optionalError is AutoAttributeEditor . Error error )
31
+ {
32
+ var baseHeight = base . GetPropertyHeight ( property , label ) ;
28
33
29
- // If we have an error, render the error stuff
30
- if ( optionalError is AutoAttributeEditor . Error error )
34
+ Rect errorBox = new Rect ( position . x + EditorGUIUtility . labelWidth + 1f , position . y + baseHeight + 1 , position . width - EditorGUIUtility . labelWidth , position . height - baseHeight - 1 ) ;
35
+ EditorGUI . HelpBox ( errorBox , error . message , error . blocks ? MessageType . Error : MessageType . Warning ) ;
36
+ }
37
+ }
38
+ catch ( System . Exception e )
31
39
{
32
- var baseHeight = base . GetPropertyHeight ( property , label ) ;
33
-
34
- Rect errorBox = new Rect ( position . x + EditorGUIUtility . labelWidth + 1f , position . y + baseHeight + 1 , position . width - EditorGUIUtility . labelWidth , position . height - baseHeight - 1 ) ;
35
- EditorGUI . HelpBox ( errorBox , error . message , error . blocks ? MessageType . Error : MessageType . Warning ) ;
40
+ EditorGUI . HelpBox ( position , e . Message , MessageType . Error ) ;
41
+ Debug . Log ( e ) ;
36
42
}
37
-
38
43
}
39
44
40
45
private void PropertyGUI ( Rect position , SerializedProperty property , GUIContent label )
41
46
{
42
- // Ensure regardless of height we still have a regular sized box
43
- position . height = base . GetPropertyHeight ( property , label ) ;
47
+ try
48
+ {
49
+ // Ensure regardless of height we still have a regular sized box
50
+ position . height = base . GetPropertyHeight ( property , label ) ;
51
+
52
+ // Not hidden, lets just display it
53
+ var iconLabel = new GUIContent ( AutoAttributeEditor . IconAuto_16 ) ;
54
+ iconLabel . tooltip = "Automatically Linked Component" ;
55
+ Rect iconBox = new Rect ( position . x + EditorGUIUtility . labelWidth - position . height - 1.5f , position . y + 1.5f , position . height - 3 , position . height - 3 ) ;
56
+ EditorGUI . LabelField ( iconBox , iconLabel ) ;
44
57
45
- // Not hidden, lets just display it
46
- var iconLabel = new GUIContent ( AutoAttributeEditor . IconAuto_16 ) ;
47
- iconLabel . tooltip = "Automatically Linked Component" ;
48
- Rect iconBox = new Rect ( position . x + EditorGUIUtility . labelWidth - position . height - 1.5f , position . y + 1.5f , position . height - 3 , position . height - 3 ) ;
49
- EditorGUI . LabelField ( iconBox , iconLabel ) ;
58
+ EditorGUI . PropertyField ( position , property , label ) ;
59
+ GUI . color = Color . white ;
50
60
51
- EditorGUI . PropertyField ( position , property , label ) ;
52
- GUI . color = Color . white ;
61
+ }
62
+ catch ( System . Exception e )
63
+ {
64
+ EditorGUI . HelpBox ( position , e . Message , MessageType . Error ) ;
65
+ Debug . Log ( e ) ;
66
+ }
53
67
}
54
68
55
69
public override float GetPropertyHeight ( SerializedProperty property , GUIContent label )
56
70
{
57
- if ( AutoAttributeEditor . Validate ( property ) . HasValue )
58
- return base . GetPropertyHeight ( property , label ) + 20 ;
71
+ try
72
+ {
73
+ if ( AutoAttributeEditor . Validate ( property ) . HasValue )
74
+ return base . GetPropertyHeight ( property , label ) + 20 ;
59
75
60
- var attr = attribute as AutoAttribute ;
61
- return attr . Hidden ? 0 : base . GetPropertyHeight ( property , label ) ;
76
+ var attr = attribute as AutoAttribute ;
77
+ return attr . Hidden ? 0 : base . GetPropertyHeight ( property , label ) ;
78
+ }
79
+ catch ( System . Exception e )
80
+ {
81
+ Debug . LogError ( "Failed to determine the best high for an auto attribute\n " + e . Message ) ;
82
+ return EditorGUIUtility . singleLineHeight ;
83
+ }
62
84
}
63
85
}
64
86
}
0 commit comments