siyao
4 年前
当前提交
b20deaaa
共有 3 个文件被更改,包括 47 次插入 和 35 次删除
-
2com.unity.uiwidgets/Runtime/engine2/AndroidPlatformUtil.cs
-
36com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
-
44com.unity.uiwidgets/Runtime/engine2/DisplayMatrix.cs
|
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.engine2 { |
|||
public class DisplayMatrix { |
|||
float _devicePixelRatioByDefault; |
|||
|
|||
public float DevicePixelRatioByDefault { |
|||
get { |
|||
if (_devicePixelRatioByDefault > 0) { |
|||
return _devicePixelRatioByDefault; |
|||
} |
|||
|
|||
#if UNITY_ANDROID
|
|||
_devicePixelRatioByDefault = AndroidDevicePixelRatio(); |
|||
#endif
|
|||
|
|||
if (_devicePixelRatioByDefault <= 0) { |
|||
_devicePixelRatioByDefault = 1; |
|||
} |
|||
|
|||
return _devicePixelRatioByDefault; |
|||
} |
|||
} |
|||
|
|||
#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
|
|||
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue