using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Svelto.Tasks; using Svelto.Tasks.Enumerators; namespace GamecraftModdingAPI.Tasks { /// /// An asynchronous task to be performed once. /// Once constructed, this can be run by scheduling it with Scheduler.Schedule() /// public class Once : ISchedulable { private Action task; private float delay; public IEnumerator Run() { yield return new WaitForSecondsEnumerator(delay).Continue(); task(); yield return Yield.It; } /// /// Construct a single-run task /// /// The task to run once /// The delay (in seconds) before the task is run public Once(Action task, float after = 0.0f) { this.task = task; this.delay = after; } } }