1- using TriInspector ;
1+ using JetBrains . Annotations ;
2+ using TriInspector ;
23using TriInspector . Drawers ;
34using TriInspector . Resolvers ;
45using UnityEngine ;
@@ -9,27 +10,33 @@ namespace TriInspector.Drawers
910{
1011 public class GUIColorDrawer : TriAttributeDrawer < GUIColorAttribute >
1112 {
12- public override void OnGUI ( Rect position , TriProperty property , TriElement next )
13+ [ CanBeNull ] private ValueResolver < Color > _colorResolver ;
14+
15+ public override TriExtensionInitializationResult Initialize ( TriPropertyDefinition propertyDefinition )
1316 {
14- var oldColor = GUI . color ;
15- var newColor = Color . white ;
16-
17- if ( string . IsNullOrEmpty ( Attribute . GetColor ) )
17+ if ( ! string . IsNullOrEmpty ( Attribute . GetColor ) )
1818 {
19- newColor = Attribute . Color ;
19+ _colorResolver = ValueResolver . Resolve < Color > ( propertyDefinition , Attribute . GetColor ) ;
2020 }
21- else
21+
22+ if ( _colorResolver != null && _colorResolver . TryGetErrorString ( out var error ) )
2223 {
23- var colorResolver = ValueResolver . Resolve < Color > ( property . Definition , Attribute . GetColor ?? "" ) ;
24-
25- newColor = colorResolver . GetValue ( property , Color . white ) ;
24+ return error ;
2625 }
27-
26+
27+ return TriExtensionInitializationResult . Ok ;
28+ }
29+
30+ public override void OnGUI ( Rect position , TriProperty property , TriElement next )
31+ {
32+ var oldColor = GUI . color ;
33+ var newColor = _colorResolver ? . GetValue ( property , Color . white ) ?? Attribute . Color ;
34+
2835 GUI . color = newColor ;
2936 GUI . contentColor = newColor ;
30-
37+
3138 next . OnGUI ( position ) ;
32-
39+
3340 GUI . color = oldColor ;
3441 GUI . contentColor = oldColor ;
3542 }
0 commit comments