1.1.0: Added validate attribute with NotNullField

This commit is contained in:
Anders Ejlersen 2021-12-04 15:04:41 +01:00
parent 18356eb532
commit 41ced8fdb7
15 changed files with 166 additions and 8 deletions

View file

@ -0,0 +1,50 @@
using UnityEditor;
namespace Module.Inspector.Editor
{
[CustomPropertyDrawer(typeof(NotNullFieldAttribute))]
internal sealed class NotNullFieldAttributeDrawer : ValidatePropertyDrawer
{
public override bool Validate(ValidatePropertyAttribute attribute, SerializedProperty property)
{
switch (property.propertyType)
{
case SerializedPropertyType.Integer:
case SerializedPropertyType.Boolean:
case SerializedPropertyType.Float:
case SerializedPropertyType.String:
case SerializedPropertyType.Color:
case SerializedPropertyType.LayerMask:
case SerializedPropertyType.Enum:
case SerializedPropertyType.Vector2:
case SerializedPropertyType.Vector3:
case SerializedPropertyType.Vector4:
case SerializedPropertyType.Rect:
case SerializedPropertyType.ArraySize:
case SerializedPropertyType.Character:
case SerializedPropertyType.Bounds:
case SerializedPropertyType.Quaternion:
case SerializedPropertyType.Vector2Int:
case SerializedPropertyType.Vector3Int:
case SerializedPropertyType.RectInt:
case SerializedPropertyType.BoundsInt:
return true;
case SerializedPropertyType.ObjectReference:
case SerializedPropertyType.Gradient:
case SerializedPropertyType.ExposedReference:
case SerializedPropertyType.ManagedReference:
case SerializedPropertyType.FixedBufferSize:
return property.objectReferenceValue != null;
case SerializedPropertyType.AnimationCurve:
return property.animationCurveValue != null;
}
return true;
}
public override string GetValidationError(SerializedProperty property)
{
return "NotNullField: Value is null";
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5e97d0a1ad0c4cc48034e3e60ef3d18f
timeCreated: 1638625437