Best way to support multiple aspect ratio Devices (Android & IOS) via Scripting

Hello everyone, i’m actually making a game and i have some buttons and stuff but i’m NOT using GUI to control them, it’s something like an app more than a game.

So, i have this hierarchy: An empty GameObject father who contains the background of the screen and the buttons, bars etc… I make all this manually, even the touch (Using raycast, etc.)

So, here is the problem: When i try to build to different devices i have black spaces on the sides, i know that this is happening because i’m not doing my screens relative to the Device screens like in GUI (Rect(screen.width…)).

So, what ideas do you have to solve a problem like that? Thanks!

Hello!

Most GUI assets like NGUI have anchors that you can set to snap to the corners and sides of the screen. So for example, we can set an anchor at the top center, top left, and top right of the screen. We don’t have any screen-wide GUI elements, but instead floating elements attached to the corners/center.

On widescreens, there is a gap between the top left and top right GUI elements. On skinny screens, the corners are closer together so the left and right GUI elements are closer together.

I created a AssetStore extension that allows for easier aspect switching called AspectSwitcher. It provides a system for allowing you to easily specify different properties for different aspects. There are generally two method that most people use to switch aspects. One is to provide different game objects for each aspect. The other is to create custom code that modifies the properties of a single game object based on the current aspect. That generally requires a lot of custom coding. My extension attempts to alleviate a lot of that pain.

If you’re using an Animator, you can create a new layer that uses either blend trees or a simple decision to change between portrait/landscape. This is especially useful if you have a graphic designer on board - he can put it on record mode for that one animation and lay out your GUI elements visually, which in my experience is more the “native language” of most designers as opposed to placing elements in code. :slight_smile: