2022-05-21 04:49:12 -04:00
|
|
|
|
using System;
|
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
|
|
|
|
using Sirenix.OdinInspector.Editor.Validation;
|
|
|
|
|
using TriInspector.Editor.Integrations.Odin;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
|
|
|
|
[assembly: RegisterValidator(typeof(OdinObjectValidator<>))]
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Editor.Integrations.Odin
|
|
|
|
|
{
|
2022-05-25 03:05:29 -04:00
|
|
|
|
public class OdinObjectValidator<T> : ValueValidator<T>, IDisposable
|
2022-05-21 04:49:12 -04:00
|
|
|
|
where T : UnityEngine.Object
|
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
private bool _initialized;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
private TriPropertyTreeForSerializedObject _propertyTree;
|
|
|
|
|
private SerializedObject _serializedObject;
|
|
|
|
|
|
|
|
|
|
public override RevalidationCriteria RevalidationCriteria { get; }
|
|
|
|
|
= RevalidationCriteria.OnValueChangeOrChildValueChange;
|
|
|
|
|
|
|
|
|
|
public override bool CanValidateProperty(InspectorProperty property)
|
|
|
|
|
{
|
2022-05-25 04:33:34 -04:00
|
|
|
|
if (!property.IsTreeRoot)
|
2022-05-25 03:05:29 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 12:17:31 -04:00
|
|
|
|
var type = property.Info.TypeOfValue;
|
|
|
|
|
|
|
|
|
|
if (type == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-05-25 04:33:34 -04:00
|
|
|
|
|
2022-08-28 08:29:49 -04:00
|
|
|
|
if (!TriOdinUtility.IsDrawnByTri(type))
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
_propertyTree?.Dispose();
|
|
|
|
|
_serializedObject?.Dispose();
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Validate(ValidationResult result)
|
|
|
|
|
{
|
2022-06-06 12:17:31 -04:00
|
|
|
|
if (!_initialized)
|
|
|
|
|
{
|
|
|
|
|
_initialized = true;
|
|
|
|
|
_serializedObject = new SerializedObject(ValueEntry.SmartValue);
|
|
|
|
|
_propertyTree = new TriPropertyTreeForSerializedObject(_serializedObject);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-21 04:49:12 -04:00
|
|
|
|
_serializedObject.Update();
|
|
|
|
|
|
|
|
|
|
_propertyTree.Update();
|
|
|
|
|
_propertyTree.RunValidation();
|
|
|
|
|
_propertyTree.CopyValidationResultsTo(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|