50b603c7dc
We're targeting .NET 5 for now to make development easier while .NET 6 is not yet released. TEMPORARY REGRESSIONS --------------------- Assembly unloading is not implemented yet. As such, many Godot resources are leaked at exit. This will be re-implemented later together with assembly hot-reloading.
51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using Godot;
|
|
using GodotTools.Internals;
|
|
using JetBrains.Annotations;
|
|
using static GodotTools.Internals.Globals;
|
|
|
|
namespace GodotTools
|
|
{
|
|
public class HotReloadAssemblyWatcher : Node
|
|
{
|
|
private Timer watchTimer;
|
|
|
|
public override void _Notification(int what)
|
|
{
|
|
if (what == Node.NotificationWmWindowFocusIn)
|
|
{
|
|
RestartTimer();
|
|
|
|
if (Internal.IsAssembliesReloadingNeeded())
|
|
Internal.ReloadAssemblies(softReload: false);
|
|
}
|
|
}
|
|
|
|
private void TimerTimeout()
|
|
{
|
|
if (Internal.IsAssembliesReloadingNeeded())
|
|
Internal.ReloadAssemblies(softReload: false);
|
|
}
|
|
|
|
[UsedImplicitly]
|
|
public void RestartTimer()
|
|
{
|
|
watchTimer.Stop();
|
|
watchTimer.Start();
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
|
|
watchTimer = new Timer
|
|
{
|
|
OneShot = false,
|
|
WaitTime = (float)EditorDef("mono/assembly_watch_interval_sec", 0.5)
|
|
};
|
|
watchTimer.Timeout += TimerTimeout;
|
|
AddChild(watchTimer);
|
|
watchTimer.Start();
|
|
}
|
|
}
|
|
}
|