2020-06-30 18:59:44 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using System.Collections.Generic;
|
2020-08-22 15:31:14 +08:00
|
|
|
|
using System.Runtime.InteropServices;
|
2020-06-30 18:59:44 +08:00
|
|
|
|
using System;
|
2021-04-19 19:36:43 +08:00
|
|
|
|
using Beebyte.Obfuscator;
|
2020-06-30 18:59:44 +08:00
|
|
|
|
|
2021-04-19 19:36:43 +08:00
|
|
|
|
[Skip]
|
2020-06-30 18:59:44 +08:00
|
|
|
|
public class NotchScreenUtil
|
|
|
|
|
{
|
|
|
|
|
private AndroidJavaObject jo;
|
|
|
|
|
private AndroidJavaObject context;
|
|
|
|
|
|
|
|
|
|
private static NotchScreenUtil _instance;
|
|
|
|
|
|
|
|
|
|
public static NotchScreenUtil Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_instance == null)
|
|
|
|
|
{
|
|
|
|
|
_instance = new NotchScreenUtil();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-22 15:31:14 +08:00
|
|
|
|
#if UNITY_IOS
|
|
|
|
|
//初始化
|
|
|
|
|
[DllImport("__Internal")]
|
|
|
|
|
private static extern string m_GetNotchHeight();
|
2021-04-19 10:09:32 +08:00
|
|
|
|
[DllImport("__Internal")]
|
|
|
|
|
private static extern string m_GetNotchBottomHeight();
|
2020-08-22 15:31:14 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2020-06-30 18:59:44 +08:00
|
|
|
|
private NotchScreenUtil()
|
|
|
|
|
{
|
2020-08-15 10:13:32 +08:00
|
|
|
|
#if UNITY_IOS
|
|
|
|
|
|
|
|
|
|
#elif UNITY_ANDROID
|
2020-06-30 18:59:44 +08:00
|
|
|
|
using (var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
|
|
|
|
{
|
|
|
|
|
context = up.GetStatic<AndroidJavaObject>("currentActivity");
|
|
|
|
|
using (var adi = new AndroidJavaClass("com.bluewhale.androidutils.NotchScreenUtil"))
|
|
|
|
|
{
|
|
|
|
|
jo = adi.CallStatic<AndroidJavaObject>("instance");
|
|
|
|
|
jo.Call("Init", context);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-15 10:13:32 +08:00
|
|
|
|
#endif
|
2020-06-30 18:59:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2021-07-09 11:56:53 +08:00
|
|
|
|
XDebug.Log.l("设备信息初始化");
|
2020-06-30 18:59:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-22 15:31:14 +08:00
|
|
|
|
|
2020-06-30 18:59:44 +08:00
|
|
|
|
// 获取刘海屏高度
|
|
|
|
|
public int GetNotchHeight()
|
|
|
|
|
{
|
2020-09-05 15:21:41 +08:00
|
|
|
|
int height = -1;
|
2020-08-15 10:13:32 +08:00
|
|
|
|
|
2020-06-30 18:59:44 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-08-15 10:13:32 +08:00
|
|
|
|
#if UNITY_IOS
|
2020-08-27 20:18:36 +08:00
|
|
|
|
height = (int)Mathf.Floor(Convert.ToSingle(m_GetNotchHeight()));
|
2020-08-15 10:13:32 +08:00
|
|
|
|
#elif UNITY_ANDROID
|
2020-06-30 18:59:44 +08:00
|
|
|
|
height = jo.CallStatic<int>("getNotchHeight");
|
2020-08-15 10:13:32 +08:00
|
|
|
|
#endif
|
2020-06-30 18:59:44 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError(e);
|
|
|
|
|
}
|
2020-08-15 10:13:32 +08:00
|
|
|
|
return height;
|
2020-06-30 18:59:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 15:21:41 +08:00
|
|
|
|
// 获取刘海屏高度
|
|
|
|
|
public int GetNotchBottomHeight()
|
|
|
|
|
{
|
|
|
|
|
int height = -1;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_IOS
|
|
|
|
|
height = (int)Mathf.Floor(Convert.ToSingle(m_GetNotchBottomHeight()));
|
|
|
|
|
#elif UNITY_ANDROID
|
|
|
|
|
height = jo.CallStatic<int>("getNotchBottomHeight");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError(e);
|
|
|
|
|
}
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 18:59:44 +08:00
|
|
|
|
|
|
|
|
|
}
|