Description
The CreateAsync
method is a static method of the SceneMap
class in the Sandbox API. It is used to asynchronously create a SceneMap
instance within a specified SceneWorld
. This method is particularly useful for loading map geometry that can be rendered in a scene.
Usage
To use the CreateAsync
method, you need to provide the following parameters:
sceneWorld
: An instance of SceneWorld
where the map will be created.
map
: A string
representing the name or path of the map to be loaded.
cancelToken
: A CancellationToken
that can be used to cancel the asynchronous operation if needed.
The method returns a Task<SceneMap>
, which represents the asynchronous operation. Once completed, the task result contains the created SceneMap
instance.
Example
// Example of using CreateAsync to load a map into a SceneWorld
// Assume sceneWorld is a valid SceneWorld instance
SceneWorld sceneWorld = new SceneWorld();
// Map name or path
string mapName = "maps/davej/cs_assault";
// Cancellation token
CancellationToken cancellationToken = new CancellationToken();
// Asynchronously create the SceneMap
Task<SceneMap> sceneMapTask = SceneMap.CreateAsync(sceneWorld, mapName, cancellationToken);
// Await the task to get the SceneMap
SceneMap sceneMap = await sceneMapTask;
// Check if the SceneMap is valid
if (sceneMap.IsValid)
{
// Use the SceneMap
Console.WriteLine($"Map {sceneMap.MapName} loaded successfully.");
}
else
{
Console.WriteLine("Failed to load the map.");
}