Exemplo n.º 1
0
    public static void UpdateReferencePPI(float referencePPI = 326.0f)
    {
#if LOG_DETAIL
        MoreDebug.MoreStaticLog <UITools>("referencePPI=" + referencePPI +
                                          ", Screen.dpi=" + Screen.dpi +
                                          ", width=" + Screen.width +
                                          ", height=" + Screen.height);
#endif

        float dpi = Screen.dpi;

        if (Mathf.Approximately(dpi, 0.0f))
        {
#if LOG_DETAIL
            MoreDebug.MoreStaticLog <UITools>("it's dpi is NOT known");
#endif
            // if the dpi is not valid, p2i is:
            ms_pixelToInchRate = 1.0f;
        }
        else
        {
            float widthPixel  = Screen.width;
            float heightPixel = Screen.height;
            if (Mathf.Approximately(widthPixel, 0.0f) || Mathf.Approximately(heightPixel, 0.0f))
            {
#if LOG_DETAIL
                MoreDebug.MoreStaticLog <UITools>("it's size is NOT known");
#endif
                // if the width or height is not valid, p2i is:
                ms_pixelToInchRate = referencePPI / dpi;
            }
            else
            {
                float widthInch  = widthPixel / dpi;
                float heightInch = heightPixel / dpi;

                const float tabletDiagonalInch = 6.0f;
                float       currDiagonalInch   = Mathf.Pow((widthInch * widthInch + heightInch * heightInch), 0.5f);
                if (currDiagonalInch < tabletDiagonalInch)
                {
                    // if current device is a phone, p2i is:
#if LOG_DETAIL
                    MoreDebug.MoreStaticLog <UITools>("currDiagonalInch= " + currDiagonalInch + ", it is a phone");
#endif
                    ms_pixelToInchRate = Mathf.Min(1.0f, referencePPI / dpi);
                }
                else
                {
#if LOG_DETAIL
                    MoreDebug.MoreStaticLog <UITools>("currDiagonalInch= " + currDiagonalInch + ", it is a tablet");
#endif
                    // if current device is a tablet, p2i is:
                    ms_pixelToInchRate = referencePPI / dpi;
                }
            }
        }

#if LOG_DETAIL
        MoreDebug.MoreStaticLog <UITools>("referencePPI=" + referencePPI +
                                          ", Screen.dpi=" + Screen.dpi +
                                          ", ms_pixelToInchRate=" + ms_pixelToInchRate);
#endif
    }