Table of Contents

Class ScriptSystemExtensions

Namespace
Stride.CommunityToolkit.Engine
Assembly
Stride.CommunityToolkit.dll

Provides extension methods for the ScriptSystem to facilitate time-based operations, including delays and frame-based executions. These extensions are useful for managing time in game logic, such as delaying actions or executing logic over a period of time.

public static class ScriptSystemExtensions
Inheritance
ScriptSystemExtensions

Examples

Example 1: Delaying an action for 2 seconds in game time (affected by time warp):

await scriptSystem.DelayWarped(2.0f);
// Action will be delayed for 2 in-game seconds, accounting for any time warp factors.

Example 2: Running a continuous action for 5 seconds of real time (unaffected by time warp):

await scriptSystem.ExecuteInTime(5.0f, elapsed =>
{
    // Perform action based on the elapsed time in real seconds.
    DebugText.Print($"Time elapsed: {elapsed} seconds");
});

Example 3: Delaying an action for 3 real-time seconds (unaffected by time warp):

await scriptSystem.Delay(3.0f);
// Action will be delayed for exactly 3 real seconds.

Remarks

These extensions allow you to control how game logic interacts with time, whether you need frame-based operations or time delays. The methods are useful for both real-time and in-game time-based operations.

Methods

Delay(ScriptSystem, float)

Waits for a specified amount of real time (not accounting for any time warp factors).

public static Task Delay(this ScriptSystem script, float seconds)

Parameters

script ScriptSystem

The ScriptSystem instance used to execute the delay.

seconds float

The number of seconds to delay execution.

Returns

Task

A Task representing the delay.

Remarks

This delay operates in real time without considering the game's time warp.

DelayWarped(ScriptSystem, float)

Waits for a specified amount of time, adjusting for any time warp factors.

public static Task DelayWarped(this ScriptSystem script, float seconds)

Parameters

script ScriptSystem

The ScriptSystem instance used to execute the delay.

seconds float

The number of seconds to delay execution.

Returns

Task

A Task representing the delay.

Remarks

This delay takes into account the game's time warp factor, using the WarpElapsed property of UpdateTime.

ExecuteInTime(ScriptSystem, float, Action<float>)

Executes an action every frame for a specified duration, using real time (not accounting for any time warp factors).

public static Task ExecuteInTime(this ScriptSystem script, float seconds, Action<float> action)

Parameters

script ScriptSystem

The ScriptSystem instance used to execute the action.

seconds float

The duration in seconds for which the action will be executed.

action Action<float>

The action to perform on each frame, which receives the elapsed time as a parameter.

Returns

Task

A Task representing the action execution.

Remarks

This method operates in real time, without considering the game's time warp.

ExecuteInWarpedTime(ScriptSystem, float, Action<float>)

Executes an action every frame for a specified duration, adjusting for any time warp factors.

public static Task ExecuteInWarpedTime(this ScriptSystem script, float seconds, Action<float> action)

Parameters

script ScriptSystem

The ScriptSystem instance used to execute the action.

seconds float

The duration in seconds for which the action will be executed.

action Action<float>

The action to perform on each frame, which receives the elapsed time as a parameter.

Returns

Task

A Task representing the action execution.

Remarks

This method accounts for the game's WarpElapsed time factor during execution.