Search Unity

Correct unity banner height [Not solved]

Discussion in 'Unity Ads' started by Kongotec, Jun 14, 2019.

  1. Kongotec

    Kongotec

    Joined:
    May 22, 2013
    Posts:
    5
    Im having problems getting the unity ads banner height correctly on iphone 7+

    There is an old thread on the topic, but its incorrect (?)
    https://forum.unity.com/threads/solved-what-are-unity-banner-dimensions.578812/

    It seems that on iphone 7+, unity renders the screen at
    Screen.width = 1080
    Screen.height = 1920
    Screen.dpi = 401

    Then scales the rendered image to 1242 x 2208 and adds the banner which is 150px high in this resolution.
    (Then scales down this image to 1080 x 1920 again for native display, however device screendumps is still 1242x2208)

    So the correct height of the banner in rendered 1080x1920 image is 130.43478260869566px

    Calculated like this:
    ---------------------

    float bannerPointHeight = 50.0f;
    float retinaLevel = 3.0f;

    float screenRenderedWidth = 1080.0f;
    float screenScaledWidth = 1242.0f;

    float screenPixelSize = bannerPointHeight * retinaLevel * (screenRenderedWidth / screenScaledWidth);

    // I prefer the height to be bigger then the banner if half pixels
    screenPixelSize = Mathf.Ceil(screenPixelSize);

    Debug.Log(screenPixelSize);

    ---------------------

    The problem is that i dont know how to find the 1242 width from unity, maybe its not even aware of this width?

    The suggested

    public float GetBannerHeight()
    {
    return Mathf.RoundToInt(50 * Screen.dpi / 160);
    }

    results in 125.3125px on iphone 7+ btw.

    Is it possible to calculate the correct banner height, in a future proof manner, without special cases for all devices?
    Im using unity 2019.2.0b2

    ---------------------

    https://developer.apple.com/library...iOSDeviceCompatibility/Displays/Displays.html
    Using the native scale factor multiplying the banner point height 50 * 2.608 = 130.4 which is correct.

    Is the native scale factor available from unity?
     
  2. Kongotec

    Kongotec

    Joined:
    May 22, 2013
    Posts:
    5
    Not possible?
     
  3. 009

    009

    Joined:
    Nov 7, 2013
    Posts:
    13
    I tried this
    public float GetBannerHeight()
    {
    return Mathf.RoundToInt(50 * Screen.dpi / 160);
    }

    and divide it by the canvas scale factor

    GetBannerHeight() / targetCanvas.scaleFactor;

    Works well on my android device, maybe you can try this
     
    Kongotec likes this.
  4. Kongotec

    Kongotec

    Joined:
    May 22, 2013
    Posts:
    5
    Your solution works on most devices, except iphone 6+, 6s+, 7+ and 8+, possibly more

    These plus models adds a downsampling step: renderedResolution / 1.15 = physicalPixels.
    https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

    So:

    float downsample = 1.15f; // 1.0f on most devices
    150.0f / downsample / targetCanvas.scaleFactor;

    Gives the correct height, but I dont know how to find the 1.15 downsample for devices with these workings.

    Unity with Metal on mentioned devices, renders 1080 x 1920 then then scales to 1242x2208 and adds the 150px high banner (50x3) then downscales to 1080 x 1920. (Or at least, banner height calculations suggest)

    To figure out the downsample, I need to know either 1.15 or both resolutions ie 1242/1080 = 1.15

    I could write special cases to each DeviceGeneration, but Id prefer a non specific solution.
     
    Last edited: Jun 25, 2019
  5. Kongotec

    Kongotec

    Joined:
    May 22, 2013
    Posts:
    5
    This special case code would give the correct calculation on above mentioned iphone+ models, is the dpi wrong?

    public float GetBannerHeight() // Should return 130 or non rounded 130.43478260869566px ion iPhone + models (150 / 1.15)
    {
    float screenDpi = 417.391304347826112f; // Instead of Screen.dpi which is reportad as 401
    return Mathf.RoundToInt(50 * screenDpi / 160);
    }

    GetBannerHeight() / targetCanvas.scaleFactor;
     
    Last edited: Jun 25, 2019