Author Topic: Best practice with automated HD -> SD atlas?  (Read 2732 times)

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Best practice with automated HD -> SD atlas?
« on: September 17, 2014, 03:25:03 AM »
Background: My hope was to replace all UISprites with UI2DSprites with Unity 4.6 but due to no support for GUIs which use the "HD mode via 0.5 pixel size + half resolution UI Root" technique, I'm not able to convert my GUI to pure UI2DSprites. Sliced sprites end up 2x too big with the above technique since the 0.5 pixel size does not get applied to them. =(

Problem: The above limitation means that I'm stuck using an NGUI atlas for my GUI, which is okay, except that as far as I can tell, there's no elegant way to auto-create an SD atlas from an HD one. We use TexturePacker for our non-NGUI sprites with an HD and SD "scale factor" to do output variants as Multiple-Sprite Sheets, and the awesome part is that it defines all the sprites rectangles for us. (big time saver since we change the sprites a lot)

As far as I can tell, the only way to get the same effect with NGUI is to have an HD and SD texture for every sprite (so no using "Sprite Mode: Multiple") and then manually create an atlas for both. Is there some trick I'm missing? For example: is there some way to convert a Multiple-Sprite Sheet into an NGUI atlas? This would allow us to still use TexturePacker and automate something that we're doing by hand just for NGUI (and not for the rest of the game).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best practice with automated HD -> SD atlas?
« Reply #1 on: September 17, 2014, 12:39:06 PM »
You can overwrite the pixelSize property, which is what UISprite uses to pass the value from the atlas. You can do the same thing on the UI2DSprite if you like. For example I just added a "float mPixelSize;" that I return in the overwritten pixelSize property, and with the NGUIEditorTools.DrawProperty("Pixel Size", serializedObject, "mPixelSize"); to draw it in the UI2DSpriteEditor.

Wisteso

  • Full Member
  • ***
  • Thank You
  • -Given: 21
  • -Receive: 3
  • Posts: 103
    • View Profile
Re: Best practice with automated HD -> SD atlas?
« Reply #2 on: September 26, 2014, 05:41:02 AM »
Overwriting pixelSize worked great for most sprites. However, pixelSize does not appear to be applied to the border dimensions. So SD/HD versions of any sliced sprites end up looking pretty messed up.

Could I just change the "border" -> "set" handler to multiply mBorder.XYZW with pixelSize? And then the same idea in the Awake() method to handle serialized values? Although maybe I should store a pre-multiplied copy of the mBorder, in case the pixelSize gets modified later and recalculation is needed.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best practice with automated HD -> SD atlas?
« Reply #3 on: September 27, 2014, 06:18:08 PM »
Simply add it to line 214 of UI2DSprite:
  1. Vector4 br = border * pixelSize;