EDITED for clarity:
There are three UIWidget-derived objects in NGUI: UILabel, UISprite, and UITexture. The UIWidgetInspector class utilizes this fact and offers a pivot alignment control within the Unity Inspector, which is awesome for when I want to align these against one edge, then change my mind and align them against a different edge.
The
UIButton and
UIImageButton classes do NOT derive from UIWidget, however, and I wonder how difficult it would be to create the same kind of pivot alignment controls for those. I find myself resizing buttons (by resizing the UISprite and UILabels within them) in the editor, which requires adjustment to the parent GameObject and its BoxCollider each time.
In order to manually set a button's pivot to the bottom-right, I need to:
- Scale the child UISprite to the desired size, then offset it by -1/2 its x scale and 1/2 its y scale (the sprite will appear too high and too far left)
- Use the same x and y positions for the UILabel as the UISprite (the label should appear to be centered over the UISprite, which is up and left of the main UIButton's center point)
- On the parent UIButton's BoxCollider, match both the UISprite's x and y positions as well as the x and y scales (the collider should now align over the top of the sprite)
- Now, the button's pivot should be in the bottom-right corner of the button
Once the button's pivot is in the bottom-right corner, if I decide to increase the offset from the edge of the panel, there's no need to recalculate the UISprite's dimensions (plus the edge offset) each time: I can simply set the GameObject's position directly to the desired offset.
But if I want to change the pivot (like if I decide the button should go in a different corner, or even centered in the panel), I have to repeat steps 1-4 again with the new offsets.
Could I request a similar "one-button solution" like we have with the UIWidgetInspector's alignment tools, for UIButtons an UIImageButtons? That would be awesome!