Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"enum": [
"BuildDocs",
"Compile",
"CreateGithubRelease",
"CreateMetadata",
"GenerateUnitySolution",
"Restore",
Expand All @@ -94,7 +93,6 @@
"enum": [
"BuildDocs",
"Compile",
"CreateGithubRelease",
"CreateMetadata",
"GenerateUnitySolution",
"Restore",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.0.1
- Add documentation comments

# 1.0.0
- Version bump, same as 0.5.0 after manual testing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,5 @@ private static bool IsMultiple<T>(this IEnumerable<T> source)
var enumerator = source.GetEnumerator();
return enumerator.MoveNext() && enumerator.MoveNext();
}

public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
{
foreach (var item in enumerable)
{
action(item);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
namespace AutSoft.UnityResourceGenerator.Editor.Generation
{
/// <summary>
/// Used by the file generation pipeline.
/// Implement this interface to create a piece of string that you want to see in the generated file
/// </summary>
public interface IModuleGenerator
{
/// <summary>
/// Create a piece of code as part of the generated file.
/// Could be static methods, properties, fields or inner classes
/// </summary>
/// <param name="context">User configured settings and logger</param>
/// <returns>Generated code module</returns>
string Generate(ResourceContext context);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
using System.Collections.Generic;
using AutSoft.UnityResourceGenerator.Editor.Generation.Modules;
using System.Collections.Generic;

namespace AutSoft.UnityResourceGenerator.Editor.Generation
{
/// <summary>
/// Data used by <see cref="AllResources"/>
/// </summary>
public interface IResourceData
{
/// <summary>
/// Name of the generated class
/// </summary>
string ClassName { get; }

/// <summary>
/// File extensions to look for.
/// </summary>
IReadOnlyList<string> FileExtensions { get; }

/// <summary>
/// Data type returned by Resources.Load
/// </summary>
string DataType { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
namespace AutSoft.UnityResourceGenerator.Editor.Generation
{
/// <summary>
/// Implement this interface to do post processing of the generated file
/// </summary>
public interface IResourcePostProcessor
{
/// <summary>
/// Priority during post processing. Higher number means it will run before others
/// </summary>
int PostProcessPriority { get; }

/// <summary>
/// Does post processing of the generated file
/// </summary>
/// <param name="context">User configured settings and logger</param>
/// <param name="resourceFileContent">The current state of the generated file</param>
/// <returns>The next state of the generated file</returns>
string PostProcess(ResourceContext context, string resourceFileContent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

namespace AutSoft.UnityResourceGenerator.Editor.Generation.Modules
{
/// <summary>
/// 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
/// </summary>
public sealed class AllResources : IModuleGenerator
{
private static readonly Regex NonAlphaNumeric = new Regex(@"[^a-zA-Z0-9]", RegexOptions.Compiled, TimeSpan.FromSeconds(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace AutSoft.UnityResourceGenerator.Editor.Generation.PostProcessors
{
/// <summary>
/// Removes duplicate newlines
/// </summary>
public sealed class RemoveDuplicateNewLines : IResourcePostProcessor
{
private static readonly Regex MultipleNewLines = new Regex(@"(?:\r\n|\r(?!\n)|(?!<\r)\n){2,}", RegexOptions.Compiled, TimeSpan.FromSeconds(10));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using AutSoft.UnityResourceGenerator.Editor.Generation.Modules;
using System;
using System.Collections.Generic;

namespace AutSoft.UnityResourceGenerator.Editor.Generation
{
/// <summary>
/// User defined settings and data and loggers
/// </summary>
public sealed class ResourceContext
{
public ResourceContext
Expand All @@ -26,14 +30,45 @@ public ResourceContext
Usings = usings;
}

/// <summary>
/// Full path to the Unity Assets folder
/// </summary>
public string AssetsFolder { get; }

/// <summary>
/// User defined path to the desired relative folder from the <see cref="AssetsFolder"/>
/// </summary>
public string FolderPath { get; }

/// <summary>
/// User defined namespace of the generated file
/// </summary>
public string BaseNamespace { get; }

/// <summary>
/// User defined class name of the generated file
/// </summary>
public string ClassName { get; }

/// <summary>
/// Info level logger
/// </summary>
public Action<string> Info { get; }

/// <summary>
/// Error level logger
/// </summary>
public Action<string> Error { get; }


/// <summary>
/// Data used by <see cref="AllResources"/>
/// </summary>
public IReadOnlyList<IResourceData> Data { get; }

/// <summary>
/// User defined custom usings
/// </summary>
public IReadOnlyList<string> Usings { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));

/// <summary>
/// Main generator. Loads and calls all implementations of <see cref="IModuleGenerator"/> and <see cref="IResourcePostProcessor"/>
/// </summary>
/// <param name="context">Resource context from settings</param>
/// <returns>The generated file content</returns>
public static string CreateResourceFile(ResourceContext context)
{
// ReSharper disable once MissingIndent
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down