1
NGUI 3 Support / Re: PixelPerfect and Atlas switching
« on: January 04, 2014, 08:48:40 PM »
To answer your question Frank, we ended up keeping the pixel perfect root, and dealing with the atlas switch by calling MakePixelPerfect, doing something like this to catch the widgets which are inactive at the time (I don't have the code in front of me, so this might not be 100% right):
It's slow, but you should only need to do it once. We also ended up basically replacing UIStretch with a number of custom versions, in order to stretch Colliders, UIGrid spacing, the areas in which UILabels can draw, etc. All of these could scale using "pixels" as well as/instead of the standard relative scaling. "Pixels" in this case could be adapted by some settings in our custom UIRoot, so that if you stretch something to be (say) 100 pixels wide, then that gets combined with a multiplier. When using standard def atlases, the multiplier is 1. When using HD atlases, it's 2, so the widget ends up 200 pixels wide, which is what you want.
The MakePixelPerfect call should (in theory) deal with most of this, but in practice we found that we had to attach custom anchors and stretches to pretty much everything in the scene, which then meant we had to add performance optimisations like the ability to turn all those anchors and stretches off after a set number of frames, once the screen had settled down. It was, to put it politely, a bit of a pain to get working, and something we definitely won't be doing again. As a result of all the custom code, we're a few versions behind on NGUI now, but I sincerely hope that more recent versions (or ones in the near future) support the PixelPerfect option in UIRoot properly, or remove it entirely.
If you're interested in the results, this is what I built: https://itunes.apple.com/gb/app/smash-bandits/id602403667?mt=8 - we had some praise for having a nice crisp UI, but in the end I'm not convinced that the extra effort was worth it. Better to ignore the PixelPerfect option, go with a relatively-scaled UIRoot, and if needs be write a custom component to specifically call MakePixelPerfect on any widgets that really need it. If you need to support both portrait and landscape mode, I'd suggest building a seperate UI for each orientation.
- // This code is called from with a custom version of UIRoot - if you want to put it somewhere else, you'll need to find the UIRoot in the scene.
- Component[] widgets = GetComponentsInChildren(typeof(UIWidget), true); // search for inactive children as well
- foreach(UIWidget widget in widgets)
- {
- if(widget != null)
- widget.MakePixelPerfect();
- }
It's slow, but you should only need to do it once. We also ended up basically replacing UIStretch with a number of custom versions, in order to stretch Colliders, UIGrid spacing, the areas in which UILabels can draw, etc. All of these could scale using "pixels" as well as/instead of the standard relative scaling. "Pixels" in this case could be adapted by some settings in our custom UIRoot, so that if you stretch something to be (say) 100 pixels wide, then that gets combined with a multiplier. When using standard def atlases, the multiplier is 1. When using HD atlases, it's 2, so the widget ends up 200 pixels wide, which is what you want.
The MakePixelPerfect call should (in theory) deal with most of this, but in practice we found that we had to attach custom anchors and stretches to pretty much everything in the scene, which then meant we had to add performance optimisations like the ability to turn all those anchors and stretches off after a set number of frames, once the screen had settled down. It was, to put it politely, a bit of a pain to get working, and something we definitely won't be doing again. As a result of all the custom code, we're a few versions behind on NGUI now, but I sincerely hope that more recent versions (or ones in the near future) support the PixelPerfect option in UIRoot properly, or remove it entirely.
If you're interested in the results, this is what I built: https://itunes.apple.com/gb/app/smash-bandits/id602403667?mt=8 - we had some praise for having a nice crisp UI, but in the end I'm not convinced that the extra effort was worth it. Better to ignore the PixelPerfect option, go with a relatively-scaled UIRoot, and if needs be write a custom component to specifically call MakePixelPerfect on any widgets that really need it. If you need to support both portrait and landscape mode, I'd suggest building a seperate UI for each orientation.