Skip to content

Commit 089ddc2

Browse files
committed
Started generating keywords from field names
Since more fields are to be added to the settings, it becomes tedious to update the keywords each time. This approach will generate keywords on fly.
1 parent 4adf012 commit 089ddc2

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

Editor/Settings/SettingsDrawer.cs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,65 @@
88

99
internal static class SettingsDrawer
1010
{
11-
private static readonly GUIContent _buildStrippingName = new GUIContent("Build Stripping Type");
11+
/// <summary>
12+
/// Field names of corresponding settings. Each field name can be accessed by the name of the setting variable.
13+
/// </summary>
14+
private static readonly Dictionary<string, string> _fieldNames = new Dictionary<string, string>
15+
{
16+
{ nameof(StripSettings.PlayMode), "Play Mode Stripping Type" },
17+
{ nameof(StripSettings.Build), "Build Stripping Type" },
18+
{ nameof(StripSettings.CapitalizeName), "Capitalize Folder Names" }
19+
};
20+
21+
private static readonly GUIContent _buildStrippingName = new GUIContent(_fieldNames[nameof(StripSettings.Build)]);
1222

1323
[SettingsProvider]
1424
public static SettingsProvider CreateSettingsProvider()
1525
{
1626
var provider = new SettingsProvider("Preferences/Hierarchy Folders", SettingsScope.User)
1727
{
18-
guiHandler = searchContext =>
19-
{
20-
StripSettings.PlayMode = (StrippingMode) EditorGUILayout.EnumPopup(
21-
"Play Mode Stripping Type", StripSettings.PlayMode);
22-
23-
if (StripSettings.PlayMode == StrippingMode.ReplaceWithSeparator)
24-
{
25-
StripSettings.CapitalizeName =
26-
EditorGUILayout.Toggle("Capitalize Folder Names", StripSettings.CapitalizeName);
27-
}
28-
29-
StripSettings.Build = (StrippingMode) EditorGUILayout.EnumPopup(
30-
_buildStrippingName, StripSettings.Build, TypeCanBeInBuild, true);
31-
},
32-
33-
keywords = new HashSet<string>(new[] { "Play", "Mode", "Build", "Stripping", "Type", "Capitalize", "Folder", "Names" })
28+
guiHandler = OnGUI,
29+
keywords = GetKeywords()
3430
};
3531

3632
return provider;
3733
}
3834

35+
private static void OnGUI(string searchContext)
36+
{
37+
StripSettings.PlayMode = (StrippingMode) EditorGUILayout.EnumPopup(
38+
_fieldNames[nameof(StripSettings.PlayMode)], StripSettings.PlayMode);
39+
40+
if (StripSettings.PlayMode == StrippingMode.ReplaceWithSeparator)
41+
{
42+
StripSettings.CapitalizeName = EditorGUILayout.Toggle(
43+
_fieldNames[nameof(StripSettings.CapitalizeName)], StripSettings.CapitalizeName);
44+
}
45+
46+
StripSettings.Build = (StrippingMode) EditorGUILayout.EnumPopup(
47+
_buildStrippingName, StripSettings.Build, TypeCanBeInBuild, true);
48+
}
49+
50+
private static HashSet<string> GetKeywords()
51+
{
52+
var keywords = new HashSet<string>();
53+
54+
foreach (string fieldName in _fieldNames.Values)
55+
{
56+
keywords.AddWords(fieldName);
57+
}
58+
59+
return keywords;
60+
}
61+
62+
private static void AddWords(this HashSet<string> set, string phrase)
63+
{
64+
foreach (string word in phrase.Split(' '))
65+
{
66+
set.Add(word);
67+
}
68+
}
69+
3970
private static bool TypeCanBeInBuild(Enum enumValue)
4071
{
4172
var mode = (StrippingMode) enumValue;

0 commit comments

Comments
 (0)