获取Unity中的Windows缩放和布局

huangapple go评论87阅读模式
英文:

Get windows scale and layout in Unity

问题

我想知道在Unity中是否有可能获取Windows的缩放和布局(以百分比表示)。

在本机C#应用程序中可以通过以下方式实现:

public static int GetWindowsScaling()  
{  
    return (int)(100 * Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth);  
}

在Unity中是否可能实现相同的功能?

英文:

I would like to know if it is possible to get windows Scale and Layout (in percent) in Unity.
It is possible to do it in native C# application through:

public static int GetWindowsScaling()  
        {  
            return (int)(100 * Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth);  
        }  

Would it be possible to do the same in Unity?

获取Unity中的Windows缩放和布局

答案1

得分: 2

查看是否有帮助 Screen.DPI。这应该为您提供相对于参考 DPI(通常为 96)的缩放因子。

此外,您可以使用 Screen.widthScreen.height 来获取窗口的宽度和高度(以像素为单位)。

希望这些有帮助。

英文:

See if this helps Screen.DPI. This should give you the scale factor against the reference DPI(usually 96).

Also, you can use Screen.width and Screen.height to get window width and height in pixels.

hope these help.

huangapple
  • 本文由 发表于 2023年6月22日 18:01:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定