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.
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using Godot;
|
|
using Godot.NativeInterop;
|
|
|
|
namespace GodotTools.Internals
|
|
{
|
|
public class EditorProgress : IDisposable
|
|
{
|
|
public string Task { get; }
|
|
|
|
public EditorProgress(string task, string label, int amount, bool canCancel = false)
|
|
{
|
|
Task = task;
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(task);
|
|
using godot_string labelIn = Marshaling.mono_string_to_godot(label);
|
|
Internal.godot_icall_EditorProgress_Create(taskIn, labelIn, amount, canCancel);
|
|
}
|
|
|
|
~EditorProgress()
|
|
{
|
|
// Should never rely on the GC to dispose EditorProgress.
|
|
// It should be disposed immediately when the task finishes.
|
|
GD.PushError("EditorProgress disposed by the Garbage Collector");
|
|
Dispose();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(Task);
|
|
Internal.godot_icall_EditorProgress_Dispose(taskIn);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public void Step(string state, int step = -1, bool forceRefresh = true)
|
|
{
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(Task);
|
|
using godot_string stateIn = Marshaling.mono_string_to_godot(state);
|
|
Internal.godot_icall_EditorProgress_Step(taskIn, stateIn, step, forceRefresh);
|
|
}
|
|
|
|
public bool TryStep(string state, int step = -1, bool forceRefresh = true)
|
|
{
|
|
using godot_string taskIn = Marshaling.mono_string_to_godot(Task);
|
|
using godot_string stateIn = Marshaling.mono_string_to_godot(state);
|
|
return Internal.godot_icall_EditorProgress_Step(taskIn, stateIn, step, forceRefresh);
|
|
}
|
|
}
|
|
}
|