Added GameObject Validators
This commit is contained in:
parent
c8a6815316
commit
269789b36f
15 changed files with 160 additions and 13 deletions
|
|
@ -40,7 +40,7 @@ namespace Module.ProjectValidator.Editor
|
|||
ProjectValidatorUtility.OpenWindow();
|
||||
|
||||
stopwatch.Stop();
|
||||
Debug.Log(stopwatch.Elapsed.TotalMilliseconds + "ms");
|
||||
Debug.Log($"Validator took {stopwatch.Elapsed.TotalMilliseconds}ms");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -63,9 +63,10 @@ namespace Module.ProjectValidator.Editor
|
|||
|
||||
_validatorList = new ValidatorList();
|
||||
_typeTree = new TypeTree();
|
||||
|
||||
FetchAllAttributeValidators();
|
||||
|
||||
FetchAllGameObjectValidators();
|
||||
FetchAllComponentValidators();
|
||||
FetchAllAttributeValidators();
|
||||
FetchAllTypesWithValidators<Component>(assemblies);
|
||||
FetchAllTypesWithValidators<ScriptableObject>(assemblies);
|
||||
_initialized = true;
|
||||
|
|
@ -100,6 +101,16 @@ namespace Module.ProjectValidator.Editor
|
|||
_validatorList.AddAttribute(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllGameObjectValidators()
|
||||
{
|
||||
var types = TypeCache.GetTypesDerivedFrom(typeof(IGameObjectValidator));
|
||||
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
_validatorList.AddGameObject(types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FetchAllComponentValidators()
|
||||
{
|
||||
|
|
@ -188,19 +199,39 @@ namespace Module.ProjectValidator.Editor
|
|||
private static void ValidateGameObject(GameObject gameObject, string scenePath, Report report)
|
||||
{
|
||||
ProjectValidatorUtility.AppendToScenePath(gameObject, ref scenePath);
|
||||
ValidateComponents(gameObject, scenePath, report);
|
||||
|
||||
var assetGuid = EditorAssetUtility.GetAssetGuid(gameObject);
|
||||
using var _ = ListPool<ValidatorResult>.Get(out var results);
|
||||
|
||||
for (var i = 0; i < _validatorList.GameObjectValidators.Count; i++)
|
||||
{
|
||||
results.Clear();
|
||||
|
||||
_validatorList.GameObjectValidators[i].Validate(gameObject, results);
|
||||
var type = ProjectValidatorUtility.GetGameObjectValidatorName(_validatorList.GameObjectValidators[i]);
|
||||
|
||||
for (var j = 0; j < results.Count; j++)
|
||||
{
|
||||
var result = results[j];
|
||||
|
||||
if (result.Severity != EValidatorSeverity.Valid)
|
||||
report.Add(assetGuid, scenePath, string.Empty, type, result.Severity, result.Message);
|
||||
}
|
||||
}
|
||||
|
||||
ValidateComponents(gameObject, assetGuid, scenePath, report);
|
||||
ValidateChildren(gameObject, scenePath, report);
|
||||
}
|
||||
|
||||
private static void ValidateComponents(GameObject gameObject, string scenePath, Report report)
|
||||
private static void ValidateComponents(GameObject gameObject, GUID assetGuid, string scenePath, Report report)
|
||||
{
|
||||
using var _ = ListPool<Component>.Get(out var components);
|
||||
var assetGuid = EditorAssetUtility.GetAssetGuid(gameObject);
|
||||
gameObject.GetComponents(components);
|
||||
|
||||
for (var i = 0; i < components.Count; i++)
|
||||
{
|
||||
Validate(assetGuid, scenePath, components[i], report);
|
||||
if (components[i] != null)
|
||||
Validate(assetGuid, scenePath, components[i], report);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue