Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Port Gdk Tools Configuration to Unity Project Settings (#1408)
Browse files Browse the repository at this point in the history
* Port GdkToolsConfiguration to Unity settings window

* Add CHANGELOG entry

* Add ability to load project settings from deployment launcher

* Change Project Settings name from GDK Tools Configuration to Spatial OS

Co-authored-by: Paul Balaji <[email protected]>
  • Loading branch information
Sean Parker and Paul Balaji authored Jun 29, 2020
1 parent 203cbcc commit 8ee7a2a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Added `map<k,v>` 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private void OnGUI()
{
if (GUILayout.Button(style.EditRuntimeVersionButtonContents, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
{
GdkToolsConfigurationWindow.ShowWindow();
SettingsService.OpenProjectSettings(GdkToolsConfigurationProvider.ProjectSettingsPath);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ internal List<string> 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++)
Expand Down Expand Up @@ -114,12 +114,12 @@ internal List<string> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
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";
Expand All @@ -35,40 +39,41 @@ public class GdkToolsConfigurationWindow : EditorWindow
private List<string> configErrors = new List<string>();
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<GdkToolsConfigurationWindow>().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())
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ee7a2a

Please sign in to comment.