Skip to content

Commit cd68d2f

Browse files
committed
Uses com.nomnom.easier-custom-preferences for the pref window
1 parent 69a6216 commit cd68d2f

3 files changed

Lines changed: 52 additions & 66 deletions

File tree

Editor/PreferenceWindow.cs

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,74 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using Nomnom.EasierCustomPreferences.Editor;
34
using UnityEditor;
45
using UnityEngine;
56

67
namespace Nomnom.ProjectWindowExtensions.Editor {
8+
[PreferencesName("Project Window Extensions")]
9+
[PreferencesKeyword("Project", "Window", "Extensions")]
710
internal static class PreferenceWindow {
811
private const string DEF_COPY_PASTE = "NOM_PROJECT_COPY_PASTE";
912
private const string DEF_MORE_FILES = "NOM_PROJECT_MORE_FILES";
10-
11-
private static ProjectWindowSettingsHandler.Settings _currentSettings;
1213

13-
[SettingsProvider]
14-
public static SettingsProvider CreateProvider() {
15-
_currentSettings = ProjectWindowSettingsHandler.GetEditorSettings();
16-
17-
var provider = new SettingsProvider("Preferences/Project Window Extensions", SettingsScope.User) {
18-
label = "Project Window Extensions",
19-
20-
guiHandler = searchContext => {
21-
ProjectWindowGUI.Draw(_currentSettings);
22-
23-
if (GUILayout.Button("Apply")) {
24-
ProjectWindowSettingsHandler.SetEditorSettings(_currentSettings);
25-
26-
// update preprocessors
27-
string definesString =
28-
PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
29-
List<string> allDefines = definesString.Split(';').ToList();
30-
31-
bool containsCopyPaste = allDefines.Contains(DEF_COPY_PASTE);
32-
bool containsMoreFiles = allDefines.Contains(DEF_MORE_FILES);
33-
34-
if (containsCopyPaste && !_currentSettings.UseCopyPaste) {
35-
allDefines.Remove(DEF_COPY_PASTE);
36-
} else if (!containsCopyPaste && _currentSettings.UseCopyPaste) {
37-
allDefines.Add(DEF_COPY_PASTE);
38-
}
39-
40-
if (containsMoreFiles && !_currentSettings.UseAdditionalFiles) {
41-
allDefines.Remove(DEF_MORE_FILES);
42-
} else if (!containsMoreFiles && _currentSettings.UseAdditionalFiles) {
43-
allDefines.Add(DEF_MORE_FILES);
44-
}
45-
46-
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", allDefines));
47-
AssetDatabase.Refresh();
48-
}
49-
},
50-
51-
// Keywords for the search bar in the Unity Preferences menu
52-
keywords = new HashSet<string>(new[] {"Project", "Window", "Extensions"})
53-
};
54-
55-
return provider;
56-
}
57-
}
58-
59-
internal sealed class ProjectWindowSettingsHandler {
6014
private const string KEY_USE_COPY_PASTE = "nomnom.project-window-extensions.use-copy-paste";
6115
private const string KEY_USE_ADDITIONAL_FILES = "nomnom.project-window-extensions.use-additional-files";
16+
17+
private static GUIContent _useCopyPasteText = new GUIContent("Use Copy/Paste");
18+
private static GUIContent _useAdditionalFilesText = new GUIContent("Use Additional Files");
19+
20+
[SettingsProvider]
21+
public static SettingsProvider CreateProvider() => CustomPreferences.GetProvider(typeof(PreferenceWindow), false);
6222

63-
public static Settings GetEditorSettings() {
23+
public static Settings OnDeserialize() {
6424
return new Settings {
6525
UseCopyPaste = EditorPrefs.GetBool(KEY_USE_COPY_PASTE, true),
6626
UseAdditionalFiles = EditorPrefs.GetBool(KEY_USE_ADDITIONAL_FILES, true),
6727
};
6828
}
6929

70-
public static void SetEditorSettings(Settings settings) {
30+
public static void OnSerialize(Settings settings) {
7131
EditorPrefs.SetBool(KEY_USE_COPY_PASTE, settings.UseCopyPaste);
7232
EditorPrefs.SetBool(KEY_USE_ADDITIONAL_FILES, settings.UseAdditionalFiles);
7333
}
34+
35+
public static void OnGUI(string searchContext, Settings obj) {
36+
EditorGUI.indentLevel++;
37+
obj.UseCopyPaste = EditorGUILayout.ToggleLeft(_useCopyPasteText, obj.UseCopyPaste);
38+
obj.UseAdditionalFiles = EditorGUILayout.ToggleLeft(_useAdditionalFilesText, obj.UseAdditionalFiles);
39+
EditorGUI.indentLevel--;
40+
41+
if (GUILayout.Button("Apply")) {
42+
OnSerialize(obj);
43+
44+
// update preprocessors
45+
string definesString =
46+
PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
47+
List<string> allDefines = definesString.Split(';').ToList();
7448

49+
bool containsCopyPaste = allDefines.Contains(DEF_COPY_PASTE);
50+
bool containsMoreFiles = allDefines.Contains(DEF_MORE_FILES);
51+
52+
if (containsCopyPaste && !obj.UseCopyPaste) {
53+
allDefines.Remove(DEF_COPY_PASTE);
54+
} else if (!containsCopyPaste && obj.UseCopyPaste) {
55+
allDefines.Add(DEF_COPY_PASTE);
56+
}
57+
58+
if (containsMoreFiles && !obj.UseAdditionalFiles) {
59+
allDefines.Remove(DEF_MORE_FILES);
60+
} else if (!containsMoreFiles && obj.UseAdditionalFiles) {
61+
allDefines.Add(DEF_MORE_FILES);
62+
}
63+
64+
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", allDefines));
65+
AssetDatabase.Refresh();
66+
}
67+
}
68+
7569
internal sealed class Settings {
7670
public bool UseCopyPaste;
7771
public bool UseAdditionalFiles;
7872
}
7973
}
80-
81-
internal static class ProjectWindowGUI {
82-
private static GUIContent _useCopyPasteText = new GUIContent("Use Copy/Paste");
83-
private static GUIContent _useAdditionalFilesText = new GUIContent("Use Additional Files");
84-
85-
86-
public static void Draw(ProjectWindowSettingsHandler.Settings settings) {
87-
EditorGUI.indentLevel++;
88-
settings.UseCopyPaste = EditorGUILayout.ToggleLeft(_useCopyPasteText, settings.UseCopyPaste);
89-
settings.UseAdditionalFiles = EditorGUILayout.ToggleLeft(_useAdditionalFilesText, settings.UseAdditionalFiles);
90-
EditorGUI.indentLevel--;
91-
}
92-
}
9374
}

Editor/com.nomnom.project-window-extensions.Editor.asmdef

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"name": "com.nomnom.project-window-extensions.Editor",
33
"rootNamespace": "Nomnom.ProjectWindowExtensions",
4-
"references": [],
4+
"references": [
5+
"com.nomnom.easier-custom-preferences.Editor"
6+
],
57
"includePlatforms": [
68
"Editor"
79
],

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"name": "com.nomnom.project-window-extensions",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"displayName": "Project Window Extensions",
55
"description": "This aims to improve the usability of the project window.",
66
"unity": "2020.3",
77
"unityRelease": "20f1",
88
"licensesUrl": "https://choosealicense.com/licenses/mit/",
9+
"dependencies": {
10+
"com.nomnom.easier-custom-preferences": "1.1.1"
11+
},
912
"keywords": [
1013
"nomnom",
1114
"project",

0 commit comments

Comments
 (0)