Skip to content

Instantly share code, notes, and snippets.

@haikusw
Created August 7, 2012 23:19
Show Gist options
  • Save haikusw/3290457 to your computer and use it in GitHub Desktop.
Save haikusw/3290457 to your computer and use it in GitHub Desktop.
some snippets of a routine to create a dynamically drawn on 2d texture in unity
Dynamic drawing to a texture in Unity3d basic. This is not complete working code but pieces cut out of working code so you'll have to look up the documentation for the functions called to get specific parameters and such.
static function CreateFooTexture ( ... )
{
// create texture:
var tex : Texture2D = new Texture2D(512, 512, TextureFormat.ARGB32, false);
// get the pixels
var cols : Color[] = tex.GetPixels( ... );
// set the specific color values in cols here based on whatever your algorithm is:
...
// things like: cols[rowbytes*ap.y + ap.x] = color;
...
// then update the texture
tex.SetPixels( ... , ..., rowbytes, rowbytes, cols );
tex.Apply();
// set any texture properties you need
tex.wrapMode = TextureWrapMode.Clamp;
return tex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment