From 801b793124b2755c7147a55a690de14d7781ed3b Mon Sep 17 00:00:00 2001 From: VladV Date: Thu, 19 May 2022 17:20:15 +0300 Subject: [PATCH] Integrates validators into drawers pipeline --- Editor/Elements/TriPropertyElement.cs | 5 ----- Editor/TriDrawerOrder.cs | 1 + Editor/TriPropertyDefinition.cs | 8 ++++++++ Editor/ValidatorsDrawer.cs | 20 ++++++++++++++++++++ Editor/ValidatorsDrawer.cs.meta | 3 +++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Editor/ValidatorsDrawer.cs create mode 100644 Editor/ValidatorsDrawer.cs.meta diff --git a/Editor/Elements/TriPropertyElement.cs b/Editor/Elements/TriPropertyElement.cs index 76b144d..f3fdeb1 100644 --- a/Editor/Elements/TriPropertyElement.cs +++ b/Editor/Elements/TriPropertyElement.cs @@ -36,11 +36,6 @@ namespace TriInspector.Elements element = drawer.CreateElementInternal(property, element); } - if (property.HasValidators) - { - AddChild(new TriPropertyValidationResultElement(property)); - } - AddChild(element); } diff --git a/Editor/TriDrawerOrder.cs b/Editor/TriDrawerOrder.cs index 2b070a9..62590eb 100644 --- a/Editor/TriDrawerOrder.cs +++ b/Editor/TriDrawerOrder.cs @@ -4,6 +4,7 @@ { public const int System = -9999; public const int Inspector = -2000; + public const int Validator = -1500; public const int Decorator = -1000; public const int Drawer = 0; public const int Fallback = 9999; diff --git a/Editor/TriPropertyDefinition.cs b/Editor/TriPropertyDefinition.cs index 6f3c481..90cdb41 100644 --- a/Editor/TriPropertyDefinition.cs +++ b/Editor/TriPropertyDefinition.cs @@ -152,6 +152,14 @@ namespace TriInspector _drawersBackingField = Enumerable.Empty() .Concat(TriDrawersUtilities.CreateValueDrawersFor(FieldType)) .Concat(TriDrawersUtilities.CreateAttributeDrawersFor(Attributes)) + .Concat(new[] + { + new ValidatorsDrawer + { + Order = TriDrawerOrder.Validator, + ApplyOnArrayElement = true, + }, + }) .Where(it => CanApplyOn(this, it.ApplyOnArrayElement)) .OrderBy(it => it.Order) .ToList(); diff --git a/Editor/ValidatorsDrawer.cs b/Editor/ValidatorsDrawer.cs new file mode 100644 index 0000000..090ffeb --- /dev/null +++ b/Editor/ValidatorsDrawer.cs @@ -0,0 +1,20 @@ +using TriInspector.Elements; + +namespace TriInspector +{ + internal class ValidatorsDrawer : TriCustomDrawer + { + public override TriElement CreateElementInternal(TriProperty property, TriElement next) + { + if (!property.HasValidators) + { + return next; + } + + var element = new TriElement(); + element.AddChild(new TriPropertyValidationResultElement(property)); + element.AddChild(next); + return element; + } + } +} \ No newline at end of file diff --git a/Editor/ValidatorsDrawer.cs.meta b/Editor/ValidatorsDrawer.cs.meta new file mode 100644 index 0000000..a0429f9 --- /dev/null +++ b/Editor/ValidatorsDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 70da4f7e93ab42ffa7b39c465d2d33e1 +timeCreated: 1652969657 \ No newline at end of file