Script System Extensions
Extension methods for ScriptSystem, in the Stride.CommunityToolkit.Engine namespace. They cover two jobs: awaiting time inside an async script, and scheduling work as a micro thread without writing one yourself.
Waiting
Every method here comes in a plain and a warped flavour. Warped time is scaled by the game's update time factor, so a warped wait slows down when the game does; the plain version does not.
Delay()- Waits the given number of seconds, ignoring the update time factor.DelayWarped()- Waits the given number of seconds in game time, so slow motion stretches the wait.WaitFor()- The same asDelay()but takes aTimeSpan. Throws if the delay is zero or negative.
Running something every frame for a while
ExecuteInTime()- Calls the action once per frame for the given number of seconds, passing the seconds elapsed so far.ExecuteInWarpedTime()- The same, measured in game time rather than real time.
Scheduling micro threads
These return the MicroThread they created, so you can keep it and cancel it later. Each takes an optional priority.
AddAction()- Runs an action once, after a delay. A second overload adds arepeatEveryinterval and keeps running it.AddTask()- Theasynccounterpart ofAddAction(), taking aFunc<Task>. Also has a repeating overload.AddOverTimeAction()- Runs an action every frame for a duration, passing progress from0.0fto1.0f. This is the one to reach for when tweening something.AddOnEventAction()- Runs an action every time an event is published. Takes anEventKey<T>or an existingEventReceiver<T>.AddOnEventTask()- Theasynccounterpart ofAddOnEventAction().CancelAll()- Cancels every micro thread in a collection and clears it. An extension on the collection, not on the script system.
Tip
When the action you pass is an instance method of a ScriptComponent, the micro thread stops on its
own once that component or its entity is removed. Pass a lambda that closes over other state and you
own the lifetime yourself - keep the MicroThread and cancel it.