Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Get a slice from a target Sprite based on a (X,Y) grid, (0,0) being the bottom left.
- * Requires a Sprite to be loaded using Resources.Load<Sprite>("Spritename").
- *
- * Param Sprite, int, int
- * Return Texture2D
- */
- Texture2D getSliceByXY(Sprite target, int xPos, int yPos) {
- Texture2D croppedTexture = new Texture2D (
- (int)target.rect.width,
- (int)target.rect.height
- );
- Color[] pixels = faces.texture.GetPixels (
- faceWidth * xPos,
- faceHeight * yPos,
- faceWidth,
- faceHeight
- );
- croppedTexture.SetPixels (pixels);
- croppedTexture.Apply (); // Upload changed pixels to the graphics card.
- return croppedTexture;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement