From ff66393f0d9a73c3cbf26896b5c902409d96cfa2 Mon Sep 17 00:00:00 2001 From: Ludovic LEROUGE - TheRed Games Date: Wed, 3 Apr 2024 11:23:10 +0200 Subject: [PATCH] fix: destination folder do not exists and convert to sprite from isometric workflow --- package/Editor/Plugins/CommonUtils.cs | 3 ++- package/Editor/Settings/PluginSettings.cs | 30 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/package/Editor/Plugins/CommonUtils.cs b/package/Editor/Plugins/CommonUtils.cs index 5dab8f7..1b3491e 100644 --- a/package/Editor/Plugins/CommonUtils.cs +++ b/package/Editor/Plugins/CommonUtils.cs @@ -88,7 +88,8 @@ private static void SaveImage(byte[] pngBytes, string fileName, Preset importPre importPreset = PluginSettings.TexturePreset; } - string downloadPath = EditorPrefs.GetString("SaveFolder", "Assets"); + + string downloadPath = PluginSettings.SaveFolder; string filePath = Path.Combine(downloadPath, fileName); File.WriteAllBytesAsync(filePath, pngBytes).ContinueWith(task => diff --git a/package/Editor/Settings/PluginSettings.cs b/package/Editor/Settings/PluginSettings.cs index 20e7aa4..204a6c7 100644 --- a/package/Editor/Settings/PluginSettings.cs +++ b/package/Editor/Settings/PluginSettings.cs @@ -13,7 +13,16 @@ public class PluginSettings : EditorWindow public static string ApiUrl => "https://api.cloud.scenario.com/v1"; public static string WebAppUrl { get { return webAppUrl; } } - public static string SaveFolder { get { return EditorPrefs.GetString("SaveFolder"); } } + public static string SaveFolder { + get + { + if (!string.IsNullOrEmpty(EditorPrefs.GetString("SaveFolder"))) + { + CheckAndCreateFolder(EditorPrefs.GetString("SaveFolder")); + } + return EditorPrefs.GetString("SaveFolder"); + } + } public static Preset TexturePreset { get { return GetPreset(EditorPrefs.GetString("scenario/texturePreset")); } } public static Preset SpritePreset { get { return GetPreset(EditorPrefs.GetString("scenario/spritePreset")); } } public static Preset TilePreset { get { return GetPreset(EditorPrefs.GetString("scenario/tilePreset")); } } @@ -61,6 +70,12 @@ private class PackageInfo public string version; } + static PluginSettings() + { + GetVersionFromPackageJson(); + PluginSettings settings = ScriptableObject.CreateInstance(); + } + #region Unity Methods private void OnEnable() @@ -282,7 +297,7 @@ private void LoadSettings() /// Check if the folder exist else create it. /// /// Folder string - private void CheckAndCreateFolder(string _folder) + private static void CheckAndCreateFolder(string _folder) { if (!AssetDatabase.IsValidFolder(_folder)) { @@ -292,8 +307,15 @@ private void CheckAndCreateFolder(string _folder) { if (!path.Equals("Assets")) { - AssetDatabase.CreateFolder(parentFolder, path); - parentFolder += "/" + path; + if (!AssetDatabase.IsValidFolder($"{parentFolder}/{path}")) + { + AssetDatabase.CreateFolder(parentFolder, path); + parentFolder += "/" + path; + } + else + { + parentFolder += "/" + path; + } } else {