Tri-Inspector/Editor.Extras/Validators/MissingReferenceValidator.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2022-01-15 11:25:12 -05:00
using TriInspector;
using TriInspector.Validators;
using UnityEditor;
[assembly: RegisterTriValueValidator(typeof(MissingReferenceValidator))]
2022-01-15 11:25:12 -05:00
namespace TriInspector.Validators
{
public class MissingReferenceValidator : TriValueValidator<UnityEngine.Object>
2022-01-15 11:25:12 -05:00
{
public override TriValidationResult Validate(TriValue<UnityEngine.Object> propertyValue)
2022-01-15 11:25:12 -05:00
{
if (propertyValue.Property.TryGetSerializedProperty(out var serializedProperty) &&
serializedProperty.propertyType == SerializedPropertyType.ObjectReference &&
serializedProperty.objectReferenceValue == null &&
serializedProperty.objectReferenceInstanceIDValue != 0)
{
return TriValidationResult.Warning($"{GetName(propertyValue.Property)} is missing");
2022-01-15 11:25:12 -05:00
}
return TriValidationResult.Valid;
}
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
}
}