Author Topic: Sprite information in UV space?  (Read 2543 times)

kamil.slawicki

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Sprite information in UV space?
« 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.
Kamil Slawicki

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite information in UV space?
« Reply #1 on: December 20, 2013, 11:31:31 AM »
TexCoords were dropped, yes. You have to calculate it manually now. Why do you need this?

kamil.slawicki

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Sprite information in UV space?
« Reply #2 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.
Kamil Slawicki