5 namespace Essentials.EssentialsSettings.UnityConfigurationModifications
11 public class EnforcePresetPerFolder : Adjustment
16 public override void Apply()
18 AssetDatabase.Refresh();
20 string[] foundAssets = AssetDatabase.FindAssets(
"EnforcePresetPostProcessor.cs");
21 if (foundAssets ==
null || foundAssets.Length < 1)
22 Debug.LogError(
"No files named 'EnforcePresetPostProcessor.cs...' have been found.");
23 else if (foundAssets.Length > 1)
24 Debug.LogError(
"More than one file named 'EnforcePresetPostProcessor.cs...' has been found.");
27 var path = AssetDatabase.GUIDToAssetPath(foundAssets[0]);
28 File.Move (path, path.Remove(path.Length-4, 4));
29 File.Delete(path+
".meta");
30 AssetDatabase.Refresh();
32 Debug.Log(
"Presets are now enforced at the folder where they are present.");
42 public override void Revert()
44 string[] foundAssets = AssetDatabase.FindAssets(
"t:script EnforcePresetPostProcessor");
45 if (foundAssets ==
null || foundAssets.Length < 1)
46 Debug.LogError(
"No files named 'EnforcePresetPostProcessor...' have been found.");
47 else if (foundAssets.Length > 1)
48 Debug.LogError(
"More than one file named 'EnforcePresetPostProcessor...' has been found.");
51 string path = AssetDatabase.GUIDToAssetPath(foundAssets[0]);
52 File.Move(path, path +
".txt");
53 File.Delete(path +
".meta");
54 AssetDatabase.Refresh();
56 Debug.Log(
"Enforcement of presets by folder disabled.");
60 public override string title {
get =>
"Enforce Preset Per Folder"; }
61 public override string revertButtonText {
get =>
"Revert"; }
62 public override string infoURL {
get =>
"https://docs.unity3d.com/Manual/DefaultPresetsByFolder.html"; }
63 public override string applyButtonText {
get =>
"Apply"; }
65 public override string applyAdjustmentShortExplanation {
get =>
"Applies the presets to all assets contained in the same folder of the preset."; }
66 public override string revertAdjustmentShortExplanation {
get =>
"Presets will no longer be automatically applied to the assets in the same folder of the preset."; }
68 public override bool showInSettingsWindow =>
true;
70 private class Popup : EditorWindow
72 public static void Init()
74 Popup window = ScriptableObject.CreateInstance<Popup>();
75 Vector2 windowSize =
new Vector2(250f, 150f);
76 window.minSize = window.maxSize = windowSize;
77 window.position =
Utils.GetEditorWindowCenteredPosition(windowSize);
83 EditorGUILayout.LabelField(
"If you want your already-imported Assets to adopt the configuration in the preset in the same folder, reimport them by right-clicking on the name of the asset.", EditorStyles.wordWrappedLabel);
85 if (GUILayout.Button(
"Okay")) this.Close();
A collection of useful methods that did not fit into any of the other sections of the asset.