Version : 1.1.0
- Unity Package Manager
- Add package from git URL:
- https://github.com/fidt17/Validator.git?path=/Assets/fidt17/UnityValidationModule
Run validator either by pressing [Alt+V] or by navigating to "Tools/Validator/Validator Window"
Specify Validation mode by selecting one of the options from dropdown menu
- "Active Scene": Validate all objects on loaded scene
- "In Build Scenes": Validate all objects across all build scenes. You will be asked to save current scene if required
- "Project Assets": Validate all Prefabs and ScriptableObjects
- "Everything": Validate "In Build Scene" + "Project Assets"
- "Run Validator on build": If enabled will start Validator in "Everything" mode before each new build
- "Stop build on Validator failure": If enabled an exception will be thrown once Validator finds an error. Which should cancel active build process
-
Fails if MyObject is null or missing
[NotNullValidation(validateInPrefab: true, recursiveValidation: true)] public Object MyObject;
Fails if MyCollection or any of it's elements are null
[NotNullValidation(validateInPrefab: true, recursiveValidation: true)] public IList<Object> MyCollection;
-
Fails if MyCollection is null or empty Field must be of type that implements ICollection interface
[NotEmptyCollection(allowNullElements: false, validateInPrefab: true, recursiveValidation: true)] public ICollection<Object> MyCollection;
-
Fails if any of call targets or methods are invalid Field must be of type UnityEvent
[UnityEventValidation(validateInPrefab: true, recursiveValidation: true)] public UnityEvent UEvent;
-
Method must return a boolean
[ValidationMethod(message: "This message will be displayed if validation fails.")] private bool MyValidationMethod() { bool validationResult = false; // ... return validationResult; }
You can create your own validation attributes with complex logic
public class LocalizationValidationAttribute : FieldValidationAttribute
{
public override ValidationResult ValidateField(FieldInfo field, object target)
{
var key = (string)field.GetValue(target);
var languages = LocalizationUtility.GetAllLanguages();
foreach (var language in languages)
{
if (string.IsNullOrEmpty(key)) continue;
var localizationMap = LocalizationUtility.GetLanguageMap(language);
if (localizationMap.IsValidLocalizationKey(key)) continue;
return new FailResult($"Missing key [{key}] in [{language}] map.", target);
}
return new PassResult();
}
}
Usage
[LocalizationValidation]
public string MyLocalizationKey;