/// <summary>
        /// Constructor that accepts the <see cref="LogCache"/> <paramref name="logCache"/> that logs will be
        /// stored in and the <see cref="SceneValidationMode"/> <paramref name="validationMode"/> that scenes
        /// will be validated in (if any).
        /// </summary>
        /// <param name="logCache"></param>
        /// <param name="validationMode"></param>
        public AssetValidatorRunner(LogCache logCache, SceneValidationMode validationMode)
        {
            _scenePaths = ProjectTools.GetScenePaths(validationMode);

            _logCache = logCache;

            _cache = new ClassTypeCache();

            // Ensure any unit test types do not get picked up for validation.
            _cache.IgnoreType <MonoBehaviourTwo>();
            _cache.IgnoreAttribute <OnlyIncludeInTestsAttribute>();

            // Find all objects for validation
            _cache.AddTypeWithAttribute <MonoBehaviour, ValidateAttribute>();

            // Add all disabled logs for this run
            AssetValidatorOverrideConfig.FindOrCreate().AddDisabledLogs(logCache);

            _isRunning   = true;
            _runningTime = EditorApplication.timeSinceStartup;
        }
Пример #2
0
        /// <summary>
        /// Iterate through all validator types and ensure an <see cref="OverrideItem"/> exists for each one.
        /// For any that no longer exist, remove these.
        /// </summary>
        internal void FindAndAddMissingTypes()
        {
            var classCache = new ClassTypeCache();

            classCache.IgnoreAttribute <OnlyIncludeInTestsAttribute>();
            classCache.AddTypeWithAttribute <FieldValidatorBase, ValidatorAttribute>();
            classCache.AddTypeWithAttribute <ObjectValidatorBase, ValidatorAttribute>();
            classCache.AddTypeWithAttribute <CrossSceneValidatorBase, ValidatorAttribute>();
            classCache.AddTypeWithAttribute <ProjectValidatorBase, ValidatorAttribute>();

            var validatorTargets = new List <ValidatorAttribute>();

            for (var i = 0; i < classCache.Count; i++)
            {
                var type           = classCache[i];
                var validatorAttrs = type.GetCustomAttributes(
                    typeof(ValidatorAttribute),
                    false)
                                     as ValidatorAttribute[];

                if (validatorAttrs == null || validatorAttrs.Length == 0)
                {
                    Debug.LogWarningFormat(ZeroValidatorAttributesFoundWarning, type.FullName);
                }
                else if (validatorAttrs.Length > 1)
                {
                    Debug.LogWarningFormat(MultipleValidatorAttributesFoundWarning, type.FullName);
                }
                else
                {
                    validatorTargets.Add(validatorAttrs[0]);
                }
            }

            // Remove any missing override items that no longer exist
            for (var i = OverrideItems.Count - 1; i > 0; i--)
            {
                if (validatorTargets.Any(x => x.Symbol == OverrideItems[i].symbol))
                {
                    continue;
                }

                OverrideItems.Remove(OverrideItems[i]);
            }

            for (var i = 0; i < validatorTargets.Count; i++)
            {
                var vValidatorAttr = validatorTargets[i];

                // If we have never cached this type before, create a reference to it by way of symbol
                // Otherwise grab the existing reference and reassign the type.
                if (OverrideItems.All(x => x.symbol != vValidatorAttr.Symbol))
                {
                    var oItem = new OverrideItem
                    {
                        enabled = true,
                        symbol  = vValidatorAttr.Symbol,
                        type    = classCache[i]
                    };
                    OverrideItems.Add(oItem);
                }
                else
                {
                    var overrideItem = OverrideItems.First(x => x.symbol == vValidatorAttr.Symbol);
                    overrideItem.type = classCache[i];
                }
            }
        }