mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
Allow suspension of script assembly watcher and reload after rebuild
This commit is contained in:
@@ -232,9 +232,22 @@ namespace GlitchyEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Rebuilds the C# scripts.
|
/// Rebuilds the C# scripts.
|
||||||
public BuildScriptsBackgroundTask BuildScripts()
|
public BuildScriptsBackgroundTask BuildScripts(bool reloadAfterBuild = true)
|
||||||
{
|
{
|
||||||
|
ScriptEngine.SuspendAssemblyWatcher();
|
||||||
|
|
||||||
BuildScriptsBackgroundTask task = new .(EditorApp.Instance.Settings.ScriptSettings.DotNetExecutablePath, EditorApp.Instance.EditorLayer.CurrentProject, false){ DeleteWhenEnded = true };
|
BuildScriptsBackgroundTask task = new .(EditorApp.Instance.Settings.ScriptSettings.DotNetExecutablePath, EditorApp.Instance.EditorLayer.CurrentProject, false){ DeleteWhenEnded = true };
|
||||||
|
task.ContinueWith(new (task) => {
|
||||||
|
ScriptEngine.ResumeAssemblyWatcher();
|
||||||
|
|
||||||
|
if (reloadAfterBuild)
|
||||||
|
{
|
||||||
|
EditorApp.Instance.InvokeOnMainThread(new () => {
|
||||||
|
ScriptEngine.ReloadAssemblies(retainScriptData: true);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(task);
|
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(task);
|
||||||
|
|
||||||
|
|||||||
@@ -826,7 +826,9 @@ namespace GlitchyEditor
|
|||||||
|
|
||||||
if (allowRebuild && EditorApp.Instance.Settings.ScriptSettings.RebuildOnPlay)
|
if (allowRebuild && EditorApp.Instance.Settings.ScriptSettings.RebuildOnPlay)
|
||||||
{
|
{
|
||||||
var task = _editor.BuildScripts();
|
// Don't immediately reload the scripts after the build, because SetActiveScene will do that anyway.
|
||||||
|
var task = _editor.BuildScripts(reloadAfterBuild: false);
|
||||||
|
|
||||||
task.ContinueWith(new (t) => {
|
task.ContinueWith(new (t) => {
|
||||||
// Continuations run in worker threads, invoke play on main thread!
|
// Continuations run in worker threads, invoke play on main thread!
|
||||||
EditorApp.Instance.InvokeOnMainThread(new () => {
|
EditorApp.Instance.InvokeOnMainThread(new () => {
|
||||||
|
|||||||
@@ -212,6 +212,22 @@ static class ScriptEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool _requestingReload = false;
|
static bool _requestingReload = false;
|
||||||
|
static bool _assemblyWatcherSuspended = false;
|
||||||
|
|
||||||
|
public static void SuspendAssemblyWatcher()
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Trace("Suspending assembly watching");
|
||||||
|
|
||||||
|
_assemblyWatcherSuspended = true;
|
||||||
|
_userAssemblyWatcher?.StopRaisingEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ResumeAssemblyWatcher()
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Trace("Resuming assembly watching");
|
||||||
|
_assemblyWatcherSuspended = false;
|
||||||
|
_userAssemblyWatcher?.StartRaisingEvents();
|
||||||
|
}
|
||||||
|
|
||||||
static void InitAssemblyWatcher()
|
static void InitAssemblyWatcher()
|
||||||
{
|
{
|
||||||
@@ -244,7 +260,8 @@ static class ScriptEngine
|
|||||||
ReloadAssemblies(retainScriptData: true);
|
ReloadAssemblies(retainScriptData: true);
|
||||||
|
|
||||||
_requestingReload = false;
|
_requestingReload = false;
|
||||||
_userAssemblyWatcher.StartRaisingEvents();
|
if (_assemblyWatcherSuspended)
|
||||||
|
_userAssemblyWatcher.StartRaisingEvents();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -252,7 +269,8 @@ static class ScriptEngine
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_userAssemblyWatcher.StartRaisingEvents();
|
if (_assemblyWatcherSuspended)
|
||||||
|
_userAssemblyWatcher.StartRaisingEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadScriptAssemblies()
|
static void LoadScriptAssemblies()
|
||||||
|
|||||||
Reference in New Issue
Block a user