Scheduler
Executing on next tick
Some functions are required to be executed on the main thread or on the next tick, and you can use Core.Scheduler.NextTick to do that.
Example:
Core.Scheduler.NextTick(() => {
Console.WriteLine(123);
});This example will print 123 on the next tick.
Timers
All timers use the game tick as the unit, if you want to use seconds, you need to use XXXBySeconds variant instead.
Delay
var token = Core.Scheduler.Delay(1000, () => {
Console.WriteLine(123);
});This example will print 123 after 1000 game ticks.
Repeat
var token = Core.Scheduler.Repeat(1000, () => {
Console.WriteLine(123);
});The callback will be executed once immediately, and then print 123 every 1000 game ticks.
Delay and Repeat
var token = Core.Scheduler.DelayAndRepeat(500, 1000, () => {
Console.WriteLine(123);
});The callback will be executed once after 500 game ticks, and then print 123 every 1000 game ticks.
Cancel
All timer methods return a CancellationTokenSource object, you can use it to cancel the timer.
token.Cancel();This example will cancel the timer.
Cancel on map change
Core.Scheduler.StopOnMapChange(token);This example will cancel the timer when the map changes.
Reference
See ISchedulerService for more details.