Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity Texture2D efficient performance draw pixels

var pixels = myTexture.GetPixels32();
for (int i = 0; i < pixels.Length; i++) 
{
    pixels[i] = Color.black;
}
    
    // Draw ants
foreach (Ant ant in ants)
{
    for (int i = 0; i < cellSize; i++)
    {
        for (int j = 0; j < cellSize; j++) 
        {
            // TODO: calculate the index of the pixel in the flat array
            // Not 100% sure on that one tbh ;)
            var index = (ant.thisX * cellSize + i) + myTexture.width * (ant.thisY * cellSize + j);
            
            pixels[index] = Color.white
        }
    }
}

myTexture.SetPixels32(pixels);

myTexture.Apply();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #unity #efficient #performance #draw #pixels
ADD COMMENT
Topic
Name
4+4 =