Tri-Inspector/Editor.Extras/Drawers/DropdownDrawer.cs
2023-04-05 21:29:06 +04:00

31 lines
995 B
C#

using TriInspector;
using TriInspector.Drawers;
using TriInspector.Elements;
using TriInspector.Resolvers;
[assembly: RegisterTriAttributeDrawer(typeof(DropdownDrawer<>), TriDrawerOrder.Decorator)]
namespace TriInspector.Drawers
{
public class DropdownDrawer<T> : TriAttributeDrawer<DropdownAttribute>
{
private DropdownValuesResolver<T> _valuesResolver;
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
{
_valuesResolver = DropdownValuesResolver<T>.Resolve(propertyDefinition, Attribute.Values);
if (_valuesResolver.TryGetErrorString(out var error))
{
return error;
}
return TriExtensionInitializationResult.Ok;
}
public override TriElement CreateElement(TriProperty property, TriElement next)
{
return new TriDropdownElement(property, _valuesResolver.GetDropdownItems);
}
}
}