Skip to content

Commit c799e5e

Browse files
authored
Merge pull request #5 from AutSoft/develop
0.3.0
2 parents e07a93e + 85de654 commit c799e5e

File tree

79 files changed

+12596
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+12596
-115
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v2
1414

15-
- name: Publish LinkerGenerator to openupm
15+
- name: Publish UnityResourceGenerator to OpenUPM
1616
uses: butlerlogic/action-autotag@stable
1717
with:
1818
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
1919
root: "UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator"
20-
21-
- name: Create GitHub Release
22-
shell: pwsh
23-
run: ./build.ps1 CreateGithubRelease --is-ci

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 0.3.0
2+
- Support for files with non-alphanumeric characters
3+
- Support for file starting with numeric characters
4+
- Update documentation with name generation rules
5+
16
# 0.2.0
27
- Add documentation website
38
- Reference documentation in `package.json`

Documentation/articles/GettingStarted.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ The tool will create new button in the Editor at `Tools / Generate Resource Path
1919
![Generate Button](~/images/intro/GenerateButton.png)
2020

2121
If your click the button the helper class will be generated in the root of the `Assets` folder
22+
23+
## Name generation rules
24+
25+
The generated method and filed names are slightly different from the actual file names, because not all valid file names are valid C# identifier names. The following rules apply:
26+
27+
- Whitespaces are removed
28+
- If the file name starts with a number a `_` character is added to the start of the identifier
29+
- All non-alphanumeric characters are replaced by the `_` character

Documentation/articles/KnownIssues.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.1.0 - *
44

5+
- Duplicate file names in the same class module will break the generated file. The solution for this requires further investigation
6+
7+
## 0.1.0 - 0.2.0: Fixed in 0.3.0
8+
59
- SpecialCharacters can break generated names.
610
- Numbers at the end of the files are supported, but not at the start
711
- Any character in the filename which would not be a valid C# filed/property/method name will break the generated code
@@ -12,5 +16,3 @@
1216
- `1Coin` does not
1317
- `!Coin` does not
1418
- `Coin!` does not
15-
16-
- Duplicate file names in the same class module will break the generated file. The solution for this requires further investigation

UnityResourceGenerator.Build/Build.cs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
using Nuke.Common.IO;
33
using Nuke.Common.Tooling;
44
using Nuke.Common.Tools.MSBuild;
5-
using Nuke.Common.Utilities.Collections;
65
using System;
76
using System.IO;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Text.Json;
117
using System.Text.RegularExpressions;
128
using System.Threading.Tasks;
139
using static Nuke.Common.Tools.DocFX.DocFXTasks;
14-
using static Nuke.Common.Tools.Git.GitTasks;
1510
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
1611
using static Nuke.Common.Tools.Unity.UnityTasks;
1712
using static UnityHelper;
@@ -22,8 +17,6 @@ class Build : NukeBuild
2217

2318
public static int Main() => Execute<Build>(x => x.Compile);
2419

25-
[PathExecutable] readonly Tool Gh = default!;
26-
2720
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
2821
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
2922

@@ -33,9 +26,6 @@ class Build : NukeBuild
3326

3427
[Parameter("Are we running in CI")] bool IsCi = false;
3528

36-
string CurrentVersion { get; set; } = default!;
37-
bool IsNewestVersion { get; set; }
38-
3929
static AbsolutePath UnityProjectPath => RootDirectory / "UnityResourceGenerator";
4030
static AbsolutePath UnitySolution => UnityProjectPath / "UnityResourceGenerator.sln";
4131

@@ -123,66 +113,4 @@ async Task GenerateSolution()
123113
Target ServeDocs => _ => _
124114
.DependsOn(BuildDocs)
125115
.Executes(() => DocFX($"{DocFxJsonPath} --serve"));
126-
127-
Target CreateGithubRelease => _ => _
128-
.OnlyWhenDynamic(() => IsNewestVersion)
129-
.OnlyWhenDynamic(() => IsCi)
130-
.Executes(() =>
131-
{
132-
var version = CurrentVersion;
133-
134-
var notes = File.ReadAllLines(RootDirectory / "CHANGELOG.md")
135-
.Skip(1)
136-
.TakeUntil(string.IsNullOrWhiteSpace)
137-
.Aggregate(new StringBuilder(), (sb, l) => sb.AppendLine(l))
138-
.ToString();
139-
140-
Gh($"release create {version} -t {version} -n \"{notes}\"");
141-
});
142-
143-
144-
protected override void OnBuildInitialized()
145-
{
146-
bool GetIsNewestVersion()
147-
{
148-
var currentVersion = new Version(CurrentVersion);
149-
150-
GitLogger = (_, s) => Logger.Info(s);
151-
152-
Git("fetch --tags");
153-
154-
var maxPublishedVersion = Git("tag")
155-
.Select(o => new Version(o.Text))
156-
.OrderBy(v => v)
157-
.LastOrDefault();
158-
159-
return currentVersion.CompareTo(maxPublishedVersion) > 0;
160-
}
161-
162-
string GetCurrentVersion()
163-
{
164-
var packagePath = UnityProjectPath / "Assets" / "AutSoft.UnityResourceGenerator" / "package.json";
165-
166-
if (!File.Exists(packagePath)) throw new InvalidOperationException($"package.json does not exist at path: {packagePath}");
167-
168-
var jsonContent = File.ReadAllText(packagePath);
169-
var package = JsonSerializer.Deserialize<PackageJson>(jsonContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
170-
171-
if (package?.Version is null) throw new InvalidOperationException($"Cloud not deserialize package.json:{Environment.NewLine}{jsonContent}");
172-
173-
return package.Version;
174-
}
175-
176-
CurrentVersion = GetCurrentVersion();
177-
IsNewestVersion = GetIsNewestVersion();
178-
179-
base.OnBuildInitialized();
180-
}
181-
182-
sealed class PackageJson
183-
{
184-
public PackageJson(string version) => Version = version;
185-
186-
public string Version { get; }
187-
}
188116
}

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator.Sample/ResourcePaths.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using UnityEngine;
22
using UnityEngine.SceneManagement;
3+
34
namespace AutSoft.UnityResourceGenerator.Sample
45
{
56
// ReSharper disable PartialTypeWithSinglePart
7+
// ReSharper disable InconsistentNaming
68
public static partial class ResourcePaths
79
{
10+
811
public static partial class Scenes
912
{
1013
public const string CreatePrefab = "AutSoft.UnityResourceGenerator.Sample/Scenes/CreatePrefab";
@@ -17,24 +20,49 @@ public static partial class Scenes
1720
public static void LoadLoadSceneNext(LoadSceneMode mode = LoadSceneMode.Single) => SceneManager.LoadScene(LoadSceneNext, mode);
1821
public static AsyncOperation LoadAsyncLoadSceneNext(LoadSceneMode mode = LoadSceneMode.Single) => SceneManager.LoadSceneAsync(LoadSceneNext, mode);
1922
}
23+
24+
2025
public static partial class Prefabs
2126
{
2227
public const string Cube = "Cube";
2328
public static GameObject LoadCube() => Resources.Load<GameObject>(Cube);
2429
}
30+
31+
2532
public static partial class Materials
2633
{
2734
public const string Cube = "Cube";
2835
public static Material LoadCube() => Resources.Load<Material>(Cube);
2936
public const string CubeAlt = "CubeAlt";
3037
public static Material LoadCubeAlt() => Resources.Load<Material>(CubeAlt);
38+
public const string LiberationSansSDF_DropShadow = "Fonts & Materials/LiberationSans SDF - Drop Shadow";
39+
public static Material LoadLiberationSansSDF_DropShadow() => Resources.Load<Material>(LiberationSansSDF_DropShadow);
40+
public const string LiberationSansSDF_Outline = "Fonts & Materials/LiberationSans SDF - Outline";
41+
public static Material LoadLiberationSansSDF_Outline() => Resources.Load<Material>(LiberationSansSDF_Outline);
3142
}
43+
44+
3245
public static partial class AudioClips
3346
{
3447
public const string CoinSpin = "Coin Spin";
3548
public static AudioClip LoadCoinSpin() => Resources.Load<AudioClip>(CoinSpin);
49+
public const string _1Coin1 = "1Coin 1";
50+
public static AudioClip Load_1Coin1() => Resources.Load<AudioClip>(_1Coin1);
3651
public const string Coin = "Coin";
3752
public static AudioClip LoadCoin() => Resources.Load<AudioClip>(Coin);
3853
}
54+
55+
56+
57+
public static partial class TextAssets
58+
{
59+
public const string LineBreakingFollowingCharacters = "LineBreaking Following Characters";
60+
public static TextAsset LoadLineBreakingFollowingCharacters() => Resources.Load<TextAsset>(LineBreakingFollowingCharacters);
61+
public const string LineBreakingLeadingCharacters = "LineBreaking Leading Characters";
62+
public static TextAsset LoadLineBreakingLeadingCharacters() => Resources.Load<TextAsset>(LineBreakingLeadingCharacters);
63+
}
64+
65+
66+
3967
}
4068
}
Binary file not shown.

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator.Sample/Resources/1Coin 1.wav.meta

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/Modules/AllResources.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7+
using System.Text.RegularExpressions;
78

89
namespace AutSoft.UnityResourceGenerator.Editor.Generation.Modules
910
{
1011
public sealed class AllResources : IModuleGenerator
1112
{
13+
private static readonly Regex NonAlphaNumeric = new Regex(@"[^a-zA-Z0-9]", RegexOptions.Compiled, TimeSpan.FromSeconds(1));
14+
private static readonly Regex StartsWithNumber = new Regex(@"^\d", RegexOptions.Compiled, TimeSpan.FromSeconds(1));
15+
1216
public string Generate(ResourceContext context) =>
1317
new StringBuilder()
1418
.AppendMultipleLines(context.Data.Select(d => Generate(context, d)))
@@ -47,9 +51,15 @@ public static partial class {data.ClassName}
4751
)
4852
.Replace('\\', '/');
4953

54+
var name = Path.GetFileNameWithoutExtension(filePath).Replace(" ", string.Empty);
55+
56+
if (StartsWithNumber.IsMatch(name)) name = name.Insert(0, "_");
57+
58+
name = NonAlphaNumeric.Replace(name, "_");
59+
5060
return
5161
(
52-
name: Path.GetFileNameWithoutExtension(filePath).Replace(" ", string.Empty),
62+
name,
5363
path: resourcePath,
5464
fileExtension: Path.GetExtension(filePath)
5565
);

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/PostProcessors.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)