Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Convert Screen.height to constant physical size Points?

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

  1. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    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. streeetwalker

    streeetwalker

    Joined:
    Jun 4, 2013
    Posts:
    327
    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?