刘海屏
This commit is contained in:
parent
4409c91b2b
commit
7c3699c11d
116
Assets/Scripts/Common/SDK/DZSDKManager.cs
Normal file
116
Assets/Scripts/Common/SDK/DZSDKManager.cs
Normal file
@ -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
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Common/SDK/DZSDKManager.cs.meta
Normal file
11
Assets/Scripts/Common/SDK/DZSDKManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ced1766fcb78b314db1ae240a0e27a9f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -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<DZSDKManager>();
|
||||
// 登陆
|
||||
BFLoginSDKMgr = sdkGo.AddComponent<BFLoginSDKManager>();
|
||||
// 支付
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user