A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Once.cs 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Svelto.Tasks;
  7. using Svelto.Tasks.Enumerators;
  8. namespace GamecraftModdingAPI.Tasks
  9. {
  10. /// <summary>
  11. /// An asynchronous task to be performed once.
  12. /// Once constructed, this can be run by scheduling it with Scheduler.Schedule()
  13. /// </summary>
  14. public class Once : ISchedulable
  15. {
  16. private Action task;
  17. private float delay;
  18. public IEnumerator<TaskContract> Run()
  19. {
  20. yield return new WaitForSecondsEnumerator(delay).Continue();
  21. task();
  22. yield return Yield.It;
  23. }
  24. /// <summary>
  25. /// Construct a single-run task
  26. /// </summary>
  27. /// <param name="task">The task to run once</param>
  28. /// <param name="after">The delay (in seconds) before the task is run</param>
  29. public Once(Action task, float after = 0.0f)
  30. {
  31. this.task = task;
  32. this.delay = after;
  33. }
  34. }
  35. }