2022-01-15 11:25:12 -05:00
|
|
|
|
using TriInspector;
|
|
|
|
|
using TriInspector.Validators;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
|
|
|
|
[assembly: RegisterTriValueValidator(typeof(MissingReferenceValidator<>))]
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Validators
|
|
|
|
|
{
|
|
|
|
|
public class MissingReferenceValidator<T> : TriValueValidator<T>
|
|
|
|
|
where T : UnityEngine.Object
|
|
|
|
|
{
|
|
|
|
|
public override TriValidationResult Validate(TriValue<T> propertyValue)
|
|
|
|
|
{
|
|
|
|
|
if (propertyValue.Property.TryGetSerializedProperty(out var serializedProperty) &&
|
|
|
|
|
serializedProperty.propertyType == SerializedPropertyType.ObjectReference &&
|
|
|
|
|
serializedProperty.objectReferenceValue == null &&
|
|
|
|
|
serializedProperty.objectReferenceInstanceIDValue != 0)
|
|
|
|
|
{
|
2022-07-02 02:29:13 -04:00
|
|
|
|
return TriValidationResult.Warning($"{GetName(propertyValue.Property)} is missing");
|
2022-01-15 11:25:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TriValidationResult.Valid;
|
|
|
|
|
}
|
2022-07-02 02:29:13 -04:00
|
|
|
|
|
|
|
|
|
private static string GetName(TriProperty property)
|
|
|
|
|
{
|
|
|
|
|
var name = property.DisplayName;
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
name = property.RawName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2022-01-15 11:25:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|