mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
Optimize GUIColorDrawer
This commit is contained in:
parent
9d0f5faeab
commit
a292fece70
@ -1,4 +1,5 @@
|
||||
using TriInspector;
|
||||
using JetBrains.Annotations;
|
||||
using TriInspector;
|
||||
using TriInspector.Drawers;
|
||||
using TriInspector.Resolvers;
|
||||
using UnityEngine;
|
||||
@ -9,21 +10,27 @@ namespace TriInspector.Drawers
|
||||
{
|
||||
public class GUIColorDrawer : TriAttributeDrawer<GUIColorAttribute>
|
||||
{
|
||||
[CanBeNull] private ValueResolver<Color> _colorResolver;
|
||||
|
||||
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Attribute.GetColor))
|
||||
{
|
||||
_colorResolver = ValueResolver.Resolve<Color>(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<Color>(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;
|
||||
|
Loading…
Reference in New Issue
Block a user