So my problem is fairly simple: if a ui sprite is partially offscreen (like more than half of it), move it toward the center. The context is that I can select objects in the game, and when I do a menu pops up over the selected object. It doesn't look good if the object is near the edge of the screen and the menu is partially cut off after it appears (i.e. with parts of the menu being rendered off screen).
So one option is to detect if a ui sprite button is offscreen. I've noticed that if the sprite's transform position (not local position) is less than -1.0 in any dimension or more than 1.0 in any dimension, then at least half of it is off-screen. It seems as if NGUI objects end up in a coordinate system that goes from -1.0 to 1.0 in X and Y. Is that a reasonable assumption?
The next problem would be: how would I make sure that the sprite appears onscreen, or with no portions being rendered offscreen? One good solution is that I can push it toward the center by some offset (based on the size of the sprite portion that is off screen).
Edit: I found this thread
http://www.tasharen.com/forum/index.php?topic=9889.msg46501#msg46501Has references to HUDText (which I don't have). There are is also a warning regarding directly using Screen.width and height since the UIRoot's settings may not jive with that idea. So I thought it would be best to rely on the (-1.0, 1.0) transformed coordinates to figure out how much of the sprite is offscreen.