Description
The LoadAsync
method is a static method of the Texture
class in the Sandbox API. It is used to asynchronously load a texture from a specified file path within a given file system. This method returns a task that resolves to a Texture
object once the loading operation is complete.
Usage
To use the LoadAsync
method, you need to provide the following parameters:
filesystem
: An instance of BaseFileSystem
that represents the file system from which the texture will be loaded.
filepath
: A string
representing the path to the texture file within the specified file system.
warnOnMissing
: A bool
indicating whether a warning should be issued if the texture file is missing.
The method returns a Task<Texture>
, which can be awaited to obtain the loaded texture.
Example
// Example of using LoadAsync to load a texture
async Task LoadTextureAsync()
{
BaseFileSystem fileSystem = FileSystem.Mounted;
string filePath = "textures/mytexture.vtex";
bool warnOnMissing = true;
Texture texture = await Texture.LoadAsync(fileSystem, filePath, warnOnMissing);
if (texture != null)
{
// Use the loaded texture
}
else
{
// Handle the case where the texture could not be loaded
}
}