TextureScale

Author: Eric Haines (Eric5h5)

Description
If you've used Texture2D.Resize, you may have been disappointed to find that it only resizes the texture; it doesn't scale the contents. Using TextureScale, however, you can in fact do just that, using either bilinear or point (nearest neighbor) filtering. It also uses multi-threading to speed up the process on CPUs with more than one core. (Although SetPixels and Apply cause a pretty big hit, so the multi-threading is perhaps limited in usefulness, but it can still be nice for large textures, and in any case it's faster than not having it.)

Usage
Name this script TextureScale and have it somewhere in your project, preferably in a folder such as Standard Assets that compiles before other folders, so you can call it from C# or Boo. You can then call TextureScale.Bilinear to use bilinear scaling, and TextureScale.Point to use point scaling. The arguments are:

function Bilinear (texture : Texture2D, newWidth : int, newHeight : int) : void

texture is the texture that you want to scale using bilinear filtering. newWidth and newHeight are the desired dimensions for the texture. It will be resized using Texture2D.Resize, and the contents scaled. Texture2D.Apply is called when done so that the changes take effect immediately. The texture must be RGBA32, RGB24, or Alpha8 in order for the function to work, and also must be read/write enabled.

function Point (texture : Texture2D, newWidth : int, newHeight : int) : void

The same as above, except point filtering is used instead of bilinear.

Note that the functions resize the texture that's passed in; they don't return a new texture. An example of usage:

Note that you probably don't want to scale the actual textures in your project. Instantiate a copy first, as shown in the code above.