Initial commit
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace NaughtyAttributes.Editor
|
||||
{
|
||||
public class RequiredPropertyValidator : PropertyValidatorBase
|
||||
{
|
||||
public override void ValidateProperty(SerializedProperty property)
|
||||
{
|
||||
RequiredAttribute requiredAttribute = PropertyUtility.GetAttribute<RequiredAttribute>(property);
|
||||
|
||||
if (property.propertyType == SerializedPropertyType.ObjectReference)
|
||||
{
|
||||
if (property.objectReferenceValue == null)
|
||||
{
|
||||
string errorMessage = property.name + " is required";
|
||||
if (!string.IsNullOrEmpty(requiredAttribute.Message))
|
||||
{
|
||||
errorMessage = requiredAttribute.Message;
|
||||
}
|
||||
|
||||
NaughtyEditorGUI.HelpBox_Layout(errorMessage, MessageType.Error, context: property.serializedObject.targetObject);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string warning = requiredAttribute.GetType().Name + " works only on reference types";
|
||||
NaughtyEditorGUI.HelpBox_Layout(warning, MessageType.Warning, context: property.serializedObject.targetObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user