浏览代码
Merge pull request #115 from Unity-Technologies/siyaoH/1.17/android
Merge pull request #115 from Unity-Technologies/siyaoH/1.17/android
replace www with UnityWebRequest/siyaoH-1.17-PlatformMessage
GitHub
4 年前
当前提交
4b4b260d
共有 4 个文件被更改,包括 78 次插入 和 22 次删除
-
26com.unity.uiwidgets/Runtime/engine2/AndroidPlatformUtil.cs
-
7com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
-
23com.unity.uiwidgets/Runtime/painting/image_provider.cs
-
44com.unity.uiwidgets/Runtime/engine2/DisplayMetrics.cs
|
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.engine2 { |
|||
public class DisplayMetrics { |
|||
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