diff --git a/CHANGELOG.md b/CHANGELOG.md index e6211168da..e7449a8e2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Added `map` support to the Worker Inspector window. [#1403](https://github.com/spatialos/gdk-for-unity/pull/1403) - Added `Open inspector V2` menu item that opens the new inspector in the browser. [#1407](https://github.com/spatialos/gdk-for-unity/pull/1407) +### Changed + +- Moved Gdk Tools Configuration to the Unity "Project Settings" window under `Spatial OS`. [#1408](https://github.com/spatialos/gdk-for-unity/pull/1408) + ### Fixed - Fixed a bug in the Worker Inspector where component foldouts were being rendered too often, causing poor performance when the entity had many components or very complex components. [#1403](https://github.com/spatialos/gdk-for-unity/pull/1403) diff --git a/workers/unity/Packages/io.improbable.gdk.deploymentlauncher/DeploymentLauncherWindow.cs b/workers/unity/Packages/io.improbable.gdk.deploymentlauncher/DeploymentLauncherWindow.cs index 4f0c2dfb31..c0e60a27d6 100644 --- a/workers/unity/Packages/io.improbable.gdk.deploymentlauncher/DeploymentLauncherWindow.cs +++ b/workers/unity/Packages/io.improbable.gdk.deploymentlauncher/DeploymentLauncherWindow.cs @@ -246,7 +246,7 @@ private void OnGUI() { if (GUILayout.Button(style.EditRuntimeVersionButtonContents, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { - GdkToolsConfigurationWindow.ShowWindow(); + SettingsService.OpenProjectSettings(GdkToolsConfigurationProvider.ProjectSettingsPath); } } diff --git a/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfiguration.cs b/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfiguration.cs index d2bff6fce6..52b2bd024a 100644 --- a/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfiguration.cs +++ b/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfiguration.cs @@ -65,22 +65,22 @@ internal List Validate() if (string.IsNullOrEmpty(CodegenLogOutputDir)) { - errors.Add($"{GdkToolsConfigurationWindow.CodegenLogOutputDirLabel} cannot be empty."); + errors.Add($"{GdkToolsConfigurationProvider.CodegenLogOutputDirLabel} cannot be empty."); } if (string.IsNullOrEmpty(CodegenOutputDir)) { - errors.Add($"{GdkToolsConfigurationWindow.CodegenOutputDirLabel} cannot be empty."); + errors.Add($"{GdkToolsConfigurationProvider.CodegenOutputDirLabel} cannot be empty."); } if (string.IsNullOrEmpty(CodegenEditorOutputDir)) { - errors.Add($"{GdkToolsConfigurationWindow.CodegenEditorOutputDirLabel} cannot be empty"); + errors.Add($"{GdkToolsConfigurationProvider.CodegenEditorOutputDirLabel} cannot be empty"); } if (string.IsNullOrEmpty(DescriptorOutputDir)) { - errors.Add($"{GdkToolsConfigurationWindow.DescriptorOutputDirLabel} cannot be empty."); + errors.Add($"{GdkToolsConfigurationProvider.DescriptorOutputDirLabel} cannot be empty."); } for (var i = 0; i < SchemaSourceDirs.Count; i++) @@ -114,12 +114,12 @@ internal List Validate() if (string.IsNullOrEmpty(DevAuthTokenDir)) { - errors.Add($"{GdkToolsConfigurationWindow.DevAuthTokenDirLabel} cannot be empty."); + errors.Add($"{GdkToolsConfigurationProvider.DevAuthTokenDirLabel} cannot be empty."); } else if (!DevAuthTokenDir.Equals("Resources") && !DevAuthTokenDir.EndsWith("/Resources")) { errors.Add( - $"{GdkToolsConfigurationWindow.DevAuthTokenDirLabel} must be at root of a Resources folder."); + $"{GdkToolsConfigurationProvider.DevAuthTokenDirLabel} must be at root of a Resources folder."); } return errors; diff --git a/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs b/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationProvider.cs similarity index 83% rename from workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs rename to workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationProvider.cs index 4d5004baa9..233d45c448 100644 --- a/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs +++ b/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationProvider.cs @@ -1,17 +1,21 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; +using System.IO; +using System.Reflection; using UnityEditor; using UnityEngine; +using UnityEngine.UIElements; namespace Improbable.Gdk.Tools { /// - /// Defines a custom inspector window that allows you to configure the GDK Tools. + /// Defines a custom section in Unity Project settings for GDK Tools configuration. /// - public class GdkToolsConfigurationWindow : EditorWindow + public class GdkToolsConfigurationProvider : SettingsProvider { + public const string ProjectSettingsPath = "Project/Spatial OS"; + internal const string SchemaStdLibDirLabel = "Standard library"; internal const string VerboseLoggingLabel = "Verbose logging"; internal const string CodegenLogOutputDirLabel = "Log output directory"; @@ -35,40 +39,41 @@ public class GdkToolsConfigurationWindow : EditorWindow private List configErrors = new List(); private Vector2 scrollPosition; - // Minimum time required from last config change before saving to file - private readonly TimeSpan FileSavingInterval = TimeSpan.FromSeconds(1); - private DateTime lastSaveTime = DateTime.Now; + // Flag to indicate if we have unsaved changes in the settings window private bool hasUnsavedData; - [MenuItem("SpatialOS/GDK tools configuration", false, MenuPriorities.GdkToolsConfiguration)] - public static void ShowWindow() + private GdkToolsConfigurationProvider(string path, SettingsScope scope = SettingsScope.User) : base(path, scope) { } + + [SettingsProvider] + public static SettingsProvider CreateGdkToolsConfigurationProvider() { - GetWindow().Show(); + var provider = new GdkToolsConfigurationProvider(ProjectSettingsPath, SettingsScope.Project); + + // Extract all members (fields, methods etc) from the GdkToolsConfiguration class + var gdkToolsConfigProperties = typeof(GdkToolsConfiguration).GetMembers(); + + // Filter the results so that fields and properties remain + // Use the names of the discovered members as the keyword search terms in the Project Settings panel + provider.keywords = gdkToolsConfigProperties + .Where(member => member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Field) + .Select(property => property.Name).ToList(); + return provider; } - private void OnEnable() + + public override void OnActivate(string searchContext, VisualElement rootElement) { if (toolsConfig != null) { return; } - titleContent = new GUIContent("GDK Tools"); toolsConfig = GdkToolsConfiguration.GetOrCreateInstance(); Undo.undoRedoPerformed += () => { configErrors = toolsConfig.Validate(); }; - - EditorApplication.quitting += OnExit; } - private void OnDestroy() - { - OnExit(); - - EditorApplication.quitting -= OnExit; - } - - private void OnExit() + public override void OnDeactivate() { if (!hasUnsavedData || configErrors.Any()) { @@ -77,9 +82,11 @@ private void OnExit() toolsConfig.Save(); AssetDatabase.SaveAssets(); + hasUnsavedData = false; } - public void OnGUI() + + public override void OnGUI(string searchContext) { if (AddSchemaDirButton == null) { @@ -118,14 +125,11 @@ public void OnGUI() using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); - if (GUILayout.Button(ResetConfigurationButtonText, EditorStyles.miniButtonMid, GUILayout.Width(150))) + if (GUILayout.Button(ResetConfigurationButtonText, EditorStyles.miniButtonMid, GUILayout.Width(150)) + && EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to reset to defaults?", "Yes", "No")) { - if (EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to reset to defaults?", - "Yes", "No")) - { - GUI.FocusControl(null); - toolsConfig.ResetToDefault(); - } + GUI.FocusControl(null); + toolsConfig.ResetToDefault(); } GUILayout.FlexibleSpace(); @@ -256,23 +260,5 @@ private void DrawCustomSnapshotDir() } } } - - private void Update() - { - TrySaveChanges(); - } - - private void TrySaveChanges() - { - var timeSinceLastSave = DateTime.Now - lastSaveTime; - if (!hasUnsavedData || timeSinceLastSave < FileSavingInterval || configErrors.Any()) - { - return; - } - - toolsConfig.Save(); - lastSaveTime = DateTime.Now; - hasUnsavedData = false; - } } } diff --git a/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs.meta b/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationProvider.cs.meta similarity index 83% rename from workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs.meta rename to workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationProvider.cs.meta index d9a6afcceb..c0ca42bf86 100644 --- a/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationWindow.cs.meta +++ b/workers/unity/Packages/io.improbable.gdk.tools/GdkToolsConfigurationProvider.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2291c626cfa43b949ac83c6af98fd454 +guid: 6f9756bf329058747902aa0d242de8ec MonoImporter: externalObjects: {} serializedVersion: 2