mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 16:28:23 -05:00
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
|
using System;
|
|||
|
using Sirenix.OdinInspector.Editor;
|
|||
|
using Sirenix.OdinInspector.Editor.Validation;
|
|||
|
using TriInspector.Editor.Integrations.Odin;
|
|||
|
|
|||
|
[assembly: RegisterValidator(typeof(OdinFieldValidator<>))]
|
|||
|
|
|||
|
namespace TriInspector.Editor.Integrations.Odin
|
|||
|
{
|
|||
|
public class OdinFieldValidator<T> : AttributeValidator<DrawWithTriInspectorAttribute, T>, IDisposable
|
|||
|
{
|
|||
|
private TriPropertyTreeForOdin<T> _propertyTree;
|
|||
|
|
|||
|
public override RevalidationCriteria RevalidationCriteria { get; }
|
|||
|
= RevalidationCriteria.OnValueChangeOrChildValueChange;
|
|||
|
|
|||
|
public override bool CanValidateProperty(InspectorProperty property)
|
|||
|
{
|
|||
|
if (typeof(UnityEngine.Object).IsAssignableFrom(property.Info.TypeOfValue))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (property.IsTreeRoot)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
protected override void Initialize()
|
|||
|
{
|
|||
|
_propertyTree = new TriPropertyTreeForOdin<T>(ValueEntry);
|
|||
|
_propertyTree.Initialize(TriEditorMode.None);
|
|||
|
}
|
|||
|
|
|||
|
public void Dispose()
|
|||
|
{
|
|||
|
_propertyTree.Dispose();
|
|||
|
}
|
|||
|
|
|||
|
protected override void Validate(ValidationResult result)
|
|||
|
{
|
|||
|
_propertyTree.Update();
|
|||
|
_propertyTree.RunValidation();
|
|||
|
_propertyTree.CopyValidationResultsTo(result);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|