c1_unity/Assets/Scripts/Common/SDK/DZSDKManager.cs
2023-08-10 15:57:01 +08:00

116 lines
3.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
// using BF.NativeCore.Platform;
namespace BF
{
//copy from sdk
public enum NotchType
{
NONE,
ANDROID,
}
[System.Serializable]
public class NotchScreenInfo
{
public NotchType notchType = NotchType.NONE;
public bool enabled = false;
public int width = 0;
public int height = 0;
public override string ToString()
{
return string.Format("notchType:{0} showNotch:{1} width:{2} height:{3}", notchType, enabled, width, height);
}
}
public class DZSDKManager : MonoBehaviour
{
#if UNITY_ANDROID
/// <summary>
/// android原生代码对象
/// </summary>
AndroidJavaObject ajc;
#endif
//解析的数据
private NotchScreenInfo notchScreenInfo = new NotchScreenInfo();
private bool initNotchScreen = false;
private void Awake()
{
#if UNITY_ANDROID
//通过该API来实例化导入的arr中对应的类
ajc = new AndroidJavaObject("com.droidhang.aod.AODHelper");
#endif
}
public void CSGetNotchScreenInfo()
{
if (initNotchScreen) return;
BFLog.Log("尝试获取适配信息 CSGetNotchScreenInfo");
#if UNITY_ANDROID
//通过API来调用原生代码的方法
bool success = ajc.Call<bool>("getNotchScreen");
if (success)
{
initNotchScreen = true;
//请求成功
BFLog.Log("获取安卓刘海屏成功");
}
#endif
}
/// <summary>
/// 原生层通过该方法传回信息
/// </summary>
/// <param name="content"></param>
public void GetNotchScreen(string content)
{
#if UNITY_ANDROID
BFLog.Log("获取NotchInfo:" + content);
if (!string.IsNullOrEmpty(content))
{
//解析刘海屏数据
notchScreenInfo = JsonUtility.FromJson<NotchScreenInfo>(content);
BFLog.Log("解析 NotchScreen:" + notchScreenInfo.ToString());
}
#endif
}
/// <summary>
/// 对外接口 获取刘海屏信息
/// </summary>
/// <returns></returns>
public NotchScreenInfo GetNotchScreenInfo()
{
return notchScreenInfo;
}
// 刘海屏信息 ***************************************************************************************************
public NotchType GetNotchScreenType()
{
return notchScreenInfo.notchType;
}
public bool GetNotchScreenEnable()
{
return notchScreenInfo.enabled;
}
public int GetNotchScreenWidth()
{
return notchScreenInfo.width;
}
public int GetNotchScreenHeight()
{
return notchScreenInfo.height;
}
}
}