I might be missing something obvious, but whenever I used Texture2D.Resize on a new texture thats been copied from another, it breaks the original. This doesn’t seem logical.
Here’s is the code snippet:
public Texture2D TextureBase;
void Start()
{
Texture2D scratchTexture = new Texture2D(TextureBase.width, TextureBase.height,TextureFormat.RGB24,false);
scratchTexture = TextureBase;
scratchTexture.Resize(8, 4);
scratchTexture.Apply(false);
}
Your code snippet will make TextureBase be 8x4 pixels in size, and it’s contents will be undefined. (Resize only changes the size of the texture, and the new contents are undefined).
You’ll probably leak one texture as well (you allocate new one, and then change the texture reference to point to the same object as TextureBase). Assignment operator on texture references just makes them point to the same object, it does not do a “copy textures”.
Ups! I was a bit too fast to open the champagne there. It doesn’t work for me. The mip maps are not generated unless I use Apply(true) on a copied texture.
I test it like this:
print( "before: " + [url]www.texture.mipmapCount[/url] );
var tex = [url]www.texture;[/url]
tex.Apply( true );
print( "after: " + tex.mipmapCount );
// returns "before: 1", "after: 1".
// should have returned "after: 11"
Oops you are right. Okay so the right way of doing it is this:
// Create empty texture set up to use mip maps
var tex = new Texture2D (4, 4, TextureFormat.ARGB32, true);
// Load image into mip mapped texture
www.LoadImageIntoTexture(tex);