Added attribute validators for min and range attributes
This commit is contained in:
parent
591693da1d
commit
47c9c53819
6 changed files with 56 additions and 1 deletions
3
Editor/Validators/Attributes.meta
Normal file
3
Editor/Validators/Attributes.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0aa1d741049f4074bb863b76ed604d07
|
||||
timeCreated: 1779214748
|
||||
23
Editor/Validators/Attributes/AttributeValidatorMin.cs
Normal file
23
Editor/Validators/Attributes/AttributeValidatorMin.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class AttributeValidatorMin : IAttributeValidator<MinAttribute>
|
||||
{
|
||||
public ValidatorResult Validate(MinAttribute attribute, object value)
|
||||
{
|
||||
if (value is int iValue)
|
||||
{
|
||||
if (iValue < attribute.min)
|
||||
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {iValue} is less than minimum value of {attribute.min}");
|
||||
}
|
||||
else if (value is float fValue)
|
||||
{
|
||||
if (fValue < attribute.min)
|
||||
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {fValue} is less than minimum value of {attribute.min}");
|
||||
}
|
||||
|
||||
return ValidatorResult.Valid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2015106b3c9b450e9efb1333e5239033
|
||||
timeCreated: 1779214761
|
||||
23
Editor/Validators/Attributes/AttributeValidatorRange.cs
Normal file
23
Editor/Validators/Attributes/AttributeValidatorRange.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Module.ProjectValidator.Editor
|
||||
{
|
||||
internal sealed class AttributeValidatorRange : IAttributeValidator<RangeAttribute>
|
||||
{
|
||||
public ValidatorResult Validate(RangeAttribute attribute, object value)
|
||||
{
|
||||
if (value is int iValue)
|
||||
{
|
||||
if (iValue < attribute.min || iValue > attribute.max)
|
||||
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {iValue} is not in the range [{attribute.min};{attribute.max}]");
|
||||
}
|
||||
else if (value is float fValue)
|
||||
{
|
||||
if (fValue < attribute.min || fValue > attribute.max)
|
||||
return ValidatorResult.Create(EValidatorSeverity.Error, $"Value {fValue} is not in the range [{attribute.min};{attribute.max}]");
|
||||
}
|
||||
|
||||
return ValidatorResult.Valid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3115c26bccfe4b1e964f784a3f9fdd55
|
||||
timeCreated: 1779214908
|
||||
Loading…
Add table
Add a link
Reference in a new issue