Search Unity

UI Screen.orientation - force GameView to change the orientation? How to design in editor?

Discussion in 'UGUI & TextMesh Pro' started by Annopolus, Oct 18, 2018.

  1. Annopolus

    Annopolus

    Joined:
    Apr 15, 2015
    Posts:
    18
    Hi,

    it's rather the question for best practice how to design UIs which are by design potrait and UI's by design landscape together the same time in editor.

    I'm making an app which heavily uses UI's with so many separate "screens" built on the Panels. There is a main parent panel with Canvas and Canvas Scaller Script which controlls all child screens in term of size. Switching between screens is just moving from script all panels from their "design" location in editor to cover canvas and back. So, easy and nothing strange.

    This approach let me to design all screens which their size is controlled by GameView parameters in edit mode and everything is ok when designing ie. all screen for Potrait orientation. I'm setting Potrait in the GameView, it impacts on the main panel with Canvas, Canvas Scaller resizes all child panels/screens. Everything is fine.

    However, the problem starts when I need to add another panel/screen which should be designed for landscape orientation. Screen.orientation is changing in runtime via script bfore switching panels/screens.

    1st problem is - how to design in editor such panel which intentionally should be landscape? Canvas Scaller will fit it in editor into parent which is potrait.

    2nd problem is - how to simulate orientation switching by script in GameView? Is GameView aware somehow that script will force to change the orientation?

    I tried to find an answer as I think it should be a very common problem for everybody having at least 2 UI screens with different orientations, but nothing.

    The only solution which I see for now is to split my app on 2 separate designing process and in separate work on portrait screens and on landscape screens. But it will be a nightmare for an app with many screens interacting each other.

    Best!
     
  2. Annopolus

    Annopolus

    Joined:
    Apr 15, 2015
    Posts:
    18
    I have an idea to let me design both landscape and portrait the same time in editor.
    1. I will set whole App to portrait (block against switching to landscape)
    2. I will "disconnet" landscape panels from impact of CanvasScaler and manually by script I'll resize them to the screen size
    3. In editor I will design them in landscape state as they should appear when app is running
    4. When it will be a time to show landscape screen in running app I will rotate it by 90 degrees and move to Canvas position to show.

    It will fix the 1st problem - it will let me design both orientations in editor the same time, however it will still not fix a behaviour of Game view.

    Any other ideas?