- 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:
parent
01ac17a078
commit
dd55a87740
30 changed files with 716 additions and 38 deletions
|
|
@ -13,7 +13,6 @@ namespace Module.ProjectValidator.Editor
|
|||
{
|
||||
internal static class ValidatorRunner
|
||||
{
|
||||
private static bool _initialized;
|
||||
private static ValidatorList _validatorList;
|
||||
private static TypeTree _typeTree;
|
||||
|
||||
|
|
@ -56,21 +55,19 @@ namespace Module.ProjectValidator.Editor
|
|||
|
||||
private static void Initialize()
|
||||
{
|
||||
if (_initialized)
|
||||
return;
|
||||
|
||||
var settings = ProjectValidatorSettings.GetOrCreate();
|
||||
var assemblies = GetAssembliesFrom(settings);
|
||||
|
||||
var enabled = GetEnabledValidators(settings);
|
||||
|
||||
_validatorList = new ValidatorList();
|
||||
_typeTree = new TypeTree();
|
||||
|
||||
FetchAllGameObjectValidators();
|
||||
FetchAllComponentValidators();
|
||||
FetchAllAttributeValidators();
|
||||
FetchAllGameObjectValidators(enabled);
|
||||
FetchAllComponentValidators(enabled);
|
||||
FetchAllAttributeValidators(enabled);
|
||||
FetchAllAssetValidators(enabled);
|
||||
FetchAllTypesWithValidators<Component>(assemblies);
|
||||
FetchAllTypesWithValidators<ScriptableObject>(assemblies);
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
private static Assembly[] GetAssembliesFrom(ProjectValidatorSettings settings)
|
||||
|
|
@ -93,33 +90,72 @@ namespace Module.ProjectValidator.Editor
|
|||
return assemblies.ToArray();
|
||||
}
|
||||
|
||||
private static void FetchAllAttributeValidators()
|
||||
private static HashSet<Type> GetEnabledValidators(ProjectValidatorSettings settings)
|
||||
{
|
||||
var enabled = new HashSet<Type>(settings.validators.Count);
|
||||
|
||||
for (var i = 0; i < settings.validators.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!settings.validators[i].enabled)
|
||||
continue;
|
||||
|
||||
var type = Type.GetType(settings.validators[i].type);
|
||||
|
||||
if (type != null)
|
||||
enabled.Add(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private static void FetchAllAttributeValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IAttributeValidator<>));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
_validatorList.AddAttribute(types[i]);
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddAttribute(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllGameObjectValidators()
|
||||
private static void FetchAllGameObjectValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IGameObjectValidator));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
_validatorList.AddGameObject(types[i]);
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddGameObject(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllComponentValidators()
|
||||
private static void FetchAllComponentValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IComponentValidator<>));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
_validatorList.AddComponent(types[i]);
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddComponent(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllAssetValidators(HashSet<Type> enabled)
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IAssetValidator<>));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
if (enabled.Contains(types[i]))
|
||||
_validatorList.AddAsset(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,6 +208,25 @@ namespace Module.ProjectValidator.Editor
|
|||
private static void ValidateAllAssets(Report report)
|
||||
{
|
||||
ValidateAssetsBytype<ScriptableObject>(report);
|
||||
|
||||
foreach (var pair in _validatorList.AssetValidators)
|
||||
{
|
||||
var assets = EditorAssetUtility.LoadAllAssets(pair.Key);
|
||||
|
||||
for (var i = 0; i < assets.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var assetPath = AssetDatabase.GetAssetPath(assets[i]);
|
||||
var assetGuid = AssetDatabase.GUIDFromAssetPath(assetPath);
|
||||
ValidateAsset(assets[i], assetGuid, assetPath, pair.Value, report);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateAllPrefabs(Report report)
|
||||
|
|
@ -253,6 +308,29 @@ namespace Module.ProjectValidator.Editor
|
|||
Validate(assetGuid, relativePath, components[i], report);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateAsset(UnityEngine.Object obj, GUID assetGuid, string relativePath, List<ValidatorList.AssetValidator> validators, Report report)
|
||||
{
|
||||
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
||||
|
||||
for (var i = 0; i < validators.Count; i++)
|
||||
{
|
||||
results.Clear();
|
||||
var validator = validators[i];
|
||||
validator.ValidatorMethod.Invoke(validator.Validator, new object[] { obj, results });
|
||||
|
||||
for (var j = 0; j < results.Count; j++)
|
||||
{
|
||||
var result = results[j];
|
||||
|
||||
if (result.Severity == EValidatorSeverity.Valid)
|
||||
continue;
|
||||
|
||||
var validatorName = ProjectValidatorUtility.GetAssetValidatorName(validator.Validator);
|
||||
report.Add(assetGuid, relativePath, string.Empty, validatorName, result.Severity, result.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateChildren(GameObject gameObject, string relativePath, Report report)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue