浏览代码

android dpi

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
424c2010
共有 1 个文件被更改,包括 36 次插入1 次删除
  1. 37
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs

37
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


static bool _ShowDebugLog;
public float devicePixelRatioOverride;
public float devicePixelRatioOverride {
get {
if (_devicePixelRatioOverride > 0) {
return _devicePixelRatioOverride;
}
#if UNITY_ANDROID
_devicePixelRatioOverride = AndroidDevicePixelRatio();
#endif
return _devicePixelRatioOverride;
}
}
#if UNITY_ANDROID
static float AndroidDevicePixelRatio() {
using (
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
) {
using (
AndroidJavaObject metricsInstance = new AndroidJavaObject("android.util.DisplayMetrics"),
activityInstance = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity"),
windowManagerInstance = activityInstance.Call<AndroidJavaObject>("getWindowManager"),
displayInstance = windowManagerInstance.Call<AndroidJavaObject>("getDefaultDisplay")
) {
displayInstance.Call("getMetrics", metricsInstance);
return metricsInstance.Get<float>("density");
}
}
}
#endif
float _devicePixelRatioOverride;
public bool hardwareAntiAliasing;

float _currentDevicePixelRatio {
get {
#if !UNITY_EDITOR && UNITY_ANDROID_API
return devicePixelRatioOverride;
#endif
var currentDpi = Screen.dpi;
if (currentDpi == 0) {
currentDpi = canvas.GetComponent<CanvasScaler>().fallbackScreenDPI;

正在加载...
取消
保存