Skip to content

Commit 6a1e6b9

Browse files
author
András Kurai
committed
make adding namespace optional
1 parent e7ade44 commit 6a1e6b9

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# 0.1.1
1+
# 0.2.0
22
- Add documentation website
3-
- Reference website in `package.json`
3+
- Reference documentation in `package.json`
4+
- Make using namespaces optional
45

56
# 0.1.0
67
- Add initial project

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/Generation/ResourceFileGenerator.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class ResourceFileGenerator
1010
public static string CreateResourceFile(ResourceContext context)
1111
{
1212
// ReSharper disable once MissingIndent
13-
const string fileBegin =
13+
const string fileBeginHasNamespace =
1414
@"
1515
using UnityEngine;
1616
using UnityEngine.SceneManagement;
@@ -22,10 +22,22 @@ public static partial class {1}
2222
{";
2323

2424
// ReSharper disable once MissingIndent
25-
const string fileEnd =
25+
const string fileEndHasNamespace =
2626
@" }
2727
}";
2828

29+
// ReSharper disable once MissingIndent
30+
const string fileBeginNoNamespace =
31+
@"
32+
using UnityEngine;
33+
using UnityEngine.SceneManagement;
34+
35+
// ReSharper disable PartialTypeWithSinglePart
36+
public static partial class {1}
37+
{";
38+
39+
const string fileEndNoNamespace = "}";
40+
2941
var builder = new StringBuilder();
3042

3143
var allConcreteTypes = AppDomain
@@ -36,17 +48,17 @@ public static partial class {1}
3648
.ToArray();
3749

3850
builder.AppendLine(
39-
fileBegin
40-
.Replace("{0}", context.BaseNamespace)
41-
.Replace("{1}", context.ClassName));
51+
(string.IsNullOrWhiteSpace(context.BaseNamespace) ? fileBeginNoNamespace : fileBeginHasNamespace)
52+
.Replace("{0}", context.BaseNamespace)
53+
.Replace("{1}", context.ClassName));
4254

4355
allConcreteTypes
4456
.Where(t => t.GetInterfaces().Any(i => typeof(IModuleGenerator).IsAssignableFrom(i)))
4557
.Select(t => (IModuleGenerator)Activator.CreateInstance(t))
4658
.Select(m => m.Generate(context))
4759
.ForEach(m => builder.AppendLine(m));
4860

49-
builder.AppendLine(fileEnd);
61+
builder.AppendLine(string.IsNullOrWhiteSpace(context.BaseNamespace) ? fileEndNoNamespace : fileEndHasNamespace);
5062

5163
var fileContent = builder.ToString();
5264

UnityResourceGenerator/Assets/AutSoft.UnityResourceGenerator/Editor/ResourceGeneratorSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static ResourceGeneratorSettings GetOrCreateSettings()
6363
settings = CreateInstance<ResourceGeneratorSettings>();
6464

6565
settings._folderPath = string.Empty;
66-
settings._baseNamespace = "Resources";
66+
settings._baseNamespace = string.Empty;
6767
settings._className = "ResourcePaths";
6868
settings._logInfo = false;
6969
settings._logError = true;

0 commit comments

Comments
 (0)