Unity 3D - Sprite with the same physical size

I am trying to create an image with an accuracy of 5 cm x 8 cm on any device. The problem is this: the devices have different dots per inch (dpi), which means that I need different pixel sizes to create the image. How can I calculate these different pixel sizes?

My approach:

  • Convert cms → inches

    float widthInches = 5f / 2.54f; // 1.9685f;

    float heightInches = 8f / 2.54f; // 3.1496f

  • Find pixel size

    float realWidthSize = Screen.dpi * widthInches;

    float realHeightSize = Screen.dpi * heightInches;

I did these tests on my devices and the results were not as expected. Am I doing something wrong?

+4

Source: https://habr.com/ru/post/1616816/


All Articles