From be4f9660fb630844be1a8bd8dcfdb3147d4a77aa Mon Sep 17 00:00:00 2001 From: Morgan - 6 Freedom Date: Tue, 9 Jan 2024 17:13:31 +0100 Subject: [PATCH 1/2] change to a dynamic path it now use a dynamic path based on the assembly definition --- Scenario/Plugins/PluginSettings.cs | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Scenario/Plugins/PluginSettings.cs b/Scenario/Plugins/PluginSettings.cs index d03f7d2..5b17c6c 100644 --- a/Scenario/Plugins/PluginSettings.cs +++ b/Scenario/Plugins/PluginSettings.cs @@ -18,7 +18,7 @@ public class PluginSettings : EditorWindow private readonly string[] imageFormats = { "JPEG", "PNG" }; private readonly string[] imageFormatExtensions = { "jpeg", "png" }; - private static string vnumber = ""; + private static string vnumber => GetVersionFromPackageJson(); private static string version => $"Scenario Beta Version {vnumber}"; [System.Serializable] @@ -27,14 +27,28 @@ private class PackageInfo public string version; } - [MenuItem("Scenario/Update Version")] - public static void UpdateVersionFromPackageJson() + /// + /// Get the correct version number from the package JSON + /// + /// The version of the plugin, as a string + private static string GetVersionFromPackageJson() { - string packageJsonPath = "Assets/Scenario/package.json"; - string packageJsonContent = File.ReadAllText(packageJsonPath); - vnumber = JsonUtility.FromJson(packageJsonContent).version; - EditorWindow.GetWindow().Repaint(); + // Find all Texture2Ds that have 'com.scenario.editor' in their filename which is an assembly definition + string[] guids = AssetDatabase.FindAssets("com.scenario.editor t:assemblydefinitionasset"); + if (guids.Length > 1) + { + Debug.LogError("it seems that you have multiple file 'com.scenario.editor.asmdf'. Please delete one"); + } + + //find the folder of that file + string folderPath = AssetDatabase.GUIDToAssetPath(guids[0]); + folderPath = folderPath.Remove(folderPath.IndexOf("com.scenario.editor.asmdef")); + + //find the package.json inside this folder + string packageJsonPath = $"{folderPath}/package.json"; + string packageJsonContent = File.ReadAllText(packageJsonPath); + return JsonUtility.FromJson(packageJsonContent).version; } public static string EncodedAuth @@ -62,7 +76,7 @@ public static void ShowWindow() private void OnEnable() { - UpdateVersionFromPackageJson(); + GetVersionFromPackageJson(); LoadSettings(); } @@ -70,7 +84,7 @@ private void OnGUI() { Color backgroundColor = new Color32(18, 18, 18, 255); EditorGUI.DrawRect(new Rect(0, 0, Screen.width, Screen.height), backgroundColor); - + GUILayout.Space(10); apiKey = EditorGUILayout.TextField("API Key", apiKey); From 0f53b458114e6b95c84800599f6a757f3aa04c94 Mon Sep 17 00:00:00 2001 From: Morgan Klein - 6freedom Date: Fri, 19 Jan 2024 18:39:13 +0100 Subject: [PATCH 2/2] fix: because the folder structure have changed --- package/Editor/Plugins/PluginSettings.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/package/Editor/Plugins/PluginSettings.cs b/package/Editor/Plugins/PluginSettings.cs index 5b17c6c..9de37dd 100644 --- a/package/Editor/Plugins/PluginSettings.cs +++ b/package/Editor/Plugins/PluginSettings.cs @@ -2,11 +2,13 @@ using UnityEditor; using UnityEngine; using System.IO; +using System.Linq; namespace Scenario { public class PluginSettings : EditorWindow { + private static string assemblyDefinitionFileName = "com.scenarioinc.scenario.editor"; private string apiKey; private string secretKey; private string saveFolder; @@ -33,17 +35,24 @@ private class PackageInfo /// The version of the plugin, as a string private static string GetVersionFromPackageJson() { - - // Find all Texture2Ds that have 'com.scenario.editor' in their filename which is an assembly definition - string[] guids = AssetDatabase.FindAssets("com.scenario.editor t:assemblydefinitionasset"); + //Find the assembly Definition which should be at package/Editor/ folder because it's a unique file. + string[] guids = AssetDatabase.FindAssets($"{assemblyDefinitionFileName} t:assemblydefinitionasset"); + if (guids.Length > 1) { - Debug.LogError("it seems that you have multiple file 'com.scenario.editor.asmdf'. Please delete one"); + Debug.LogError($"it seems that you have multiple file '{assemblyDefinitionFileName}.asmdef'. Please delete one"); + return "0"; + } + + if (guids.Length == 0) + { + Debug.LogError($"It seems that you don't have the file '{assemblyDefinitionFileName}.asmdef'. Please redownload the plugin from the asset store."); + return "0"; } //find the folder of that file string folderPath = AssetDatabase.GUIDToAssetPath(guids[0]); - folderPath = folderPath.Remove(folderPath.IndexOf("com.scenario.editor.asmdef")); + folderPath = folderPath.Remove(folderPath.IndexOf($"Editor/{assemblyDefinitionFileName}.asmdef")); //find the package.json inside this folder string packageJsonPath = $"{folderPath}/package.json";