2022-01-15 11:25:12 -05:00
|
|
|
|
using TriInspector;
|
|
|
|
|
using TriInspector.Validators;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
2022-07-14 05:51:08 -04:00
|
|
|
|
[assembly: RegisterTriValueValidator(typeof(MissingReferenceValidator))]
|
2022-01-15 11:25:12 -05:00
|
|
|
|
|
|
|
|
|
namespace TriInspector.Validators
|
|
|
|
|
{
|
2022-07-14 05:51:08 -04:00
|
|
|
|
public class MissingReferenceValidator : TriValueValidator<UnityEngine.Object>
|
2022-01-15 11:25:12 -05:00
|
|
|
|
{
|
2022-07-14 05:51:08 -04: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)
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
}
|