From 4b9b5a8c1d5cd30dcd98e69d5b9c2d8bb16d426d Mon Sep 17 00:00:00 2001 From: max Date: Mon, 27 Dec 2021 00:52:50 +0100 Subject: [PATCH] Base validator SceneValidator & AssetValidator of objects that implement IValidatable. --- CHANGELOG.md | 5 +- CHANGELOG.md.meta | 7 + .../{PACKAGENAME.md => Validator.md} | 2 +- Editor.meta | 8 + Editor/COMPANYNAME.PACKAGENAME.Editor.asmdef | 16 - Editor/EditorExample.cs | 6 - Editor/IValidator.cs | 7 + Editor/IValidator.cs.meta | 11 + Editor/ValidatorEditorWindow.cs | 381 ++++++++++++++++++ Editor/ValidatorEditorWindow.cs.meta | 11 + Editor/Validators.meta | 8 + Editor/Validators/AssetValidator.cs | 48 +++ Editor/Validators/AssetValidator.cs.meta | 11 + Editor/Validators/SceneValidator.cs | 55 +++ Editor/Validators/SceneValidator.cs.meta | 11 + .../VertexColor.Validator.Editor.asmdef | 10 +- .../VertexColor.Validator.Editor.asmdef.meta | 7 + LICENSE.md | 2 +- LICENSE.md.meta | 7 + README.md | 30 +- README.md.meta | 7 + Runtime.meta | 8 + Runtime/IValidatable.cs | 9 + Runtime/IValidatable.cs.meta | 11 + Runtime/Report.cs | 60 +++ Runtime/Report.cs.meta | 11 + Runtime/ReportCategories.cs | 9 + Runtime/ReportCategories.cs.meta | 11 + Runtime/RuntimeExample.cs | 5 - ...ME.asmdef => VertexColor.Validator.asmdef} | 6 +- Runtime/VertexColor.Validator.asmdef.meta | 7 + Samples~/Example1/Example.txt | 2 - THIRD PARTY NOTICES.md.meta | 7 + Tests/Editor/TestEditorExample.cs | 26 -- .../COMPANYNAME.PACKAGENAME.Tests.asmdef | 17 - Tests/Runtime/TestRuntimeExample.cs | 25 -- package.json | 20 +- package.json.meta | 7 + 38 files changed, 762 insertions(+), 129 deletions(-) create mode 100644 CHANGELOG.md.meta rename Documentation~/{PACKAGENAME.md => Validator.md} (51%) create mode 100644 Editor.meta delete mode 100644 Editor/COMPANYNAME.PACKAGENAME.Editor.asmdef delete mode 100644 Editor/EditorExample.cs create mode 100644 Editor/IValidator.cs create mode 100644 Editor/IValidator.cs.meta create mode 100644 Editor/ValidatorEditorWindow.cs create mode 100644 Editor/ValidatorEditorWindow.cs.meta create mode 100644 Editor/Validators.meta create mode 100644 Editor/Validators/AssetValidator.cs create mode 100644 Editor/Validators/AssetValidator.cs.meta create mode 100644 Editor/Validators/SceneValidator.cs create mode 100644 Editor/Validators/SceneValidator.cs.meta rename Tests/Editor/COMPANYNAME.PACKAGENAME.Editor.Tests.asmdef => Editor/VertexColor.Validator.Editor.asmdef (59%) create mode 100644 Editor/VertexColor.Validator.Editor.asmdef.meta create mode 100644 LICENSE.md.meta create mode 100644 README.md.meta create mode 100644 Runtime.meta create mode 100644 Runtime/IValidatable.cs create mode 100644 Runtime/IValidatable.cs.meta create mode 100644 Runtime/Report.cs create mode 100644 Runtime/Report.cs.meta create mode 100644 Runtime/ReportCategories.cs create mode 100644 Runtime/ReportCategories.cs.meta delete mode 100644 Runtime/RuntimeExample.cs rename Runtime/{COMPANYNAME.PACKAGENAME.asmdef => VertexColor.Validator.asmdef} (64%) create mode 100644 Runtime/VertexColor.Validator.asmdef.meta delete mode 100644 Samples~/Example1/Example.txt create mode 100644 THIRD PARTY NOTICES.md.meta delete mode 100644 Tests/Editor/TestEditorExample.cs delete mode 100644 Tests/Runtime/COMPANYNAME.PACKAGENAME.Tests.asmdef delete mode 100644 Tests/Runtime/TestRuntimeExample.cs create mode 100644 package.json.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 2da9e92..9de31ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,3 @@ # Change Log: - ## 0.1.0 - -- Start Project: - - ... +- Base validator framework. \ No newline at end of file diff --git a/CHANGELOG.md.meta b/CHANGELOG.md.meta new file mode 100644 index 0000000..1053ced --- /dev/null +++ b/CHANGELOG.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 12174dcb2c74c6f4eb0f6d28d8670c14 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Documentation~/PACKAGENAME.md b/Documentation~/Validator.md similarity index 51% rename from Documentation~/PACKAGENAME.md rename to Documentation~/Validator.md index 119e48a..4923a4a 100644 --- a/Documentation~/PACKAGENAME.md +++ b/Documentation~/Validator.md @@ -1,3 +1,3 @@ -# PACKAGENAME +# Validator Documentation. \ No newline at end of file diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..eba7c41 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27a6e9d765504c6449f6cb83c81f2353 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/COMPANYNAME.PACKAGENAME.Editor.asmdef b/Editor/COMPANYNAME.PACKAGENAME.Editor.asmdef deleted file mode 100644 index 2c9e8f1..0000000 --- a/Editor/COMPANYNAME.PACKAGENAME.Editor.asmdef +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "COMPANYNAME.PACKAGENAME.Editor", - "references": [ - "COMPANYNAME.PACKAGENAME" - ], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": false, - "precompiledReferences": [], - "autoReferenced": true, - "defineConstraints": [], - "versionDefines": [] -} \ No newline at end of file diff --git a/Editor/EditorExample.cs b/Editor/EditorExample.cs deleted file mode 100644 index 7bf43e5..0000000 --- a/Editor/EditorExample.cs +++ /dev/null @@ -1,6 +0,0 @@ -using UnityEngine; -using UnityEditor; - -namespace COMPANYNAME.PACKAGENAME.Editor -{ -} \ No newline at end of file diff --git a/Editor/IValidator.cs b/Editor/IValidator.cs new file mode 100644 index 0000000..f067f61 --- /dev/null +++ b/Editor/IValidator.cs @@ -0,0 +1,7 @@ +namespace Validator.Editor +{ + public interface IValidator + { + public Report Validate(); + } +} \ No newline at end of file diff --git a/Editor/IValidator.cs.meta b/Editor/IValidator.cs.meta new file mode 100644 index 0000000..9faf265 --- /dev/null +++ b/Editor/IValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 75a64c845d92d1548bb095b40a6f5c9f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValidatorEditorWindow.cs b/Editor/ValidatorEditorWindow.cs new file mode 100644 index 0000000..eab77b6 --- /dev/null +++ b/Editor/ValidatorEditorWindow.cs @@ -0,0 +1,381 @@ +using System; +using System.Linq; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using UnityEditor.IMGUI.Controls; +using Object = UnityEngine.Object; + +namespace Validator.Editor +{ + public class ValidatorEditorWindow : EditorWindow + { + private readonly List reports = new List(); + private readonly List validators = new List(); + + private MultiColumnHeaderState multiColumnHeaderState; + private MultiColumnHeader multiColumnHeader; + private MultiColumnHeaderState.Column[] columns; + private readonly Color lightColor = Color.white * 0.3f; + private readonly Color darkColor = Color.white * 0.1f; + private Vector2 scrollPosition; + private float multiColumnHeaderWidth; + private float rows; + + [MenuItem("Window/General/Validator")] + private static void Init() + { + ValidatorEditorWindow window = (ValidatorEditorWindow)GetWindow(typeof(ValidatorEditorWindow)); + window.titleContent = new GUIContent("Validator"); + window.Show(); + window.LoadValidators(); + } + + private void OnGUI() + { + using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) + { + using (new EditorGUILayout.HorizontalScope()) + { + if (GUILayout.Button(EditorGUIUtility.IconContent("Refresh", "Refresh"))) + { + LoadValidators(); + } + + if (GUILayout.Button(EditorGUIUtility.IconContent("PlayButton", "Run all"))) + { + reports.Clear(); + + foreach (IValidator validator in validators) + { + reports.Add(validator.Validate()); + } + } + + if (GUILayout.Button(EditorGUIUtility.IconContent("d_preAudioLoopOff", "Select validator"))) + { + GenericMenu validatorOptionsMenu = new GenericMenu(); + foreach (IValidator validator in validators) + { + validatorOptionsMenu.AddItem(new GUIContent($"{validator.GetType().Name}"), false, OnGenericValidate, validator); + } + validatorOptionsMenu.ShowAsContext(); + } + + GUILayout.FlexibleSpace(); + GUILayout.Label($"{reports.Count}/{validators.Count}"); + } + + GUILayout.Space(EditorGUIUtility.standardVerticalSpacing); + DrawMultiColumnScope(); + } + } + + private void InitializeMultiColumn() + { + columns = new MultiColumnHeaderState.Column[] + { + new MultiColumnHeaderState.Column() + { + allowToggleVisibility = false, // At least one column must be there. + autoResize = false, + width = 36f, + minWidth = 36f, + maxWidth = 36f, + canSort = false, + sortingArrowAlignment = TextAlignment.Right, + headerContent = EditorGUIUtility.IconContent("d_console.erroricon.inactive.sml", "Warning Type."), + headerTextAlignment = TextAlignment.Center, + }, + new MultiColumnHeaderState.Column() + { + allowToggleVisibility = true, + autoResize = false, + width = 36f, + minWidth = 36f, + maxWidth = 36f, + canSort = false, + sortingArrowAlignment = TextAlignment.Right, + headerContent = EditorGUIUtility.IconContent("Animation.FilterBySelection", "Target Objects"), + headerTextAlignment = TextAlignment.Center, + }, + new MultiColumnHeaderState.Column() + { + allowToggleVisibility = true, + autoResize = true, + width = 75.0f, + minWidth = 75.0f, + canSort = false, + sortingArrowAlignment = TextAlignment.Right, + headerContent = new GUIContent("Category", "Warning Category."), + headerTextAlignment = TextAlignment.Center, + }, + new MultiColumnHeaderState.Column() + { + allowToggleVisibility = true, + autoResize = true, + width = 200.0f, + minWidth = 200.0f, + canSort = false, + sortingArrowAlignment = TextAlignment.Right, + headerContent = new GUIContent("Message", "Warning Message."), + headerTextAlignment = TextAlignment.Center, + }, + new MultiColumnHeaderState.Column() + { + allowToggleVisibility = true, + autoResize = true, + width = 200.0f, + minWidth = 200.0f, + canSort = false, + sortingArrowAlignment = TextAlignment.Right, + headerContent = new GUIContent("Solution", "Warning Solution."), + headerTextAlignment = TextAlignment.Center, + }, + }; + + multiColumnHeaderState = new MultiColumnHeaderState(columns: this.columns); + multiColumnHeader = new MultiColumnHeader(state: this.multiColumnHeaderState); + + // When we chagne visibility of the column we resize columns to fit in the window. + //multiColumnHeader.visibleColumnsChanged += (multiColumnHeader) => multiColumnHeader.ResizeToFit(); + // Initial resizing of the content. + multiColumnHeader.ResizeToFit(); + } + + private void DrawMultiColumnScope() + { + GUILayout.FlexibleSpace(); + Rect windowRect = GUILayoutUtility.GetLastRect(); + windowRect.width = position.width; + windowRect.height = position.height; + + if (multiColumnHeader == null) + { + InitializeMultiColumn(); + } + + float columnHeight = EditorGUIUtility.singleLineHeight * 2; + + Rect headerRect = new Rect(source: windowRect) + { + height = EditorGUIUtility.singleLineHeight, + }; + + Rect scrollViewPositionRect = GUILayoutUtility.GetRect(0, float.MaxValue, 0, float.MaxValue); + scrollViewPositionRect.y += headerRect.height - EditorGUIUtility.standardVerticalSpacing; + scrollViewPositionRect.height -= headerRect.height - EditorGUIUtility.standardVerticalSpacing; + + Rect scrollViewRect = new Rect(source: windowRect) + { + width = multiColumnHeaderState.widthOfAllVisibleColumns, + height = rows * columnHeight + }; + + Rect rowRect = new Rect(source: windowRect) + { + width = multiColumnHeaderWidth, + height = columnHeight, + }; + + // Draw column header. + multiColumnHeader.OnGUI(rect: headerRect, xScroll: scrollPosition.x); + + // Draw scroll view. + using (GUI.ScrollViewScope scope = new GUI.ScrollViewScope(scrollViewPositionRect, scrollPosition, scrollViewRect, false, false)) + { + scrollPosition = scope.scrollPosition; + multiColumnHeaderWidth = Mathf.Max(scrollViewPositionRect.width + scrollPosition.x, multiColumnHeaderWidth); + + rows = 0; + for (int i = 0; i < reports.Count; i++) + { + for (int j = 0; j < reports[i].Reports.Count; j++) + { + // Only draw what is visable within the view. + if (rowRect.yMax > windowRect.y + scrollPosition.y && rowRect.yMin < windowRect.height + scrollPosition.y) + { + if (j % 2 == 0) + { + EditorGUI.DrawRect(rect: rowRect, color: darkColor); + } + else + { + EditorGUI.DrawRect(rect: rowRect, color: lightColor); + } + + // Warning Field. + int columnIndex = 0; + if (multiColumnHeader.IsColumnVisible(columnIndex: columnIndex)) + { + int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex: columnIndex); + Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex: visibleColumnIndex); + columnRect.y = rowRect.y; + columnRect.height = rowRect.height; + + Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex: visibleColumnIndex, columnRect); + labelFieldRect.x += 9; + labelFieldRect.width -= 9; + + EditorGUI.LabelField( + position: labelFieldRect, + label: EditorGUIUtility.IconContent(GetWarningIconName(reports[i].Reports[j].WarningType), $"{reports[i].Reports[j].WarningType}") + ); + } + + // Target Field. + columnIndex = 1; + if (multiColumnHeader.IsColumnVisible(columnIndex: columnIndex)) + { + int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex: columnIndex); + Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex: visibleColumnIndex); + columnRect.y = rowRect.y; + columnRect.height = rowRect.height; + + if(reports[i].Reports[j].Target != null) + { + if (GUI.Button( + position: multiColumnHeader.GetCellRect(visibleColumnIndex: visibleColumnIndex, columnRect), + content: EditorGUIUtility.IconContent("Animation.FilterBySelection", "Ping Object") + )) + { + Selection.objects = new Object[] { reports[i].Reports[j].Target }; + + if (!Selection.activeObject) + { + Debug.Log($"{nameof(Selection.activeObject)} is null."); + continue; + } + + foreach (Object o in Selection.objects) + { + EditorGUIUtility.PingObject(o); + } + } + } + } + + // Category Field. + columnIndex = 2; + if (multiColumnHeader.IsColumnVisible(columnIndex: columnIndex)) + { + int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex: columnIndex); + Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex: visibleColumnIndex); + columnRect.y = rowRect.y; + columnRect.height = rowRect.height; + + Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex: visibleColumnIndex, columnRect); + labelFieldRect.x += 7; + labelFieldRect.width -= 7; + + EditorGUI.LabelField( + position: labelFieldRect, + label: new GUIContent($"{reports[i].Reports[j].Category}") + ); + } + + // Message Field. + columnIndex = 3; + if (multiColumnHeader.IsColumnVisible(columnIndex: columnIndex)) + { + int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex: columnIndex); + Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex: visibleColumnIndex); + columnRect.y = rowRect.y; + columnRect.height = rowRect.height; + + Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex: visibleColumnIndex, columnRect); + labelFieldRect.x += 7; + labelFieldRect.width -= 7; + + EditorGUI.LabelField( + position: labelFieldRect, + label: new GUIContent($"{reports[i].Reports[j].Message}") + ); + } + + // Solution Field. + columnIndex = 4; + if (multiColumnHeader.IsColumnVisible(columnIndex: columnIndex)) + { + int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex: columnIndex); + Rect columnRect = multiColumnHeader.GetColumnRect(visibleColumnIndex: visibleColumnIndex); + columnRect.y = rowRect.y; + columnRect.height = rowRect.height; + + Rect labelFieldRect = multiColumnHeader.GetCellRect(visibleColumnIndex: visibleColumnIndex, columnRect); + labelFieldRect.x += 7; + labelFieldRect.width -= 7; + + EditorGUI.LabelField( + position: labelFieldRect, + label: new GUIContent($"{reports[i].Reports[j].Solution}") + ); + } + } + + rowRect.y += columnHeight; + rows++; + } + } + scope.handleScrollWheel = true; + } + } + + private void LoadValidators() + { + for (int i = validators.Count - 1; i >= 0; i--) + { + if (validators[i] == null) + { + validators.RemoveAt(i); + } + } + + foreach (Type type in GetValidatorTypes()) + { + bool hasValidator = false; + foreach (IValidator validator in validators) + { + if (validator.GetType() == type) + { + hasValidator = true; + } + } + + if (!hasValidator) + { + IValidator validator = (IValidator)Activator.CreateInstance(type); + if (validator != null) + { + validators.Add(validator); + } + } + } + } + + private void OnGenericValidate(object validator) + { + if (validator is IValidator val) + { + reports.Clear(); + reports.Add(val.Validate()); + } + } + + private static Type[] GetValidatorTypes() + { + return TypeCache.GetTypesDerivedFrom().ToArray(); + } + + private static string GetWarningIconName(WarningType warningType) + { + return warningType switch + { + WarningType.Info => "d_console.warnicon.inactive.sml", + WarningType.Warning => "d_console.warnicon.sml", + WarningType.Error => "d_console.erroricon.sml", + _ => "d_console.erroricon.inactive.sml", + }; + } + } +} \ No newline at end of file diff --git a/Editor/ValidatorEditorWindow.cs.meta b/Editor/ValidatorEditorWindow.cs.meta new file mode 100644 index 0000000..a89bdc7 --- /dev/null +++ b/Editor/ValidatorEditorWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8f89d88b32f5b7c40a089dbec6b2c406 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Validators.meta b/Editor/Validators.meta new file mode 100644 index 0000000..b15cef4 --- /dev/null +++ b/Editor/Validators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 69e4deb3492cc174aa67baedeefdb790 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Validators/AssetValidator.cs b/Editor/Validators/AssetValidator.cs new file mode 100644 index 0000000..5224223 --- /dev/null +++ b/Editor/Validators/AssetValidator.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace Validator.Editor +{ + public class AssetValidator : IValidator + { + public Report Validate() + { + Report reporter = new Report("AssetValidator"); + + List objects = FindAssetsByType(); + for (int i = 0; i < objects.Count; i++) + { + EditorUtility.DisplayProgressBar("AssetValidator", "Validate...", (float)i / objects.Count); + if (objects[i] is IValidatable validatable) + { + validatable.Validate(reporter); + } + } + EditorUtility.ClearProgressBar(); + + return reporter; + } + + public static List FindAssetsByType() where T : Object + { + List assets = new List(); + string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T))); + + for (int i = 0; i < guids.Length; i++) + { + EditorUtility.DisplayProgressBar("AssetValidator", "FindAssetsByType...", (float)i / guids.Length); + + string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]); + T asset = AssetDatabase.LoadAssetAtPath(assetPath); + if (asset != null) + { + assets.Add(asset); + } + } + EditorUtility.ClearProgressBar(); + + return assets; + } + } +} \ No newline at end of file diff --git a/Editor/Validators/AssetValidator.cs.meta b/Editor/Validators/AssetValidator.cs.meta new file mode 100644 index 0000000..899b835 --- /dev/null +++ b/Editor/Validators/AssetValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 458ef52fac9354e4fb723a3a8645dd2d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Validators/SceneValidator.cs b/Editor/Validators/SceneValidator.cs new file mode 100644 index 0000000..02843b1 --- /dev/null +++ b/Editor/Validators/SceneValidator.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace Validator.Editor +{ + public class SceneValidator : IValidator + { + public Report Validate() + { + Report report = new Report("SceneValidator"); + + List objects = FindAllObjectsOfType(); + for (int i = 0; i < objects.Count; i++) + { + EditorUtility.DisplayProgressBar("SceneValidator", "Validate...", (float)i / objects.Count); + + objects[i].Validate(report); + } + EditorUtility.ClearProgressBar(); + + return report; + } + + private static List GetAllRootGameObjects() + { + List gameObjects = new List(); + + for (int i = 0; i < SceneManager.sceneCount; i++) + { + EditorUtility.DisplayProgressBar("SceneValidator", "GetAllRootGameObjects...", (float)i / SceneManager.sceneCount); + gameObjects.AddRange(SceneManager.GetSceneAt(i).GetRootGameObjects()); + } + EditorUtility.ClearProgressBar(); + + return gameObjects; + } + + private static List FindAllObjectsOfType() + { + List objects = new List(); + + List gameObjects = GetAllRootGameObjects(); + for (int i = 0; i < gameObjects.Count; i++) + { + EditorUtility.DisplayProgressBar("SceneValidator", "FindAllObjectsOfType...", (float)i / gameObjects.Count); + objects.AddRange(gameObjects[i].GetComponentsInChildren(true)); + } + EditorUtility.ClearProgressBar(); + + return objects; + } + } +} \ No newline at end of file diff --git a/Editor/Validators/SceneValidator.cs.meta b/Editor/Validators/SceneValidator.cs.meta new file mode 100644 index 0000000..e272d16 --- /dev/null +++ b/Editor/Validators/SceneValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fced302525286954493f623662b36f33 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/COMPANYNAME.PACKAGENAME.Editor.Tests.asmdef b/Editor/VertexColor.Validator.Editor.asmdef similarity index 59% rename from Tests/Editor/COMPANYNAME.PACKAGENAME.Editor.Tests.asmdef rename to Editor/VertexColor.Validator.Editor.asmdef index ef6c99d..91ac86f 100644 --- a/Tests/Editor/COMPANYNAME.PACKAGENAME.Editor.Tests.asmdef +++ b/Editor/VertexColor.Validator.Editor.asmdef @@ -1,8 +1,8 @@ { - "name": "COMPANYNAME.PACKAGENAME.Editor.Tests", + "name": "Validator.Editor", + "rootNamespace": "Validator.Editor", "references": [ - "COMPANYNAME.PACKAGENAME", - "COMPANYNAME.PACKAGENAME.Editor" + "GUID:334c4fbff44e0f9439f29f9d8e0ce6e9" ], "includePlatforms": [ "Editor" @@ -14,7 +14,5 @@ "autoReferenced": true, "defineConstraints": [], "versionDefines": [], - "optionalUnityReferences": [ - "TestAssemblies" - ] + "noEngineReferences": false } \ No newline at end of file diff --git a/Editor/VertexColor.Validator.Editor.asmdef.meta b/Editor/VertexColor.Validator.Editor.asmdef.meta new file mode 100644 index 0000000..16a87f2 --- /dev/null +++ b/Editor/VertexColor.Validator.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 20d798ece823f744489d29f7453b3315 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/LICENSE.md b/LICENSE.md index b8a0b36..eeec6c1 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 COMPANYNAME +Copyright (c) 2021 Max Kruf Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE.md.meta b/LICENSE.md.meta new file mode 100644 index 0000000..50243f9 --- /dev/null +++ b/LICENSE.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e466f8c2ce68a6a4eaa6a680cb28895b +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index d1a57a1..7eba5d3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,32 @@ -# [COMPANYNAME]() - PACKAGENAME +# Validator -Description. +Unity project validator framework. + +## Getting Started +Open Validator Window: +> Window -> General -> Validator + +Add validatable: +```C# +using Validator; + +public class MyBehaviour : MonoBehaviour, IValidatable +{ + [SerializeField] private float startHealth = 10; // If someone was to put it to low <= 0, it would be invalid. + +#if UNITY_EDITOR + public void Validate(Report report) + { + // Check if health is valid. + if(startHealth <= 0) + { + // If not, log it. + report.Log(this, WarningType.Warning, ReportCategories.Design, $"{nameof(startHealth)} is to low", $"Make value > 0"); + } + } +#endif +} +``` ## Install diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..719ef49 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: fe23a067c33426a459b6554df6d0487e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..192add4 --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2752af9ac554eac43949290d597db9ab +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/IValidatable.cs b/Runtime/IValidatable.cs new file mode 100644 index 0000000..7a864e6 --- /dev/null +++ b/Runtime/IValidatable.cs @@ -0,0 +1,9 @@ +namespace Validator +{ + public interface IValidatable + { +#if UNITY_EDITOR + public void Validate(Report report); +#endif + } +} \ No newline at end of file diff --git a/Runtime/IValidatable.cs.meta b/Runtime/IValidatable.cs.meta new file mode 100644 index 0000000..8d59b67 --- /dev/null +++ b/Runtime/IValidatable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9745876369d865247b2bae9393491734 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Report.cs b/Runtime/Report.cs new file mode 100644 index 0000000..73fe3f8 --- /dev/null +++ b/Runtime/Report.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Validator +{ + public enum WarningType + { + Info, + Warning, + Error, + } + + public class Report + { + public struct ReportMessage + { + public Object Target => target; + public WarningType WarningType => warningType; + public string Category => category; + public string Message => message; + public string Solution => solution; + + private readonly Object target; + private readonly WarningType warningType; + private readonly string category; + private readonly string message; + private readonly string solution; + + public ReportMessage(Object target, WarningType warningLevel, string category, string message, string solution) + { + this.target = target; + this.warningType = warningLevel; + this.category = category; + this.message = message; + this.solution = solution; + } + } + + public string Name => name; + + public IList Reports => reports.AsReadOnly(); + private readonly string name; + private readonly List reports = new List(); + + public Report(string name) + { + this.name = name; + } + + public void Log(ReportMessage report) + { + reports.Add(report); + } + + public void Log(Object target, WarningType warningType, string category, string message, string solution) + { + Log(new ReportMessage(target, warningType, category, message, solution)); + } + } +} \ No newline at end of file diff --git a/Runtime/Report.cs.meta b/Runtime/Report.cs.meta new file mode 100644 index 0000000..2abbc55 --- /dev/null +++ b/Runtime/Report.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d39518e0aab78db47adc586ce678d8a9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ReportCategories.cs b/Runtime/ReportCategories.cs new file mode 100644 index 0000000..4a08f2c --- /dev/null +++ b/Runtime/ReportCategories.cs @@ -0,0 +1,9 @@ +namespace Validator +{ + public static partial class ReportCategories + { + public const string Art = "Art"; + public const string Design = "Design"; + public const string Code = "Code"; + } +} \ No newline at end of file diff --git a/Runtime/ReportCategories.cs.meta b/Runtime/ReportCategories.cs.meta new file mode 100644 index 0000000..7d4944b --- /dev/null +++ b/Runtime/ReportCategories.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d2016a6a28d54304ea9cd64801c4f0b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/RuntimeExample.cs b/Runtime/RuntimeExample.cs deleted file mode 100644 index 9315689..0000000 --- a/Runtime/RuntimeExample.cs +++ /dev/null @@ -1,5 +0,0 @@ -using UnityEngine; - -namespace COMPANYNAME.PACKAGENAME -{ -} \ No newline at end of file diff --git a/Runtime/COMPANYNAME.PACKAGENAME.asmdef b/Runtime/VertexColor.Validator.asmdef similarity index 64% rename from Runtime/COMPANYNAME.PACKAGENAME.asmdef rename to Runtime/VertexColor.Validator.asmdef index 39855df..089d676 100644 --- a/Runtime/COMPANYNAME.PACKAGENAME.asmdef +++ b/Runtime/VertexColor.Validator.asmdef @@ -1,5 +1,6 @@ { - "name": "COMPANYNAME.PACKAGENAME", + "name": "VertexColor.Validator", + "rootNamespace": "Validator", "references": [], "includePlatforms": [], "excludePlatforms": [], @@ -8,5 +9,6 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [] + "versionDefines": [], + "noEngineReferences": false } \ No newline at end of file diff --git a/Runtime/VertexColor.Validator.asmdef.meta b/Runtime/VertexColor.Validator.asmdef.meta new file mode 100644 index 0000000..874dbc6 --- /dev/null +++ b/Runtime/VertexColor.Validator.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 334c4fbff44e0f9439f29f9d8e0ce6e9 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Samples~/Example1/Example.txt b/Samples~/Example1/Example.txt deleted file mode 100644 index d505ef0..0000000 --- a/Samples~/Example1/Example.txt +++ /dev/null @@ -1,2 +0,0 @@ -This is just a template package with a template sample folder structure. -Import of this example file is successful! diff --git a/THIRD PARTY NOTICES.md.meta b/THIRD PARTY NOTICES.md.meta new file mode 100644 index 0000000..1cdaf48 --- /dev/null +++ b/THIRD PARTY NOTICES.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e3e716ef6981e984eb7f8a0196a2dc92 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/TestEditorExample.cs b/Tests/Editor/TestEditorExample.cs deleted file mode 100644 index caf7bbb..0000000 --- a/Tests/Editor/TestEditorExample.cs +++ /dev/null @@ -1,26 +0,0 @@ -using UnityEngine; -using UnityEngine.TestTools; -using UnityEditor; -using System.Collections; -using System.Collections.Generic; -using NUnit.Framework; - -namespace COMPANYNAME.PACKAGENAME.Editor.Tests -{ - public class TestEditorExample - { - [Test] - public void TestEditorExampleSimplePasses() - { - // Use the Assert class to test conditions - } - - [UnityTest] - public IEnumerator TestEditorExampleWithEnumeratorPasses() - { - // Use the Assert class to test conditions. - // Use yield to skip a frame. - yield return null; - } - } -} \ No newline at end of file diff --git a/Tests/Runtime/COMPANYNAME.PACKAGENAME.Tests.asmdef b/Tests/Runtime/COMPANYNAME.PACKAGENAME.Tests.asmdef deleted file mode 100644 index d6c0cd3..0000000 --- a/Tests/Runtime/COMPANYNAME.PACKAGENAME.Tests.asmdef +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "COMPANYNAME.PACKAGENAME.Tests", - "references": [ - "COMPANYNAME.PACKAGENAME" - ], - "includePlatforms": [], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": false, - "precompiledReferences": [], - "autoReferenced": true, - "defineConstraints": [], - "versionDefines": [], - "optionalUnityReferences": [ - "TestAssemblies" - ] -} \ No newline at end of file diff --git a/Tests/Runtime/TestRuntimeExample.cs b/Tests/Runtime/TestRuntimeExample.cs deleted file mode 100644 index bb62108..0000000 --- a/Tests/Runtime/TestRuntimeExample.cs +++ /dev/null @@ -1,25 +0,0 @@ -using UnityEngine; -using UnityEngine.TestTools; -using System.Collections; -using System.Collections.Generic; -using NUnit.Framework; - -namespace COMPANYNAME.PACKAGENAME.Tests -{ - public class TestRuntimeExample - { - [Test] - public void TestRuntimeExampleSimplePasses() - { - // Use the Assert class to test conditions - } - - [UnityTest] - public IEnumerator TestRuntimeExampleEnumeratorPasses() - { - // Use the Assert class to test conditions. - // Use yield to skip a frame. - yield return null; - } - } -} diff --git a/package.json b/package.json index 5c6f7f8..99d111e 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,9 @@ { - "name": "com.COMPANYNAME.PACKAGENAME", - "displayName": "Template Unity Package", + "name": "com.vertexcolor.validator", + "displayName": "Validator", "version": "0.1.0", "unity": "2019.3", - "unityRelease": "7f1", - "description": "This is a template package, used as a basis to build a bigger one.", + "description": "Unity project validator framework.", "category": "Tool", "type": "tool", "license": "MIT", @@ -13,18 +12,7 @@ "email": "info@maxartz15.com", "url": "https://www.maxartz15.com" }, - "dependencies": { - "com.maxartz15.package1": "0.1.0" - }, "keywords": [ - "COMPANYNAME", - "PACKAGENAME" - ], - "samples": [ - { - "displayName": "Example 1", - "description": "This sample is just an example", - "path": "Samples~/Example1" - } + "Validator" ] } diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..3653ed9 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 84601f755fc0e304f85a3ebf67e1601b +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: