... Or, possibly, just a bit more control over a UIDraggablePanel? I think the former would give more flexibility, but whatever works best.
UIStretch does a good job of stretching transforms to proportions of the screen size, but it's not really enough when you're dealing with different aspect ratios and resolutions. For my current project, I've had to copy/paste and adapt UIStretch to create several new but very similar components:
- UIAspectStretch - to stretch widgets (particularly non-sliced sprites) whilst maintaining their original aspect ratio (because using UIStretch alone, a sprite that looks normal on an iPhone will look squashed on an iPad because of the different aspect ratios)
- UIPixelStretch - Like UIStretch but with an additional pixel component in addition to relativeSize, so you can say "I want this to be 0.75 of the screen width, minus 20 pixels". Again, this allows for more precise layouts when building something to run in different aspect ratios, by making the horizontal and vertical gaps between things always be consistent
- UIPanelStretch - changes a UIPanel's clipping region, rather than an object's Transform. This is essential if you want to have a UIDraggablePanel that's clipped to some proportion of the screen size rather than an absolute amount
- UIGridStretch - Also for UIDraggablePanels, but for any use of grids in which the grid elements are scaled: Changes the grid spacing depending on the size of some scaled widget, and updates the grid positioning. Means that if you have a grid of things on (say) an iPad2, and you stretch them to be the same relative size on an iPad3, the grid doesn't leave them overlapping but spreads them out properly
- UIColliderStretch - Again, made necessary by having a scaled UIDraggablePanel. Scales the BoxCollider for an object to keep all the collision working properly
None of that was difficult to do, but it was a bit annoying that it was necessary, and it involved a lot of copy/pasting of the code. In general, they all calculate the rectangle size in the same way as UIStretch, but then all do different things with them. In future, I'm wondering if it's possible to have UIStretch be able to adjust these things as well as just the transform, or for it to be refactored in such a way that the code to calculate the scaling rectangle is more re-usable.
Also, it would be brilliant if stretching didn't have to happen every Update, but only when something external has changed (i.e. the window the game is running in, or the size of some object that the stretch is using as a reference). It would save a lot of unnecessary processing, although I admit that it doesn't sound easy to properly propagate the information that relevant reference points have changed.