2019-12-25 19:25:53 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-02-25 23:05:13 +00:00
|
|
|
|
/// An asynchronous task to be performed once.
|
|
|
|
|
/// Once constructed, this can be run by scheduling it with Scheduler.Schedule()
|
2019-12-25 19:25:53 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class Once : ISchedulable
|
|
|
|
|
{
|
|
|
|
|
private Action task;
|
|
|
|
|
|
|
|
|
|
private float delay;
|
|
|
|
|
public IEnumerator<TaskContract> Run()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSecondsEnumerator(delay).Continue();
|
|
|
|
|
task();
|
|
|
|
|
yield return Yield.It;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a single-run task
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="task">The task to run once</param>
|
|
|
|
|
/// <param name="after">The delay (in seconds) before the task is run</param>
|
|
|
|
|
public Once(Action task, float after = 0.0f)
|
|
|
|
|
{
|
|
|
|
|
this.task = task;
|
|
|
|
|
this.delay = after;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|