Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Adjust screen to liquid design interface (2D)

Discussion in 'General Graphics' started by bsivko, Mar 26, 2019.

  1. bsivko

    bsivko

    Joined:
    Jan 24, 2018
    Posts:
    2
    I'm trying to implement liquid design and faced some problems that deployed appliaction works different. In Unity with different size of game-window works fine, but deployed camera mostly capture only small part of scene.

    I have orthograpic camera, game field as example is 40x30. I need to put it in the screen which can have different resolution.

    Camera: https://i.ibb.co/DGNKTZW/orth-camera.png
    Code:
    Code (CSharp):
    1.  
    2.         // Camera adjusting.
    3.         _camera.orthographicSize = Screen.height / 2 / 100.0f;
    4.  
    5.         Debug.Log("_camera.orthographicSize:" + _camera.orthographicSize);
    6.  
    7.         Debug.Log("Screen.height:" + Screen.height);
    8.         Debug.Log("Screen.width:" + Screen.width);
    9.  
    10.         // Field Plane - back of allplane with drag events.
    11.         {
    12.             var t = _fieldPlane.GetComponent<Transform>();
    13.             var l = t.localScale;
    14.  
    15.             l.y = Screen.height / 100.0f;
    16.  
    17.             l.x = l.y * Env._instance._fieldWidth / Env._instance._fieldHeight;
    18.  
    19.             if (l.x > Screen.width / 100.0f)
    20.             {
    21.                 float k = l.x / (Screen.width / 100.0f);
    22.                 l.x /= k;
    23.                 l.y /= k;
    24.             }
    25.             t.localScale = l;
    26.             Debug.Log("t.localScale:" + t.localScale);
    27.  
    28.             _one_cell_x = l.x / Env._instance._fieldWidth;
    29.             _one_cell_y = l.y / Env._instance._fieldHeight;
    30.             Debug.Log("_one_cell_x:" + _one_cell_x);
    31.             Debug.Log("_one_cell_y:" + _one_cell_y);
    32.  
    33.             var pos = t.localPosition;
    34.             pos.y = 0;
    35.             pos.x = 0;
    36.             t.localPosition = pos;
    37.         }
    _fieldPlane - background component, it should be fit to screen.
    _one_cell_x, _one_cell_y - x,y-size of one cell.

    The code starts on GameObject of scen, in Start() method.

    If I start it on iPhone 8, the logs are:

    Code (csharp):
    1. _camera.orthographicSize:3.75
    2. Screen.height:750
    3. Screen.width:1334
    4. t.localScale:(10.0, 7.5, 1.0)
    5. _one_cell_x:0.25
    6. _one_cell_y:0.25
    Screen.width and Screen.height are correct, _camera.orthographicSize takes half of height, one cell is 0.25x0.25, which is 40x30 for 10x7.5

    However, if I deploy it on the phone, the result is looks like: https://i.ibb.co/2h24sFS/IMG-2660.png
    There is a block 1x3 in the scene.

    In Unity the camera captures a bigger picture and it fits the screen well:https://i.ibb.co/B4mfWqf/unity-3x2.png

    How to tune such kind of liquid design properly?
     
  2. bsivko

    bsivko

    Joined:
    Jan 24, 2018
    Posts:
    2
    Some research brought up some results..

    One more thing of implementation is the following. We have several scenes and put into all of them Camera instances which are instances of one prefab. The code above runs in one GameObject (method Start()), which is in the scene. The GameObject has a link to Camera prefab:

    Code (CSharp):
    1. [SerializeField] public Camera _camera;
    and it's managable via inspector.

    So, if we drag and set original prefab (from directory with all prefabs), the glitch is present. If we drag and set instance of prefab (which is in the scene), it works as expected.

    We expected, that if we have a prefab object in the scene, and we change the original prefab, it effects all of instances (we can set up camera once and use in all scenes). And it works in Unity environment. However, in deployed application it might not work like that.
    If we change the link (drag and set _camera) to _camera in the scene (the blue one), it works in Unity and in the deployed application.

    And now the question is.. is it our misunderstanding of prefab Unity mechanisms or it's a glitch?
    The idea of glitch came up because the behaviour is different for unity environment and for deployed application.