Skip to content

Commit 177a4ce

Browse files
author
András Kurai
committed
Merge branch 'feature/fix-non-alphanumeric-characters' into develop
2 parents 8111736 + 60f88e4 commit 177a4ce

File tree

77 files changed

+12595
-38
lines changed

Some content is hidden

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

77 files changed

+12595
-38
lines changed

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/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.

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/PostProcessors/RemoveUnnecessaryNewLines.cs

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

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

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

0 commit comments

Comments
 (0)