Пример #1
0
        protected InstanceValidatorManagerBase(ClassTypeCache cache, LogCache logCache)
            : base(logCache)
        {
            _cache = cache;
            _instanceValidatorCache = new InstanceValidatorCache();
            for (var i = 0; i < _instanceValidatorCache.Count; i++)
            {
                _instanceValidatorCache[i].LogCreated += OnLogCreated;
            }

            // Build up a lookup table of type to validators to be able to apply that set of validators to
            // an instance of that type later on.
            _objectsToValidate      = new List <Object>();
            _typeToValidatorsLookup = new Dictionary <Type, List <AbstractInstanceValidator> >();

            for (var i = 0; i < _cache.Count; i++)
            {
                var cacheType = _cache[i];
                for (var j = 0; j < _instanceValidatorCache.Count; j++)
                {
                    var validator = _instanceValidatorCache[j];
                    if (!validator.AppliesTo(cacheType))
                    {
                        continue;
                    }

                    if (!_typeToValidatorsLookup.ContainsKey(cacheType))
                    {
                        _typeToValidatorsLookup.Add(cacheType, new List <AbstractInstanceValidator>());
                    }

                    _typeToValidatorsLookup[cacheType].Add(validator);
                }
            }
        }
 public ProjectAssetValidatorManager(ClassTypeCache cache, LogCache logCache)
     : base(cache, logCache)
 {
     _continueSearchProgress = 0;
     _allPrefabGUIDs         = AssetDatabase.FindAssets(PrefabWildcardFilter);
     _projectValidatorCache  = new ProjectValidatorCache();
     for (var i = 0; i < _projectValidatorCache.Count; i++)
     {
         _projectValidatorCache[i].LogCreated += OnLogCreated;
     }
 }
        /// <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;
        }
Пример #4
0
 public ActiveSceneValidatorManager(ClassTypeCache cache, LogCache logCache)
     : base(cache, logCache)
 {
 }
Пример #5
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];
                }
            }
        }