Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. /*
  2. * Get a slice from a target Sprite based on a (X,Y) grid, (0,0) being the bottom left.
  3. * Requires a Sprite to be loaded using Resources.Load<Sprite>("Spritename").
  4. *
  5. * Param Sprite, int, int
  6. * Return Texture2D
  7. */
  8. Texture2D getSliceByXY(Sprite target, int xPos, int yPos) {
  9. Texture2D croppedTexture = new Texture2D (
  10. (int)target.rect.width,
  11. (int)target.rect.height
  12. );
  13.  
  14. Color[] pixels = faces.texture.GetPixels (
  15. faceWidth * xPos,
  16. faceHeight * yPos,
  17. faceWidth,
  18. faceHeight
  19. );
  20.  
  21. croppedTexture.SetPixels (pixels);
  22. croppedTexture.Apply (); // Upload changed pixels to the graphics card.
  23.  
  24. return croppedTexture;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement