Tri-Inspector/Editor.Extras/Processors/DisableIfProcessor.cs
2022-08-03 11:38:52 +03:00

33 lines
1.1 KiB
C#

using TriInspector;
using TriInspector.Processors;
using TriInspector.Resolvers;
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))]
namespace TriInspector.Processors
{
public class DisableIfProcessor : TriPropertyDisableProcessor<DisableIfAttribute>
{
private ValueResolver<object> _conditionResolver;
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
{
base.Initialize(propertyDefinition);
_conditionResolver = ValueResolver.Resolve<object>(propertyDefinition, Attribute.Condition);
if (_conditionResolver.TryGetErrorString(out var error))
{
return error;
}
return TriExtensionInitializationResult.Ok;
}
public sealed override bool IsDisabled(TriProperty property)
{
var val = _conditionResolver.GetValue(property);
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
return equal != Attribute.Inverse;
}
}
}