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); } } }