Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Convert Screen.height to constant physical size Points?

Discussion in 'UGUI & TextMesh Pro' started by Gordon_G, Aug 18, 2022.

  1. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    Hi, I've got a Canvas Scaler set to Constant Phyisical Size in Points units, so that I can show chat messages at the same size no matter the device. the Chat messages are displayed in a ScrollView Content holder.

    All this works fine but I need to set the height of the Content holder to change it's height based on the screen height of the device.

    Do do this I need to be able to convert Screen.height to my Constant Physical size units, which is Points. I understand that I need the dpi of the device in the calculation but am lost on what to do with dpi and Screen.height from there.

    Can anyone help with the calculation needed?
     
  2. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    OK, I think I got it:

    It seems by definition there are 72 Points per inch.

    From there I need to get the number of pixels per inch. The DPI of the device will give me that.

    So the formula should be:

    inches = Screen.Height / Device DPI
    points = inches * 72

    therefore, the screen height in points is:

    points = ( Screen.Height / Device DPI ) * 72

    How's my math - this is correct?