Beispiel #1
0
        /// <summary>
        /// Constructor to create a pre-filled <see cref="InstanceValidatorCache"/>.
        /// </summary>
        public InstanceValidatorCache()
        {
            _validators = new List <AbstractInstanceValidator>();

            // Make sure any overriden disabled types are not included
            var overrideConfig = AssetValidatorOverrideConfig.FindOrCreate();

            // Get and add all field validators, excluding override disabled ones.
            var fieldValidators = ReflectionTools.GetAllDerivedInstancesOfType <FieldValidatorBase>();

            foreach (var fieldValidator in fieldValidators)
            {
                var t = fieldValidator.GetType();

                AssetValidatorOverrideConfig.OverrideItem overrideItem;
                if (overrideConfig.TryGetOverrideConfigItem(t, out overrideItem) && overrideItem.enabled)
                {
                    _validators.Add(fieldValidator);
                }
            }

            // Get and add all object validators, excluding override disabled ones.
            var objectValidators = ReflectionTools.GetAllDerivedInstancesOfType <ObjectValidatorBase>();

            foreach (var objectValidator in objectValidators)
            {
                var t = objectValidator.GetType();

                AssetValidatorOverrideConfig.OverrideItem overrideItem;
                if (overrideConfig.TryGetOverrideConfigItem(t, out overrideItem) && overrideItem.enabled)
                {
                    _validators.Add(objectValidator);
                }
            }
        }
        /// <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;
        }
        /// <summary>
        /// Constructor to create a pre-filled <see cref="ProjectValidatorCache"/>.
        /// </summary>
        public ProjectValidatorCache()
        {
            _validators = new List <ProjectValidatorBase>();

            // Make sure any overriden disabled types are not included
            var overrideConfig = AssetValidatorOverrideConfig.FindOrCreate();

            // Get and add all field validators, excluding override disabled ones.
            var pvs = ReflectionTools.GetAllDerivedInstancesOfTypeWithAttribute <ProjectValidatorBase, ValidatorAttribute>();

            foreach (var projectValidator in pvs)
            {
                var t = projectValidator.GetType();

                AssetValidatorOverrideConfig.OverrideItem overrideItem;
                if (overrideConfig.TryGetOverrideConfigItem(t, out overrideItem) && overrideItem.enabled)
                {
                    _validators.Add(projectValidator);
                }
            }
        }
        /// <summary>
        /// Constructor to create a pre-filled <see cref="CrossSceneValidatorCache"/>.
        /// </summary>
        public CrossSceneValidatorCache()
        {
            // Find all non-abstract derived instances of CrossSceneValidatorBase
            var validators = ReflectionTools.GetAllDerivedInstancesOfType <CrossSceneValidatorBase>();

            _validators = new List <CrossSceneValidatorBase>();

            // Make sure any overriden, disabled validator types are not included
            var overrideConfig = AssetValidatorOverrideConfig.FindOrCreate();

            foreach (var baseCrossSceneValidator in validators)
            {
                var t = baseCrossSceneValidator.GetType();

                AssetValidatorOverrideConfig.OverrideItem overrideItem;
                if (overrideConfig.TryGetOverrideConfigItem(t, out overrideItem) && overrideItem.enabled)
                {
                    _validators.Add(baseCrossSceneValidator);
                }
            }
        }