module-project-validator/README.md
Anders Ejlersen dd55a87740 - Validator: Added asset validators with material texture and shader validation
- Validator: Added option to enable/disable certain validators
- Project Settings: Fixed issue, where changes weren't always saved
- Unity: Removed deprecated warnings in Unity 6.4
2026-05-24 18:06:56 +02:00

105 lines
No EOL
2.8 KiB
Markdown

# Description
A tool to help validate data across scenes, prefabs, scriptable objects and assets.
![Editor Window](~Images/editor-window.png)
## Unity Windows
![Hierachy Window](~Images/editor-hierarchy-window.png)
![Project Window](~Images/editor-project-window.png)
## Settings
![Project Settings](~Images/editor-project-settings.png)
## Validators
### Asset Validators
```csharp
public sealed class AssetValidatorMaterialTexture : IAssetValidator<Material>
{
public void Validate(Material obj, List<ValidatorResult> results)
{
if (obj.shader == null)
return;
var count = obj.shader.GetPropertyCount();
for (var i = 0; i < count; i++)
{
var propertyType = obj.shader.GetPropertyType(i);
if (propertyType != ShaderPropertyType.Texture)
continue;
var propertyName = obj.shader.GetPropertyName(i);
var propertyValue = obj.GetTexture(propertyName);
if (propertyValue == null)
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Texture property '{propertyName}' is Null"));
}
}
}
```
### Game Object Validators
```csharp
public sealed class GameObjectValidatorBrokenPrefab : IGameObjectValidator
{
public void Validate(GameObject gameObject, List<ValidatorResult> results)
{
if (PrefabUtility.IsPrefabAssetMissing(gameObject))
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, "GameObject is missing prefab asset"));
}
}
```
### Component Validators
```csharp
public sealed class ComponentValidatorMeshCollider : IComponentValidator<MeshCollider>
{
public void Validate(MeshCollider component, List<ValidatorResult> results)
{
if (component.sharedMesh == null)
results.Add(ValidatorResult.Create(EValidatorSeverity.Error, "Missing mesh"));
}
}
```
### Attribute Validators
The field attribute:
```csharp
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = true)]
public sealed class RequiredAttribute : Attribute
{
private readonly EValidatorSeverity _severity;
public RequiredAttribute()
{
_severity = EValidatorSeverity.Error;
}
public RequiredAttribute(EValidatorSeverity severity)
{
_severity = severity;
}
}
```
The validator implements `IAttributeValidator<T>`, where `T` is the attribute and will automatically be found by the validator.
```csharp
public sealed class Validator : IAttributeValidator<RequiredAttribute>
{
public ValidatorResult Validate(RequiredAttribute attribute, object value)
{
var isValid = value is UnityEngine.Object obj ? obj != null : value != null;
return isValid ? ValidatorResult.Valid : ValidatorResult.Create(attribute._severity, "Value is Null");
}
}
```