- 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
This commit is contained in:
Anders Ejlersen 2026-05-24 18:06:56 +02:00
parent 01ac17a078
commit dd55a87740
30 changed files with 716 additions and 38 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using UnityEngine;
@ -11,6 +12,7 @@ namespace Module.ProjectValidator.Editor
private readonly Dictionary<Type, object> _attributeValidators = new();
private readonly Dictionary<Type, List<object>> _componentValidators = new();
public readonly List<IGameObjectValidator> GameObjectValidators = new();
public readonly Dictionary<Type, List<AssetValidator>> AssetValidators = new();
public void AddAttribute(Type type)
{
@ -75,6 +77,33 @@ namespace Module.ProjectValidator.Editor
Debug.LogException(e);
}
}
public void AddAsset(Type type)
{
if (type.IsInterface || type.IsAbstract)
return;
var typeValidator = type.GetInterfaces().FirstOrDefault(typeInterface => typeInterface.IsGenericType && typeInterface.GetGenericTypeDefinition() == typeof(IAssetValidator<>));
var componentType = typeValidator?.GetGenericArguments()[0];
if (componentType == null)
return;
try
{
var instance = FormatterServices.GetUninitializedObject(type);
var validator = new AssetValidator(instance);
if (AssetValidators.TryGetValue(componentType, out var list))
list.Add(validator);
else
AssetValidators.Add(componentType, new List<AssetValidator> { validator });
}
catch (Exception e)
{
Debug.LogException(e);
}
}
public bool TryGetAttributeValidator(Type type, out object validatorInstance)
{
@ -85,5 +114,17 @@ namespace Module.ProjectValidator.Editor
{
return _componentValidators.TryGetValue(type, out validatorInstances);
}
public sealed class AssetValidator
{
public readonly object Validator;
public readonly MethodInfo ValidatorMethod;
public AssetValidator(object validator)
{
Validator = validator;
ValidatorMethod = validator.GetType().GetMethod("Validate");
}
}
}
}