From 7c3699c11dc62b11b9ab2bbd5825615816e9e662 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Thu, 10 Aug 2023 15:57:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=98=E6=B5=B7=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Common/SDK/DZSDKManager.cs | 116 ++++++++++++++++++ .../Scripts/Common/SDK/DZSDKManager.cs.meta | 11 ++ Assets/Scripts/Common/SDK/SDKManager.cs | 27 ++++ 3 files changed, 154 insertions(+) create mode 100644 Assets/Scripts/Common/SDK/DZSDKManager.cs create mode 100644 Assets/Scripts/Common/SDK/DZSDKManager.cs.meta diff --git a/Assets/Scripts/Common/SDK/DZSDKManager.cs b/Assets/Scripts/Common/SDK/DZSDKManager.cs new file mode 100644 index 000000000..969ea6856 --- /dev/null +++ b/Assets/Scripts/Common/SDK/DZSDKManager.cs @@ -0,0 +1,116 @@ +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 + /// + /// android原生代码对象 + /// + 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("getNotchScreen"); + if (success) + { + initNotchScreen = true; + //请求成功 + BFLog.Log("获取安卓刘海屏成功"); + } +#endif + } + + /// + /// 原生层通过该方法传回信息 + /// + /// + public void GetNotchScreen(string content) + { +#if UNITY_ANDROID + BFLog.Log("获取NotchInfo:" + content); + + if (!string.IsNullOrEmpty(content)) + { + //解析刘海屏数据 + notchScreenInfo = JsonUtility.FromJson(content); + + BFLog.Log("解析 NotchScreen:" + notchScreenInfo.ToString()); + } +#endif + } + + /// + /// 对外接口 获取刘海屏信息 + /// + /// + 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; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/SDK/DZSDKManager.cs.meta b/Assets/Scripts/Common/SDK/DZSDKManager.cs.meta new file mode 100644 index 000000000..bcf899ee4 --- /dev/null +++ b/Assets/Scripts/Common/SDK/DZSDKManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ced1766fcb78b314db1ae240a0e27a9f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Common/SDK/SDKManager.cs b/Assets/Scripts/Common/SDK/SDKManager.cs index 42ce08d4b..9befe8411 100644 --- a/Assets/Scripts/Common/SDK/SDKManager.cs +++ b/Assets/Scripts/Common/SDK/SDKManager.cs @@ -65,6 +65,8 @@ namespace BF public BFIronSourceSDKManager BFIronSourceSDKMgr { get; private set; } public BFNativeSDKManager BFNativeSDKMgr { get; private set; } public BFThirdReportSDKManager BFThirdReportSDKMgr { get; private set; } + //刘海屏 + public DZSDKManager DZSDKMgr { get; private set; } static SDKManager instance; public static SDKManager Create() @@ -85,6 +87,9 @@ namespace BF { sdkGo = new GameObject("SDKManager"); } + + // 刘海屏数据 + DZSDKMgr = sdkGo.AddComponent(); // 登陆 BFLoginSDKMgr = sdkGo.AddComponent(); // 支付 @@ -122,5 +127,27 @@ namespace BF { return NativeUtils.GetTimeZone(); } + + // 刘海屏信息 *************************************************************************************************** + + public NotchType GetNotchScreenType() + { + return DZSDKMgr.GetNotchScreenType(); + } + + public bool GetNotchScreenEnable() + { + return DZSDKMgr.GetNotchScreenEnable(); + } + + public int GetNotchScreenWidth() + { + return DZSDKMgr.GetNotchScreenWidth(); + } + + public int GetNotchScreenHeight() + { + return DZSDKMgr.GetNotchScreenHeight(); + } } } \ No newline at end of file