Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: kamil.slawicki on December 20, 2013, 11:08:23 AM

Title: Sprite information in UV space?
Post by: kamil.slawicki on December 20, 2013, 11:08:23 AM
Hi there.

Is there a way to get sprite's x, y, width and height in uv coords rather than pixels? I know I can divide by the atlas texture width/height but I was hoping there was a built in way to do that. I recently converted from 2.x to 3.x and it looks like this stuff has been dropped.

Thanks.
Title: Re: Sprite information in UV space?
Post by: ArenMook on December 20, 2013, 11:31:31 AM
TexCoords were dropped, yes. You have to calculate it manually now. Why do you need this?
Title: Re: Sprite information in UV space?
Post by: kamil.slawicki on December 20, 2013, 12:00:13 PM
We are setting textures for particle systems to use the same texture as a sprite.

  1. IconMaterial.mainTexture = IconSprite.mainTexture; // load the texture used by the sprite
  2. IconMaterial.mainTextureOffset = new Vector2((float)IconSprite.GetAtlasSprite().x / IconSprite.mainTexture.width, 1 - (float)IconSprite.GetAtlasSprite().y / IconSprite.mainTexture.height - (float)IconSprite.GetAtlasSprite().height / IconSprite.mainTexture.height); // set UVs of that particular icon
  3. IconMaterial.mainTextureScale = new Vector2((float)IconSprite.GetAtlasSprite().width / IconSprite.mainTexture.width, (float)IconSprite.GetAtlasSprite().height / IconSprite.mainTexture.height); // same here
  4.  

I was just testing stuff a second ago so forgive my poor formatting. I was thinking to make an extension method for UISprite that returns a Vector2 for x,y and another one for width,height.