Author Topic: How can I use NGUI Atlases in standard Mesh Renderer?  (Read 3214 times)

trzmiel

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
How can I use NGUI Atlases in standard Mesh Renderer?
« on: April 09, 2015, 04:13:01 AM »
I would like to use NGUI Atlases outside NGUI. Just to map sprites to the quads and use Mesh Renderer (or Sprite Renderer). Is it any script for it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How can I use NGUI Atlases in standard Mesh Renderer?
« Reply #1 on: April 09, 2015, 03:53:27 PM »
NGUI widgets are standard mesh renderers under the hood, except they're batched together.

If you want to just put a sprite onto an existing renderer, then you would need to specify the atlas material and set UV coordinates to be that of the sprite. You can calculate the UV coordinates by finding the sprite using UIAtlas.GetSprite, then using its x, y, width and height divided by the texture's width and height. You may also need to flip the Y (y = 1 - y).