Allow suspension of script assembly watcher and reload after rebuild

This commit is contained in:
Simon Lübeß
2026-10-23 23:03:50 +02:00
parent 1b10e98f8c
commit a7d0ef830b
3 changed files with 37 additions and 4 deletions
+14 -1
View File
@@ -232,9 +232,22 @@ namespace GlitchyEditor
}
/// 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 };
task.ContinueWith(new (task) => {
ScriptEngine.ResumeAssemblyWatcher();
if (reloadAfterBuild)
{
EditorApp.Instance.InvokeOnMainThread(new () => {
ScriptEngine.ReloadAssemblies(retainScriptData: true);
return true;
});
}
});
EditorApp.Instance.BackgroundTaskManager.StartBackgroundTask(task);
+3 -1
View File
@@ -826,7 +826,9 @@ namespace GlitchyEditor
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) => {
// Continuations run in worker threads, invoke play on main thread!
EditorApp.Instance.InvokeOnMainThread(new () => {