I'm trying to use GetData() on a Texture2D, as such:
/// <summary>
/// Manually replaces a specified color in a texture with transparent black,
/// thereby masking it.
/// </summary>
/// <param name="Texture">The texture on which to apply the mask.</param>
/// <param name="ColorFrom">The color to mask away.</param>
private static uint[] SINGLE_THREADED_TEXTURE_BUFFER = new uint[MaxResampleBufferSize];
public static void ManualTextureMaskSingleThreaded(Texture2D Texture, uint[] ColorsFrom)
{
var ColorTo = Color.TransparentBlack.PackedValue;
var size = Texture.Width * Texture.Height;
uint[] buffer = SINGLE_THREADED_TEXTURE_BUFFER;
Texture.GetData<uint>(buffer);
var didChange = false;
for (int i = 0; i < size; i++)
{
if (ColorsFrom.Contains(buffer[i]))
{
didChange = true;
buffer[i] = ColorTo;
}
}
if (didChange)
{
Texture.SetData(buffer, 0, size);
}
else return;
}
But it always returns an array of 0s. Why? :\