Author Topic: How to handle creating an atlas during runtime  (Read 9333 times)

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
How to handle creating an atlas during runtime
« on: August 21, 2012, 01:07:32 PM »
Players have the ability to pull some images off of the internet and use them in-game.  However, I am not sure how to handle this using NGUI, considering you need an atlas, which needs a material with the image.  I effectively want the image to become a button which won't be hard once I figure out how to handle it.  Is creating a material, assigning that material the new Texture2D (Or whatever it would have to be), then creating an atlas with that material, be the best way, or what are other alternatives? 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to handle creating an atlas during runtime
« Reply #1 on: August 21, 2012, 01:14:11 PM »
Use UITexture for this.

DoctorWhy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: How to handle creating an atlas during runtime
« Reply #2 on: August 21, 2012, 03:18:32 PM »
Thanks.  A quick question though.  I will have a bunch of images loaded (upwards of 100+) on a draggable panel.  It says in the documentation that there is a draw call for each one of these.  Will that be a problem?  Also, when they are disabled in unity, I am guessing there will not be a draw call?   If both of those are true, I can probably make it so the ones that are not seen will be disabled, which would probably work.

PhilipC

  • Guest
Re: How to handle creating an atlas during runtime
« Reply #3 on: August 21, 2012, 03:57:59 PM »
If you have that many images loaded at once think about creating your own atlas at run time. (i.e. get the images and pack them into a single texture). You can then still use the UITexture but now specify the UV's of the image you want. This will help reduce your draw calls.

teeleton

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: How to handle creating an atlas during runtime
« Reply #4 on: September 10, 2012, 11:27:46 PM »
What about the rest of the atlas metadata like slicedsprite borders and such?  Not quite wrapping my head around how to define those values at runtime.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to handle creating an atlas during runtime
« Reply #5 on: September 11, 2012, 03:34:25 AM »
Everything you can do via the editor can also be done at run-time. As Phil suggested, if you're concerned with draw calls (which are only a factor if you're targeting a mobile device), then batching a bunch of textures into one would help. Texture2D.PackTextures can be used to create one large texture containing smaller ones.

basil_11

  • Guest
Re: How to handle creating an atlas during runtime
« Reply #6 on: December 10, 2012, 12:02:05 AM »
If you have that many images loaded at once think about creating your own atlas at run time. (i.e. get the images and pack them into a single texture). You can then still use the UITexture but now specify the UV's of the image you want. This will help reduce your draw calls.

--> everything that is done in Editor Can be done in RunTime
-- (i.e. get the images and pack them into a single texture) it is better if there are some codes for this. thanks in advance

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: How to handle creating an atlas during runtime
« Reply #7 on: December 10, 2012, 01:29:52 AM »
Look in the UIAtlasMaker script, line 108, there is a method PackTextures that calls either the defaut Unity packing method (texture2D.PackTextures) or another one added by NGUi UITexturePacker.PackTexture

basil_11

  • Guest
Re: How to handle creating an atlas during runtime
« Reply #8 on: December 10, 2012, 04:26:29 AM »
thanks, but how can I add/create atlas in runtime?
for ex.
   ->OnStart() of the program, I want to Pack textures
   - > How can I call the TexturePacker in runtime?

thanks master!!!

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile