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

Port Gdk Tools Configuration to Unity Project Settings #1408

Merged
merged 15 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- 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. [#1408](https://github.com/spatialos/gdk-for-unity/pull/1408)
seanjparker marked this conversation as resolved.
Show resolved Hide resolved
seanjparker marked this conversation as resolved.
Show resolved Hide resolved

### 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();
seanjparker marked this conversation as resolved.
Show resolved Hide resolved
SettingsService.OpenProjectSettings("Project/GDK Tools Configuration");
seanjparker marked this conversation as resolved.
Show resolved Hide resolved
}
}

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,16 +1,18 @@
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
{
internal const string SchemaStdLibDirLabel = "Standard library";
internal const string VerboseLoggingLabel = "Verbose logging";
Expand All @@ -35,40 +37,36 @@ 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()
public GdkToolsConfigurationProvider(string path, SettingsScope scope = SettingsScope.User)
: base(path, scope) { }

[SettingsProvider]
public static SettingsProvider CreateGdkToolsConfigurationProvider()
{
GetWindow<GdkToolsConfigurationWindow>().Show();
var provider = new GdkToolsConfigurationProvider("Project/GDK Tools Configuration", SettingsScope.Project);
seanjparker marked this conversation as resolved.
Show resolved Hide resolved

PropertyInfo[] GdkToolsConfigProperties = typeof(GdkToolsConfiguration).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
seanjparker marked this conversation as resolved.
Show resolved Hide resolved
provider.keywords = GdkToolsConfigProperties.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 +75,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 +118,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 +253,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.