/// <summary> /// Returns a read-only list of scene paths based on the passed <see cref="SceneValidationMode"/> /// <paramref name="validationMode"/>. /// </summary> /// <param name="validationMode"></param> /// <returns></returns> public static IReadOnlyList <string> GetScenePaths(SceneValidationMode validationMode) { switch (validationMode) { case SceneValidationMode.None: return(new string[0]); case SceneValidationMode.ActiveScene: return(new[] { SceneManager.GetActiveScene().path }); case SceneValidationMode.AllScenes: return(GetAllScenePathsInProject()); case SceneValidationMode.AllBuildScenes: return(GetAllScenePathsInBuildSettings()); case SceneValidationMode.AllBuildAndAssetBundleScenes: var finalScenes = GetAllScenePathsInAssetBundles(); finalScenes.AddRange(GetAllScenePathsInBuildSettings()); return(finalScenes); default: throw new ArgumentOutOfRangeException(Enum.GetName(typeof(SceneValidationMode), validationMode)); } }
public static IList <string> GetScenePaths(SceneValidationMode vmode) { switch (vmode) { case SceneValidationMode.None: return(new string[0]); case SceneValidationMode.ActiveScene: return(new[] { EditorSceneManager.GetActiveScene().path }); case SceneValidationMode.AllScenes: return(GetAllScenePathsInProject()); case SceneValidationMode.AllBuildScenes: return(GetAllScenePathsInBuildSettings()); case SceneValidationMode.AllBuildAndAssetBundleScenes: var finalScenes = GetAllScenePathsInAssetBundles(); finalScenes.AddRange(GetAllScenePathsInBuildSettings()); return(finalScenes); default: throw new ArgumentOutOfRangeException("vmode", vmode, null); } }
public static void LaunchWindowWithValidation( SceneValidationMode validationMode, FileOutputFormat fileOutputFormat) { var window = GetWindow <AssetValidatorEditorWindow>(); window.Show(); window.LaunchValidator(validationMode, fileOutputFormat, false, false, string.Empty); }
public static void LaunchWindowWithValidation(SceneValidationMode vMode, OutputFormat oFormat, bool doValidateProjectAssets = false, bool doValidateAcrossScenes = false, string fileName = "asset_validator_results") { var window = GetWindow <AssetValidatorEditorWindow>(); window.Show(); window.LaunchValidator(vMode, oFormat, doValidateProjectAssets, doValidateAcrossScenes, fileName); }
/// <summary> /// Launch Validator is a one-all fit for being able to run Validation /// </summary> /// <param name="vMode"></param> /// <param name="oFormat"></param> /// <param name="doValidateProjectAssets"></param> /// <param name="doValidateAcrossScenes"></param> /// <param name="fileName"></param> private void LaunchValidator(SceneValidationMode vMode, OutputFormat oFormat, bool doValidateProjectAssets = false, bool doValidateAcrossScenes = false, string fileName = "asset_validator_results") { AssetValidatorUtility.EditorOuputFormat = oFormat; AssetValidatorUtility.EditorFilename = fileName; OnValidateSelectionClick(vMode, doValidateProjectAssets, doValidateAcrossScenes); }
/// <summary> /// Runs validation against the project in <see cref="SceneValidationMode"/> /// <paramref name="validationMode"/> and writes the log file to a file with the default name. /// </summary> /// <param name="validationMode">The <see cref="SceneValidationMode"/> the validation is run in.</param> /// <param name="fileOutputFormat">The <see cref="FileOutputFormat"/> the file will be written in, if any.</param> /// <param name="doValidateProjectAssets">True if project assets should be validated, false if not.</param> /// <param name="doValidateAcrossScenes">True if cross-scene validation should be performed.</param> /// <returns></returns> public static Result RunValidation( SceneValidationMode validationMode, FileOutputFormat fileOutputFormat, bool doValidateProjectAssets, bool doValidateAcrossScenes) { return(RunValidation( validationMode, fileOutputFormat, doValidateProjectAssets, doValidateAcrossScenes, string.Empty)); }
/// <summary> /// Launch Validator is a one-all fit for being able to run Validation /// </summary> /// <param name="vMode"></param> /// <param name="fileOutputFormat"></param> /// <param name="doValidateProjectAssets"></param> /// <param name="doValidateAcrossScenes"></param> /// <param name="fileName"></param> private void LaunchValidator(SceneValidationMode vMode, FileOutputFormat fileOutputFormat, bool doValidateProjectAssets, bool doValidateAcrossScenes, string fileName) { _selectedFileOutputFormat = fileOutputFormat; _outputFilename = string.IsNullOrEmpty(fileName) ? EditorConstants.DefaultLogFilename : fileName; OnValidateSelectionClick(vMode, doValidateProjectAssets, doValidateAcrossScenes); }
/// <summary> /// Runs validation against the project in <see cref="SceneValidationMode"/> /// <paramref name="validationMode"/> and writes the log file to a file with a custom name. /// </summary> /// <param name="validationMode">The <see cref="SceneValidationMode"/> the validation is run in.</param> /// <param name="fileOutputFormat">The <see cref="FileOutputFormat"/> the file will be written in, if any.</param> /// <param name="doValidateProjectAssets">True if project assets should be validated, false if not.</param> /// <param name="doValidateAcrossScenes">True if cross-scene validation should be performed.</param> /// <param name="fileName">A custom filename for the log results to be written to.</param> /// <returns></returns> public static Result RunValidation( SceneValidationMode validationMode, FileOutputFormat fileOutputFormat, bool doValidateProjectAssets, bool doValidateAcrossScenes, string fileName) { try { var logCache = new LogCache(); var assetValidationRunner = new AssetValidatorRunner(logCache, validationMode); if (doValidateProjectAssets) { assetValidationRunner.EnableProjectAssetValidation(); } if (doValidateAcrossScenes) { assetValidationRunner.EnableCrossSceneValidation(); } assetValidationRunner.Run(); var newFileName = string.IsNullOrEmpty(fileName) ? EditorConstants.DefaultLogFilename : fileName; LogFileWriter.WriteLogs(newFileName, fileOutputFormat, logCache); var result = new Result { isSuccessful = logCache.All(x => x.logType != LogType.Error) }; result.message = result.isSuccessful ? ValidationSuccessMessage : ValidationFailedMessage; return(result); } catch (Exception ex) { return(new Result { isSuccessful = false, message = string.Format(ValidationErrorFormat, ex) }); } }
private void OnValidateSelectionClick( SceneValidationMode validationMode, bool doValidateProjectAssets = false, bool doValidateAcrossScenes = false) { // Only perform validation across multiple scenes if the current scene is saved, or // barring that if you don't care if it gets unloaded and lose changes var canExecute = true; var currentScene = SceneManager.GetActiveScene(); if (currentScene.isDirty && validationMode != SceneValidationMode.None && validationMode != SceneValidationMode.ActiveScene) { var didSave = EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() && !currentScene.isDirty; if (!didSave) { canExecute = EditorUtility.DisplayDialog( EditorConstants.EditorWindowTitle, EditorConstants.ContinuePromptMessage, EditorConstants.ProceedValidationButtonText, EditorConstants.CancelButtonText); } } if (!canExecute) { return; } // Clear out any remaining logs and queue up an AssetValidationRunner with // the desired config _logCache.ClearLogs(); _runner = new AssetValidatorRunner(_logCache, validationMode); if (doValidateProjectAssets) { _runner.EnableProjectAssetValidation(); } if (doValidateAcrossScenes) { _runner.EnableCrossSceneValidation(); } }
private void OnValidateSelectionClick(SceneValidationMode vmode, bool doValidateProjectAssets = false, bool doValidateAcrossScenes = false) { // Only perform validation across multiple scenes if the current scene is saved, or // barring that if you don't care if it gets unloaded and lose changes var canExecute = true; var currentScene = EditorSceneManager.GetActiveScene(); if (currentScene.isDirty && vmode != SceneValidationMode.None && vmode != SceneValidationMode.ActiveScene) { var didSave = EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() && !currentScene.isDirty; if (!didSave) { canExecute = EditorUtility.DisplayDialog("Asset Validator", "Continuing with validation may unload the current scene. Do you wish to continue?", "Continue Validation", "Cancel"); } } if (!canExecute) { return; } // Clear out any remaining logs and queue up an AssetValidationRunner with // the desired config _logger.ClearLogs(); _runner = new AssetValidatorRunner(_logger, vmode); if (doValidateProjectAssets) { _runner.EnableProjectAssetValidation(); } if (doValidateAcrossScenes) { _runner.EnableCrossSceneValidation(); } }
/// <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; }
public static Result RunValidation(SceneValidationMode vMode, OutputFormat oFormat, bool doValidateProjectAssets = false, bool doValidateAcrossScenes = false, string fileName = "asset_validator_results") { AssetValidatorUtility.EditorOuputFormat = oFormat; AssetValidatorUtility.EditorFilename = fileName; try { var assetLogger = new AssetValidatorLogger(); using (var assetValidationRunner = new AssetValidatorRunner(assetLogger, vMode)) { if (doValidateProjectAssets) { assetValidationRunner.EnableProjectAssetValidation(); } if (doValidateAcrossScenes) { assetValidationRunner.EnableCrossSceneValidation(); } assetValidationRunner.Run(); } var logs = assetLogger.GetLogs(); if (AssetValidatorUtility.EditorOuputFormat != OutputFormat.None) { using (var writer = new AssetValidatorLogWriter(AssetValidatorUtility.EditorFilename, AssetValidatorUtility.EditorOuputFormat)) { if (AssetValidatorUtility.EditorOuputFormat == OutputFormat.Html) { writer.CreateHtmlStyles(logs); } writer.AppendHeader(); for (var i = 0; i < logs.Count; i++) { writer.AppendVLog(logs[i]); } writer.AppendFooter(); writer.Flush(); } } var result = new Result { isSuccessful = logs.Any(x => x.vLogType == VLogType.Error) }; result.message = result.isSuccessful ? "No AssetValidation errors were found." : "Several AssetValidation errors were found"; return(result); } catch (Exception ex) { return(new Result() { isSuccessful = false, message = string.Format("AssetValidation failed to be run with the following exception: [{0}]", ex) }); } }