From 9faf5d9f322e8da7c69d1bced6548242f830e34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Kurai?= Date: Fri, 15 Oct 2021 13:02:57 +0200 Subject: [PATCH 1/3] add some code documentation --- .../Extensions/EnumerableExtensions.cs | 8 ---- .../Editor/Generation/IModuleGenerator.cs | 10 +++++ .../Editor/Generation/IResourceData.cs | 17 ++++++++- .../Generation/IResourcePostProcessor.cs | 13 +++++++ .../Editor/Generation/Modules/AllResources.cs | 5 +++ .../PostProcessors/RemoveDuplicateNewLines.cs | 3 ++ .../Editor/Generation/ResourceContext.cs | 37 ++++++++++++++++++- .../Generation/ResourceFileGenerator.cs | 5 +++ 8 files changed, 88 insertions(+), 10 deletions(-) diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Extensions/EnumerableExtensions.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Extensions/EnumerableExtensions.cs index 4c61e0a..896c30d 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Extensions/EnumerableExtensions.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Extensions/EnumerableExtensions.cs @@ -19,13 +19,5 @@ private static bool IsMultiple(this IEnumerable source) var enumerator = source.GetEnumerator(); return enumerator.MoveNext() && enumerator.MoveNext(); } - - public static void ForEach(this IEnumerable enumerable, Action action) - { - foreach (var item in enumerable) - { - action(item); - } - } } } diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IModuleGenerator.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IModuleGenerator.cs index d48aa9c..08ac98c 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IModuleGenerator.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IModuleGenerator.cs @@ -1,7 +1,17 @@ namespace AutSoft.UnityResourceGenerator.Editor.Generation { + /// + /// Used by the file generation pipeline. + /// Implement this interface to create a piece of string that you want to see in the generated file + /// public interface IModuleGenerator { + /// + /// Create a piece of code as part of the generated file. + /// Could be static methods, properties, fields or inner classes + /// + /// User configured settings and logger + /// Generated code module string Generate(ResourceContext context); } } diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourceData.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourceData.cs index 7ee24cc..96bbf23 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourceData.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourceData.cs @@ -1,11 +1,26 @@ -using System.Collections.Generic; +using AutSoft.UnityResourceGenerator.Editor.Generation.Modules; +using System.Collections.Generic; namespace AutSoft.UnityResourceGenerator.Editor.Generation { + /// + /// Data used by + /// public interface IResourceData { + /// + /// Name of the generated class + /// string ClassName { get; } + + /// + /// File extensions to look for. + /// IReadOnlyList FileExtensions { get; } + + /// + /// Data type returned by Resources.Load + /// string DataType { get; } } } \ No newline at end of file diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourcePostProcessor.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourcePostProcessor.cs index b09e7f7..0e21a73 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourcePostProcessor.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/IResourcePostProcessor.cs @@ -1,8 +1,21 @@ namespace AutSoft.UnityResourceGenerator.Editor.Generation { + /// + /// Implement this interface to do post processing of the generated file + /// public interface IResourcePostProcessor { + /// + /// Priority during post processing. Higher number means it will run before others + /// int PostProcessPriority { get; } + + /// + /// Does post processing of the generated file + /// + /// User configured settings and logger + /// The current state of the generated file + /// The next state of the generated file string PostProcess(ResourceContext context, string resourceFileContent); } } \ No newline at end of file diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Modules/AllResources.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Modules/AllResources.cs index 40b993d..a703025 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Modules/AllResources.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Modules/AllResources.cs @@ -8,6 +8,11 @@ namespace AutSoft.UnityResourceGenerator.Editor.Generation.Modules { + /// + /// Generates code for all known and loadable Unity resource files. + /// Each loadable type is produced as a static class. + /// Also creates code for loading scenes + /// public sealed class AllResources : IModuleGenerator { private static readonly Regex NonAlphaNumeric = new Regex(@"[^a-zA-Z0-9]", RegexOptions.Compiled, TimeSpan.FromSeconds(1)); diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/PostProcessors/RemoveDuplicateNewLines.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/PostProcessors/RemoveDuplicateNewLines.cs index 3862251..5d335f1 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/PostProcessors/RemoveDuplicateNewLines.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/PostProcessors/RemoveDuplicateNewLines.cs @@ -3,6 +3,9 @@ namespace AutSoft.UnityResourceGenerator.Editor.Generation.PostProcessors { + /// + /// Removes duplicate newlines + /// public sealed class RemoveDuplicateNewLines : IResourcePostProcessor { private static readonly Regex MultipleNewLines = new Regex(@"(?:\r\n|\r(?!\n)|(?!<\r)\n){2,}", RegexOptions.Compiled, TimeSpan.FromSeconds(10)); diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceContext.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceContext.cs index 28be47a..384784b 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceContext.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceContext.cs @@ -1,8 +1,12 @@ -using System; +using AutSoft.UnityResourceGenerator.Editor.Generation.Modules; +using System; using System.Collections.Generic; namespace AutSoft.UnityResourceGenerator.Editor.Generation { + /// + /// User defined settings and data and loggers + /// public sealed class ResourceContext { public ResourceContext @@ -26,14 +30,45 @@ public ResourceContext Usings = usings; } + /// + /// Full path to the Unity Assets folder + /// public string AssetsFolder { get; } + + /// + /// User defined path to the desired relative folder from the + /// public string FolderPath { get; } + + /// + /// User defined namespace of the generated file + /// public string BaseNamespace { get; } + + /// + /// User defined class name of the generated file + /// public string ClassName { get; } + + /// + /// Info level logger + /// public Action Info { get; } + + /// + /// Error level logger + /// public Action Error { get; } + + /// + /// Data used by + /// public IReadOnlyList Data { get; } + + /// + /// User defined custom usings + /// public IReadOnlyList Usings { get; } } } diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceFileGenerator.cs b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceFileGenerator.cs index 38d7d07..77825ed 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceFileGenerator.cs +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceFileGenerator.cs @@ -10,6 +10,11 @@ public static class ResourceFileGenerator { private static readonly Regex NormalizedLineEndings = new Regex(@"\r\n|\n\r|\n|\r", RegexOptions.Compiled, TimeSpan.FromSeconds(10)); + /// + /// Main generator. Loads and calls all implementations of and + /// + /// Resource context from settings + /// The generated file content public static string CreateResourceFile(ResourceContext context) { // ReSharper disable once MissingIndent From 708986a7b114a14d313943dde0529f87082a4756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Kurai?= Date: Fri, 15 Oct 2021 13:08:40 +0200 Subject: [PATCH 2/3] forgotten nuke properties --- .nuke/build.schema.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 0a07d8b..b9a6d8c 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -77,7 +77,6 @@ "enum": [ "BuildDocs", "Compile", - "CreateGithubRelease", "CreateMetadata", "GenerateUnitySolution", "Restore", @@ -94,7 +93,6 @@ "enum": [ "BuildDocs", "Compile", - "CreateGithubRelease", "CreateMetadata", "GenerateUnitySolution", "Restore", From b2ad7a0b90be97615fefa3cffa34f7c51ce05abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Kurai?= Date: Fri, 15 Oct 2021 13:09:35 +0200 Subject: [PATCH 3/3] add changelog, bump version --- CHANGELOG.md | 3 +++ .../Assets/AutSoft.UnityResourceGenerator/package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff39224..55705f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.0.1 +- Add documentation comments + # 1.0.0 - Version bump, same as 0.5.0 after manual testing diff --git a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/package.json b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/package.json index 5ca6c4b..e56d10e 100644 --- a/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/package.json +++ b/UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/package.json @@ -1,6 +1,6 @@ { "name": "com.autsoft.unityresourcegenerator", - "version": "1.0.0", + "version": "1.0.1", "displayName": "Unity Resource Generator", "description": "Generate path strings for Resources.Load", "license": "MIT",