Create color folder if non-existent

This commit is contained in:
Banane_Rotative
2025-12-01 18:40:47 +01:00
parent 5985860c31
commit 4d481338a1

View File

@@ -12,18 +12,30 @@ public class ColorFolderMap : ScriptableObject {
} }
private const string SoundTexturesFolder = "Sound/Textures/"; private const string SoundTexturesFolder = "Sound/Textures/";
private const string ResourcesFolderPath = "Assets/Resources/";
public List<Entry> entries = new List<Entry>(); public List<Entry> entries = new List<Entry>();
/// Returns folder path for color, or null if not found (Editor + Runtime safe) /// Returns folder path for color, or null if config not set (Editor + Runtime safe)
/// Creates the folder if it does not exist
public string GetFolder(Color color) { public string GetFolder(Color color) {
string hexColor = color.ToHexString(); string hexColor = color.ToHexString();
foreach (var entry in entries) { foreach (var entry in entries) {
if (entry.color.ToHexString() == hexColor) { if (entry.color.ToHexString() == hexColor) {
CreateFolderIfNonExistent(entry.folderName);
return SoundTexturesFolder + entry.folderName; return SoundTexturesFolder + entry.folderName;
} }
} }
return null; return null;
} }
private void CreateFolderIfNonExistent(string folderName) {
#if UNITY_EDITOR // AssetDatabase is Editor-only
if (!UnityEditor.AssetDatabase.IsValidFolder(ResourcesFolderPath + SoundTexturesFolder + folderName)) {
UnityEditor.AssetDatabase.CreateFolder(ResourcesFolderPath + SoundTexturesFolder, folderName);
UnityEditor.AssetDatabase.Refresh();
}
#endif
}
} }