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

34 lines
1.1 KiB
C#

using TriInspector;
using TriInspector.Processors;
using TriInspector.Resolvers;
[assembly: RegisterTriPropertyHideProcessor(typeof(HideIfProcessor))]
namespace TriInspector.Processors
{
public class HideIfProcessor : TriPropertyHideProcessor<HideIfAttribute>
{
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 IsHidden(TriProperty property)
{
var val = _conditionResolver.GetValue(property);
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
return equal != Attribute.Inverse;
}
}
}