void Update( System.ReadOnlySpan<System.Byte> data, int x, int y, int width, int height )
void Update( System.ReadOnlySpan<T> data, int x, int y, int width, int height )
void Update( System.ReadOnlySpan<Color32> data, int x, int y, int width, int height )
void Update( Color32 color, Rect rect )
void Update( Color32 color, float x, float y )

book_4_sparkGenerated
code_blocksInput

Description

The Update method of the Texture class allows you to update a specific region of the texture with new pixel data. This method is useful for dynamically changing the texture content at runtime.

Usage

To use the Update method, you need to provide the following parameters:

  • data: A ReadOnlySpan<byte> containing the pixel data to update the texture with. The data should be in a format compatible with the texture's current format.
  • x: The x-coordinate of the top-left corner of the region to update.
  • y: The y-coordinate of the top-left corner of the region to update.
  • width: The width of the region to update.
  • height: The height of the region to update.

Ensure that the specified region is within the bounds of the texture to avoid runtime errors.

Example

// Example of updating a texture region
Texture myTexture = ...; // Assume this is an existing texture

// Define the region to update
int x = 10;
int y = 20;
int width = 50;
int height = 50;

// Create pixel data to update the texture
byte[] pixelData = new byte[width * height * 4]; // Assuming 4 bytes per pixel (e.g., RGBA)
// Fill pixelData with your desired color data

// Update the texture
myTexture.Update(pixelData, x, y, width, height);