Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - 19xdxd

Pages: [1]
1
NGUI 3 Support / Convert UISprite to Texture2D
« on: March 22, 2014, 06:31:32 AM »
Hi,

I'm having a bit of trouble converting UISprite to Texture2D

I only want the selected sprite to be converted to the Texture2D and not the whole thing

I have done the following so far:


  1. UIAtlas atlas = objectWithSprite.GetComponent<UISprite>().atlas;
  2. UISpriteData sprite = objectWithSprite.GetComponent<UISprite>().GetAtlasSprite();
  3.  
  4. Texture2D atlasTexture = atlas.spriteMaterial.mainTexture as Texture2D;
  5. Rect outer = new Rect(sprite.x, sprite.y, sprite.width, sprite.height);
  6. Rect uv0 = NGUIMath.ConvertToTexCoords(outer, atlasTexture.width, atlasTexture.height);
  7.  
  8. UITexture tex = new UITexture();
  9. tex.uvRect = uv0;
  10.  
  11. Texture2D t = tex.mainTexture;

Can someone please tell me what I am doing wrong please?

Pages: [1]