miduo_client/Assets/LuaFramework/Scripts/Global/NotchScreenUtil.cs

62 lines
1.3 KiB
C#

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System;
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;
}
}
private NotchScreenUtil()
{
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);
}
}
}
public void Init()
{
Debug.Log("设备信息初始化");
}
// 获取刘海屏高度
public int GetNotchHeight()
{
int height = 0;
try
{
height = jo.CallStatic<int>("getNotchHeight");
}
catch (Exception e)
{
Debug.LogError(e);
}
return height;
}
}