Validator: Duplicate component validator is now only run on types without DisallowMultipleComponent attribute

This commit is contained in:
Anders Ejlersen 2026-05-27 19:17:55 +02:00
parent ed3c02a0aa
commit 3802ca557c

View file

@ -1,4 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine; using UnityEngine;
using UnityEngine.Pool; using UnityEngine.Pool;
@ -28,7 +30,7 @@ namespace Module.ProjectValidator.Editor
} }
else else
{ {
if (count > 1) if (count > 1 && IsMultipleComponentsAllowed(type))
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components")); results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components"));
type = t; type = t;
@ -36,8 +38,13 @@ namespace Module.ProjectValidator.Editor
} }
} }
if (count > 1) if (count > 1 && IsMultipleComponentsAllowed(type))
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components")); results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"GameObject has duplicate '{type.Name}' ({count}) components"));
} }
private static bool IsMultipleComponentsAllowed(Type type)
{
return type.GetCustomAttribute<DisallowMultipleComponent>(true) == null;
}
} }
} }