Fix custom content and importers blocking scripting reload
This commit is contained in:
@@ -819,6 +819,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
|||||||
OnGroupsEnd();
|
OnGroupsEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
protected override void Deinitialize()
|
protected override void Deinitialize()
|
||||||
{
|
{
|
||||||
_visibleIfCaches = null;
|
_visibleIfCaches = null;
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ namespace FlaxEditor.Modules
|
|||||||
|
|
||||||
// Register AssetItems serialization helper (serialize ref ID only)
|
// Register AssetItems serialization helper (serialize ref ID only)
|
||||||
FlaxEngine.Json.JsonSerializer.Settings.Converters.Add(new AssetItemConverter());
|
FlaxEngine.Json.JsonSerializer.Settings.Converters.Add(new AssetItemConverter());
|
||||||
|
|
||||||
|
ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnContentAssetDisposing(Asset asset)
|
private void OnContentAssetDisposing(Asset asset)
|
||||||
@@ -1313,6 +1315,47 @@ namespace FlaxEditor.Modules
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnScriptsReloadBegin()
|
||||||
|
{
|
||||||
|
var enabledEvents = _enableEvents;
|
||||||
|
_enableEvents = false;
|
||||||
|
_isDuringFastSetup = true;
|
||||||
|
var startItems = _itemsCreated;
|
||||||
|
foreach (var project in Projects)
|
||||||
|
{
|
||||||
|
if (project.Content != null)
|
||||||
|
{
|
||||||
|
//Dispose(project.Content.Folder);
|
||||||
|
for (int i = 0; i < project.Content.Folder.Children.Count; i++)
|
||||||
|
{
|
||||||
|
Dispose(project.Content.Folder.Children[i]);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (project.Source != null)
|
||||||
|
{
|
||||||
|
//Dispose(project.Source.Folder);
|
||||||
|
for (int i = 0; i < project.Source.Folder.Children.Count; i++)
|
||||||
|
{
|
||||||
|
Dispose(project.Source.Folder.Children[i]);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ContentProxy> removeProxies = new List<ContentProxy>();
|
||||||
|
foreach (var proxy in Editor.Instance.ContentDatabase.Proxy)
|
||||||
|
{
|
||||||
|
if (proxy.GetType().IsCollectible)
|
||||||
|
removeProxies.Add(proxy);
|
||||||
|
}
|
||||||
|
foreach (var proxy in removeProxies)
|
||||||
|
RemoveProxy(proxy, false);
|
||||||
|
|
||||||
|
_isDuringFastSetup = false;
|
||||||
|
_enableEvents = enabledEvents;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
{
|
{
|
||||||
@@ -1340,6 +1383,7 @@ namespace FlaxEditor.Modules
|
|||||||
public override void OnExit()
|
public override void OnExit()
|
||||||
{
|
{
|
||||||
FlaxEngine.Content.AssetDisposing -= OnContentAssetDisposing;
|
FlaxEngine.Content.AssetDisposing -= OnContentAssetDisposing;
|
||||||
|
ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin;
|
||||||
|
|
||||||
// Disable events
|
// Disable events
|
||||||
_enableEvents = false;
|
_enableEvents = false;
|
||||||
|
|||||||
@@ -391,6 +391,20 @@ namespace FlaxEditor.Modules
|
|||||||
public override void OnInit()
|
public override void OnInit()
|
||||||
{
|
{
|
||||||
ImportFileEntry.RegisterDefaultTypes();
|
ImportFileEntry.RegisterDefaultTypes();
|
||||||
|
ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnScriptsReloadBegin()
|
||||||
|
{
|
||||||
|
// Remove import file types from scripting assemblies
|
||||||
|
List<string> removeFileTypes = new List<string>();
|
||||||
|
foreach (var pair in ImportFileEntry.FileTypes)
|
||||||
|
{
|
||||||
|
if (pair.Value.Method.IsCollectible || (pair.Value.Target != null && pair.Value.Target.GetType().IsCollectible))
|
||||||
|
removeFileTypes.Add(pair.Key);
|
||||||
|
}
|
||||||
|
foreach (var fileType in removeFileTypes)
|
||||||
|
ImportFileEntry.FileTypes.Remove(fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -451,6 +465,7 @@ namespace FlaxEditor.Modules
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnExit()
|
public override void OnExit()
|
||||||
{
|
{
|
||||||
|
ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin;
|
||||||
EndWorker();
|
EndWorker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ namespace FlaxEditor.Modules
|
|||||||
public Float2 FloatPosition;
|
public Float2 FloatPosition;
|
||||||
|
|
||||||
public AssetItem Item;
|
public AssetItem Item;
|
||||||
public AssetItem Item2;
|
|
||||||
|
|
||||||
// Constructor, to allow for default values
|
// Constructor, to allow for default values
|
||||||
public WindowRestoreData()
|
public WindowRestoreData()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ namespace FlaxEditor.Windows
|
|||||||
private const string ProjectDataLastViewedFolder = "LastViewedFolder";
|
private const string ProjectDataLastViewedFolder = "LastViewedFolder";
|
||||||
private bool _isWorkspaceDirty;
|
private bool _isWorkspaceDirty;
|
||||||
private string _workspaceRebuildLocation;
|
private string _workspaceRebuildLocation;
|
||||||
|
private string _lastViewedFolderBeforeReload;
|
||||||
private SplitPanel _split;
|
private SplitPanel _split;
|
||||||
private Panel _contentViewPanel;
|
private Panel _contentViewPanel;
|
||||||
private Panel _contentTreePanel;
|
private Panel _contentTreePanel;
|
||||||
@@ -1037,6 +1038,41 @@ namespace FlaxEditor.Windows
|
|||||||
ShowRoot();
|
ShowRoot();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
|
||||||
|
// Load last viewed folder
|
||||||
|
if (Editor.ProjectCache.TryGetCustomData(ProjectDataLastViewedFolder, out string lastViewedFolder))
|
||||||
|
{
|
||||||
|
if (Editor.ContentDatabase.Find(lastViewedFolder) is ContentFolder folder)
|
||||||
|
_tree.Select(folder.Node);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
|
||||||
|
ScriptsBuilder.ScriptsReloadEnd += OnScriptsReloadEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnScriptsReloadBegin()
|
||||||
|
{
|
||||||
|
var lastViewedFolder = _tree.Selection.Count == 1 ? _tree.SelectedNode as ContentTreeNode : null;
|
||||||
|
_lastViewedFolderBeforeReload = lastViewedFolder?.Path ?? string.Empty;
|
||||||
|
|
||||||
|
_tree.RemoveChild(_root);
|
||||||
|
_root = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnScriptsReloadEnd()
|
||||||
|
{
|
||||||
|
Refresh();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(_lastViewedFolderBeforeReload))
|
||||||
|
{
|
||||||
|
if (Editor.ContentDatabase.Find(_lastViewedFolderBeforeReload) is ContentFolder folder)
|
||||||
|
_tree.Select(folder.Node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Refresh()
|
||||||
|
{
|
||||||
// Setup content root node
|
// Setup content root node
|
||||||
_root = new RootContentTreeNode
|
_root = new RootContentTreeNode
|
||||||
{
|
{
|
||||||
@@ -1072,13 +1108,6 @@ namespace FlaxEditor.Windows
|
|||||||
// Update UI layout
|
// Update UI layout
|
||||||
_isLayoutLocked = false;
|
_isLayoutLocked = false;
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
|
|
||||||
// Load last viewed folder
|
|
||||||
if (Editor.ProjectCache.TryGetCustomData(ProjectDataLastViewedFolder, out string lastViewedFolder))
|
|
||||||
{
|
|
||||||
if (Editor.ContentDatabase.Find(lastViewedFolder) is ContentFolder folder)
|
|
||||||
_tree.Select(folder.Node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -1226,6 +1255,8 @@ namespace FlaxEditor.Windows
|
|||||||
_viewDropdown = null;
|
_viewDropdown = null;
|
||||||
|
|
||||||
Editor.Options.OptionsChanged -= OnOptionsChanged;
|
Editor.Options.OptionsChanged -= OnOptionsChanged;
|
||||||
|
ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin;
|
||||||
|
ScriptsBuilder.ScriptsReloadEnd -= OnScriptsReloadEnd;
|
||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,6 +150,22 @@ namespace FlaxEditor.Windows
|
|||||||
_searchBox.Clear();
|
_searchBox.Clear();
|
||||||
_groupSearch.DisposeChildren();
|
_groupSearch.DisposeChildren();
|
||||||
_groupSearch.PerformLayout();
|
_groupSearch.PerformLayout();
|
||||||
|
|
||||||
|
// Remove tabs
|
||||||
|
var tabs = new List<Tab>();
|
||||||
|
foreach (var child in _actorGroups.Children)
|
||||||
|
{
|
||||||
|
if (child is Tab tab)
|
||||||
|
{
|
||||||
|
if (tab.Text != "Search")
|
||||||
|
tabs.Add(tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var tab in tabs)
|
||||||
|
{
|
||||||
|
var group = _actorGroups.Children.Find(T => T == tab);
|
||||||
|
group.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnScriptsReloadEnd()
|
private void OnScriptsReloadEnd()
|
||||||
|
|||||||
@@ -170,6 +170,10 @@ namespace FlaxEngine
|
|||||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||||
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||||
Localization.LocalizationChanged += OnLocalizationChanged;
|
Localization.LocalizationChanged += OnLocalizationChanged;
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
FlaxEditor.ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
|
||||||
|
FlaxEditor.ScriptsBuilder.ScriptsReloadEnd += OnScriptsReloadEnd;
|
||||||
|
#endif
|
||||||
|
|
||||||
OnLocalizationChanged();
|
OnLocalizationChanged();
|
||||||
if (!Engine.IsEditor)
|
if (!Engine.IsEditor)
|
||||||
@@ -178,6 +182,19 @@ namespace FlaxEngine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
private static void OnScriptsReloadBegin()
|
||||||
|
{
|
||||||
|
// Tooltip might hold references to scripting assemblies
|
||||||
|
Style.Current.SharedTooltip = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnScriptsReloadEnd()
|
||||||
|
{
|
||||||
|
Style.Current.SharedTooltip = new Tooltip();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private static void OnLocalizationChanged()
|
private static void OnLocalizationChanged()
|
||||||
{
|
{
|
||||||
// Invariant-globalization only (see InitHostfxr with Mono)
|
// Invariant-globalization only (see InitHostfxr with Mono)
|
||||||
@@ -359,6 +376,10 @@ namespace FlaxEngine
|
|||||||
|
|
||||||
MainThreadTaskScheduler.Dispose();
|
MainThreadTaskScheduler.Dispose();
|
||||||
Json.JsonSerializer.Dispose();
|
Json.JsonSerializer.Dispose();
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
FlaxEditor.ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin;
|
||||||
|
FlaxEditor.ScriptsBuilder.ScriptsReloadEnd -= OnScriptsReloadEnd;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user