Search Unity

UI Issue with Xiaomi devices

Discussion in 'Xiaomi' started by DaniyarGilymov, Jan 17, 2019.

  1. DaniyarGilymov

    DaniyarGilymov

    Joined:
    Dec 26, 2017
    Posts:
    14
    In Xiaomi devices, there are drawn an image outside of camera's letterbox
    In other devices everything is correct
    I attached both sumsung and xiaomi images, the screenshot that looks ugly is xiaomi

    Code (CSharp):
    1. float targetaspect = 750f / 1334f;
    2.  
    3.         // determine the game window's current aspect ratio
    4.         float windowaspect = (float)Screen.width / (float)Screen.height;
    5.  
    6.         // current viewport height should be scaled by this amount
    7.         float scaleheight = windowaspect / targetaspect;
    8.  
    9.         // obtain camera component so we can modify its viewport
    10.         Camera camera = GetComponent<Camera>();
    11.  
    12.         // if scaled height is less than current height, add letterbox
    13.         if (scaleheight < 1.0f)
    14.         {
    15.             Rect rect = camera.rect;
    16.             rect.width = 1.0f;
    17.             rect.height = scaleheight;
    18.             rect.x = 0;
    19.             rect.y = (1.0f - scaleheight) / 2.0f;
    20.             camera.rect = rect;
    21.         }
     

    Attached Files:

  2. You just posted in the wrong forum. Please hit the Report link on your initial post and ask the moderators to move it into the Platforms/Xiaomi forum, where there are clever people who probably can help with your problem. General Discussion isn't a support forum.
     
    DaniyarGilymov likes this.