diff --git a/Editor.Extras/Drawers/GUIColorDrawer.cs b/Editor.Extras/Drawers/GUIColorDrawer.cs index 65c6d04..3cf04d6 100644 --- a/Editor.Extras/Drawers/GUIColorDrawer.cs +++ b/Editor.Extras/Drawers/GUIColorDrawer.cs @@ -1,4 +1,5 @@ -using TriInspector; +using JetBrains.Annotations; +using TriInspector; using TriInspector.Drawers; using TriInspector.Resolvers; using UnityEngine; @@ -9,27 +10,33 @@ namespace TriInspector.Drawers { public class GUIColorDrawer : TriAttributeDrawer { + [CanBeNull] private ValueResolver _colorResolver; + + public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition) + { + if (!string.IsNullOrEmpty(Attribute.GetColor)) + { + _colorResolver = ValueResolver.Resolve(propertyDefinition, Attribute.GetColor); + } + + if (_colorResolver != null && _colorResolver.TryGetErrorString(out var error)) + { + return error; + } + + return TriExtensionInitializationResult.Ok; + } + public override void OnGUI(Rect position, TriProperty property, TriElement next) { var oldColor = GUI.color; - var newColor = Color.white; - - if (string.IsNullOrEmpty(Attribute.GetColor)) - { - newColor = Attribute.Color; - } - else - { - var colorResolver = ValueResolver.Resolve(property.Definition, Attribute.GetColor ?? ""); - - newColor = colorResolver.GetValue(property, Color.white); - } - + var newColor = _colorResolver?.GetValue(property, Color.white) ?? Attribute.Color; + GUI.color = newColor; GUI.contentColor = newColor; - + next.OnGUI(position); - + GUI.color = oldColor; GUI.contentColor = oldColor; }