static Task<Texture> LoadAsync( BaseFileSystem filesystem, string filepath, bool warnOnMissing )

book_4_sparkGenerated
code_blocksInput

Description

The LoadAsync method is a static method of the Texture class in the Sandbox namespace. It asynchronously loads a texture from a specified file path within a given file system. This method is useful for loading textures without blocking the main thread, which is essential for maintaining smooth performance in applications.

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 to log a warning if the texture file is not found.

The method returns a Task<Texture>, which represents the asynchronous operation. You can await this task to get the loaded Texture object once the operation is complete.

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
        Console.WriteLine("Texture loaded successfully.");
    }
    else
    {
        Console.WriteLine("Failed to load texture.");
    }
}