You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
using System; |
|
using System.Collections.Generic; |
|
using UnityEditor; |
|
|
|
namespace NaughtyAttributes.Editor |
|
{ |
|
public abstract class PropertyValidatorBase |
|
{ |
|
public abstract void ValidateProperty(SerializedProperty property); |
|
} |
|
|
|
public static class ValidatorAttributeExtensions |
|
{ |
|
private static Dictionary<Type, PropertyValidatorBase> _validatorsByAttributeType; |
|
|
|
static ValidatorAttributeExtensions() |
|
{ |
|
_validatorsByAttributeType = new Dictionary<Type, PropertyValidatorBase>(); |
|
_validatorsByAttributeType[typeof(MinValueAttribute)] = new MinValuePropertyValidator(); |
|
_validatorsByAttributeType[typeof(MaxValueAttribute)] = new MaxValuePropertyValidator(); |
|
_validatorsByAttributeType[typeof(RequiredAttribute)] = new RequiredPropertyValidator(); |
|
_validatorsByAttributeType[typeof(ValidateInputAttribute)] = new ValidateInputPropertyValidator(); |
|
} |
|
|
|
public static PropertyValidatorBase GetValidator(this ValidatorAttribute attr) |
|
{ |
|
PropertyValidatorBase validator; |
|
if (_validatorsByAttributeType.TryGetValue(attr.GetType(), out validator)) |
|
{ |
|
return validator; |
|
} |
|
else |
|
{ |
|
return null; |
|
} |
|
} |
|
} |
|
}
|
|
|