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:
UIAtlas atlas = objectWithSprite.GetComponent<UISprite>().atlas;
UISpriteData sprite = objectWithSprite.GetComponent<UISprite>().GetAtlasSprite();
Texture2D atlasTexture = atlas.spriteMaterial.mainTexture as Texture2D;
Rect outer
= new Rect
(sprite
.x, sprite
.y, sprite
.width, sprite
.height);Rect uv0 = NGUIMath.ConvertToTexCoords(outer, atlasTexture.width, atlasTexture.height);
UITexture tex
= new UITexture
();tex.uvRect = uv0;
Texture2D t = tex.mainTexture;
Can someone please tell me what I am doing wrong please?