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.
  2. Dismiss Notice

Pixels Per Point

Discussion in 'Scripting' started by tiggaxxx, May 6, 2020.

  1. tiggaxxx

    tiggaxxx

    Joined:
    Jan 13, 2020
    Posts:
    30
    Hi guys,
    So, i have a 3D webgl widget built with Unity, and i need a way to get pixel density outside the editor, to correct some object positioning on retina screens..

    I know about the EditorGUIUtility.pixelsPerPoint, but that only works inside the editor...
     
  2. Bersaelor

    Bersaelor

    Joined:
    Oct 8, 2016
    Posts:
    110
    I'm wondering about the exact same issue, have you ever found a solution?
     
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Screen.width / Screen.height
    Camera.pixelWidth / Camera.pixelHeight
    Camera.scaledPixelWidth / Camera.scaledPixelHeight

    To get pixelsPerPoint you need to define what's a point. If you mean a point like a physical unit measuring 1/72 inches in printing and typography, then it is hardware-dependent.

    EditorGUIUtility.pixelsPerPoint is specifically intended to represent some hard-set values. And this is highly volatile, as evidenced by the docs
    So this is hardly a scientific approach, more like a convenience.

    Given that this screen density was initially pushed by Apple, they have a tendency to align things with physical reality, and so they opted for PPI measure of physical "points per inch" which is a standard that is used to describe the density of the physical cells of a display device while reserving the term "pixel" for the actual software content.

    So what you really want is to find this measure, and because these standards are cringe, there is also DPI, which is a printing industry standard, known as "dots per inch". And indeed, you have things like Screen.dpi, but also solutions like these.

    Check out this thread as well.

    Disclaimer: I am not an expert, this has all been a product of a 5-minute research, with some prior background.