2023-12-26 03:40:48 +00:00
namespace Guru
{
using UnityEngine ;
using System ;
2024-06-20 10:30:22 +00:00
using Guru.Notification ;
2023-12-26 03:40:48 +00:00
public partial class GuruSDK
{
2024-06-20 10:30:22 +00:00
private const float CONSENT_FLOW_TIMEOUT = 10 ; // Consent Flow 超时时间(秒)
2024-03-15 09:00:40 +00:00
private static AdsInitSpec _adInitSpec ;
2023-12-26 03:40:48 +00:00
/// <summary>
/// 启动广告服务
/// </summary>
2024-03-15 09:00:40 +00:00
public static void StartAds ( AdsInitSpec spec = null )
2023-12-26 03:40:48 +00:00
{
2024-03-15 09:00:40 +00:00
_adInitSpec = spec ;
2023-12-26 03:40:48 +00:00
if ( InitConfig . UseCustomConsent )
{
2024-08-07 14:10:22 +00:00
Debug . Log ( $"{Tag} --- Call <color=orange>StartAdsWithCustomConsent</color> when you use custom consent, and pass the result (boolean) to the method." ) ;
2024-03-15 09:00:40 +00:00
return ;
2023-12-26 03:40:48 +00:00
}
2024-03-15 09:00:40 +00:00
// 默认的启动顺序是先启动Consent后, 根据用户回调的结果来启动广告
Instance . StartConsentFlow ( ) ;
2023-12-26 03:40:48 +00:00
}
2024-03-15 09:12:36 +00:00
/// <summary>
/// 是否已经购买了去广告
/// </summary>
/// <param name="buyNoAds"></param>
public static void StartAds ( bool buyNoAds = false )
{
StartAds ( AdsInitSpec . BuildWithNoAds ( ) ) ; // 按照默认的去广告来生成广告启动配置
}
2023-12-26 03:40:48 +00:00
/// <summary>
/// 使用自定义的Consent, 获取用户授权后, 调用此方法
/// </summary>
/// <param name="userAllow"></param>
2024-03-15 09:12:36 +00:00
/// <param name="consentName">Consent 引导的类型, 如果使用了 MAX 的 consent 请填写 max </param>
/// <param name="spec">广告启动配置</param>
public static void StartAdsWithCustomConsent ( bool userAllow = true ,
string consentName = "custom" , AdsInitSpec spec = null )
2023-12-26 03:40:48 +00:00
{
2024-01-30 02:23:49 +00:00
#if UNITY_IOS
2024-03-15 09:12:36 +00:00
_attType = consentName ;
2024-01-30 02:23:49 +00:00
InitAttStatus ( ) ;
# endif
2023-12-26 03:40:48 +00:00
if ( userAllow )
{
2024-01-30 02:23:49 +00:00
#if UNITY_IOS
2024-06-20 10:30:22 +00:00
Instance . CheckAttStatus ( ) ;
2024-01-30 02:23:49 +00:00
# else
2024-03-15 09:00:40 +00:00
StartAdService ( spec ) ;
2024-01-30 02:23:49 +00:00
# endif
2023-12-26 03:40:48 +00:00
}
else
{
2024-08-07 14:10:22 +00:00
Debug . Log ( $"{Tag} --- User refuse to provide ads Id, Ads Service will be cancelled" ) ;
2023-12-26 03:40:48 +00:00
}
}
2024-03-15 09:12:36 +00:00
/// <summary>
/// 使用自定义的Consent, 获取用户授权后, 调用此方法
/// </summary>
/// <param name="userAllow">自定义 Consent 的用户授权结果</param>
/// <param name="consentName">Consent引导名称</param>
/// <param name="buyNoAds">是否已经购买了去广告</param>
public static void StartAdsWithCustomConsent ( bool userAllow = true , string consentName = "custom" ,
bool buyNoAds = false )
{
StartAdsWithCustomConsent ( userAllow , consentName , AdsInitSpec . BuildWithNoAds ( ) ) ;
}
2023-12-26 03:40:48 +00:00
#region Guru Consent
2024-03-01 05:13:26 +00:00
private bool _hasConsentCalled = false ;
2024-03-19 08:19:39 +00:00
private bool _adServiceHasStarted = false ;
2024-06-20 10:30:22 +00:00
private string _notiStatue = "" ;
private bool _hasNotiGranted = false ;
2024-03-01 05:13:26 +00:00
2023-12-26 03:40:48 +00:00
/// <summary>
/// 启动Consent流程
2024-03-01 05:13:26 +00:00
/// 因为之后规划广告流程会放在 Consent 初始化之后, 因此请求广告的时候会需要先请求 Consent
2023-12-26 03:40:48 +00:00
/// </summary>
private void StartConsentFlow ( )
{
2024-06-20 10:30:22 +00:00
LogI ( $"#4.5 --- StartConsentFlow ---" ) ;
2024-03-19 09:33:37 +00:00
float time = 1 ;
if ( ! _adServiceHasStarted & & _appServicesConfig ! = null )
2024-03-19 08:19:39 +00:00
{
2024-06-20 10:30:22 +00:00
time = _appServicesConfig . IsAdsCompliance ( ) ? CONSENT_FLOW_TIMEOUT : 1f ; // 启动合规判定后, 延迟最多 10 秒后启动广告
2024-03-19 08:19:39 +00:00
}
2024-03-19 09:33:37 +00:00
Delay ( time , AdServiceHandler ) ; // 广告延迟启动
2024-03-19 08:19:39 +00:00
2024-03-01 05:13:26 +00:00
if ( _hasConsentCalled ) return ;
_hasConsentCalled = true ;
2024-03-08 11:27:55 +00:00
bool enableCountryCheck = false ;
string dmaMapRule = "" ;
2024-03-19 09:33:37 +00:00
2024-03-08 11:27:55 +00:00
if ( _appServicesConfig ! = null & & _appServicesConfig . parameters ! = null )
{
enableCountryCheck = _appServicesConfig . DMACountryCheck ( ) ;
dmaMapRule = _appServicesConfig . DMAMapRule ( ) ;
}
2024-03-04 04:19:48 +00:00
#if UNITY_IOS
InitAttStatus ( ) ; // Consent 启动前记录 ATT 初始值
# endif
2024-05-07 12:37:57 +00:00
UnityEngine . Debug . Log ( $"{Tag} --- Call:StartConsentFlow ---" ) ;
2024-03-04 04:19:48 +00:00
GuruConsent . StartConsent ( OnGuruConsentOver , dmaMapRule : dmaMapRule , enableCountryCheck : enableCountryCheck ) ;
2023-12-26 03:40:48 +00:00
}
2024-03-04 04:19:48 +00:00
/// <summary>
/// Guru Consent flow is Over
/// </summary>
/// <param name="code"></param>
private void OnGuruConsentOver ( int code )
2023-12-26 03:40:48 +00:00
{
2024-03-15 09:12:36 +00:00
2024-03-04 04:19:48 +00:00
// 无论状态如何, 都在回调内启动广告初始化
2024-03-19 08:19:39 +00:00
AdServiceHandler ( ) ;
2024-03-04 04:19:48 +00:00
// 调用回调
2024-07-31 04:56:01 +00:00
Callbacks . ConsentFlow . InvokeOnConsentResult ( code ) ;
2024-03-04 04:19:48 +00:00
2024-01-30 02:23:49 +00:00
#if UNITY_IOS
2024-03-04 04:19:48 +00:00
CheckAttStatus ( ) ; // [iOS] Consent 启动后检查 ATT 初始值
2024-04-25 12:13:36 +00:00
#elif UNITY_ANDROID
2024-06-20 10:30:22 +00:00
CheckNotiPermission ( ) ; // Consent 回调后检查 Notification 权限
2024-01-30 02:23:49 +00:00
# endif
2024-03-04 04:19:48 +00:00
// 内部处理后继逻辑
2023-12-26 03:40:48 +00:00
switch ( code )
{
case GuruConsent . StatusCode . OBTAINED :
case GuruConsent . StatusCode . NOT_AVAILABLE :
2024-03-01 05:13:26 +00:00
// 已获取授权, 或者地区不可用, ATT 尚未启动
2024-03-04 04:19:48 +00:00
// TODO: 添加后继处理逻辑
2023-12-26 03:40:48 +00:00
break ;
}
}
2024-03-19 08:19:39 +00:00
/// <summary>
/// 启动广告服务
/// </summary>
private void AdServiceHandler ( )
{
if ( _adServiceHasStarted ) return ;
_adServiceHasStarted = true ;
StartAdService ( _adInitSpec ) ;
}
2024-06-20 10:30:22 +00:00
2024-01-30 02:23:49 +00:00
# endregion
#region IOS ATT 广告授权流程
2023-12-26 03:40:48 +00:00
#if UNITY_IOS
2024-01-30 02:23:49 +00:00
private static string _initialAttStatus ;
private static String _attType = "admob" ;
2024-03-04 04:19:48 +00:00
private static bool _autoReCallAtt = false ;
2024-01-30 02:23:49 +00:00
/// <summary>
/// 显示系统的 ATT 弹窗
2023-12-26 03:40:48 +00:00
/// </summary>
2024-06-20 10:30:22 +00:00
public void RequestAttDialog ( )
2023-12-26 03:40:48 +00:00
{
2024-01-30 02:23:49 +00:00
LogI ( $"RequestATTDialog" ) ;
ATTManager . RequestATTDailog ( ReportAttStatus ) ;
2023-12-26 03:40:48 +00:00
}
2024-01-30 02:23:49 +00:00
/// <summary>
/// 初始化 ATT 状态
/// </summary>
public static void InitAttStatus ( )
{
2024-03-04 05:12:31 +00:00
_attType = InitConfig . UseCustomConsent ? ATTManager . GUIDE_TYPE_CUSTOM : ATTManager . GUIDE_TYPE_ADMOB ; // 点位属性确定
2024-01-30 02:23:49 +00:00
_initialAttStatus = ATTManager . GetStatus ( ) ;
2024-08-06 19:28:44 +00:00
SetATTStatus ( _initialAttStatus ) ; // 上报一个初始的状态
2024-01-30 02:23:49 +00:00
}
/// <summary>
/// iOS 平台检查 ATT 状态
/// </summary>
2024-06-20 10:30:22 +00:00
private void CheckAttStatus ( bool autoReCall = false )
2024-03-04 04:19:48 +00:00
{
_autoReCallAtt = autoReCall ;
2024-03-06 04:36:41 +00:00
// Delay 1s to get the user choice
Delay ( 1 , ( ) = > ATTManager . CheckStatus ( ReportAttStatus ) ) ;
2024-03-04 04:19:48 +00:00
}
2024-06-20 10:30:22 +00:00
private void ReportAttStatus ( string status )
2024-01-30 02:23:49 +00:00
{
2024-03-04 04:19:48 +00:00
LogI ( $"{Tag} --- Get Att status:{status} att Type:{_attType} recall:{_autoReCallAtt}" ) ;
2024-08-06 19:28:44 +00:00
SetATTStatus ( _initialAttStatus ) ; // 上报一个初始的状态
// SetUserProperty(Analytics.ParameterATTStatus, status); // 当前的状态
2024-03-06 04:36:41 +00:00
if ( ! string . IsNullOrEmpty ( status )
& & status ! = _initialAttStatus
2024-03-04 04:19:48 +00:00
& & status ! = ATTManager . ATT_STATUS_NOT_DETERMINED )
2024-01-30 02:23:49 +00:00
{
// 上报点位:
2024-08-06 19:28:44 +00:00
SetATTStatus ( _initialAttStatus ) ;
2024-01-30 02:23:49 +00:00
}
2023-12-26 03:40:48 +00:00
2024-01-30 02:23:49 +00:00
switch ( status )
{
case ATTManager . ATT_STATUS_NOT_DETERMINED :
// ATT 状态未知, 请求弹窗
2024-03-04 04:19:48 +00:00
if ( _autoReCallAtt ) RequestAttDialog ( ) ;
2024-01-30 02:23:49 +00:00
break ;
case ATTManager . ATT_STATUS_RESTRICTED :
case ATTManager . ATT_STATUS_DENIED :
2024-02-01 09:53:45 +00:00
// ATT 状态受限, 或者被拒绝
2024-01-30 02:23:49 +00:00
break ;
case ATTManager . ATT_STATUS_AUTHORIZED :
2024-02-01 09:53:45 +00:00
// ATT 状态已授权
2024-01-30 02:23:49 +00:00
break ;
}
2024-06-20 10:30:22 +00:00
CheckNotiPermission ( ) ; // Consent 回调后检查 Notification 权限
2024-01-30 02:23:49 +00:00
}
# endif
2024-04-25 12:13:36 +00:00
# endregion
2024-06-20 10:30:22 +00:00
#region Notification Permission Check
/// <summary>
/// 初始化 Noti Service
/// </summary>
private void InitNotiPermission ( )
{
2024-07-31 04:56:01 +00:00
// bool hasNotiGranted = false;
2024-06-20 10:30:22 +00:00
_notiStatue = "no_determined" ;
NotificationService . Initialize ( ) ; // 初始化 Noti 服务
2024-08-07 14:10:22 +00:00
Analytics . SetNotiPerm ( NotificationService . GetStatus ( ) ) ;
2024-06-20 10:30:22 +00:00
}
/// <summary>
/// 检查 Noti 状态
/// </summary>
private void CheckNotiPermission ( )
2024-04-25 12:13:36 +00:00
{
2024-06-20 10:30:22 +00:00
var status = NotificationService . GetStatus ( ) ;
// 如果未启用自动 Noti 授权,则直接上报状态
if ( ! _initConfig . AutoNotificationPermission )
2024-04-25 12:13:36 +00:00
{
2024-07-31 04:56:01 +00:00
Debug . LogWarning ( $"[SDK] ---- AutoNotificationPermission is OFF, Project should request permission own." ) ;
2024-04-25 12:13:36 +00:00
return ;
}
2024-06-20 10:30:22 +00:00
bool isGranted = NotificationService . IsPermissionGranted ( ) ;
2024-07-31 04:56:01 +00:00
Debug . Log ( $"[SDK] ---- Check Noti Permission: {isGranted}" ) ;
2024-06-20 10:30:22 +00:00
if ( isGranted )
{
2024-07-31 04:56:01 +00:00
Debug . Log ( $"[SDK] ---- Set Notification Permission: {status}" ) ;
2024-08-07 14:10:22 +00:00
Analytics . SetNotiPerm ( status ) ;
2024-06-20 10:30:22 +00:00
return ;
}
RequestNotificationPermission ( ) ; // 请求授权
}
2024-04-25 12:13:36 +00:00
/// <summary>
2024-06-20 10:30:22 +00:00
/// 请求推送授权
2024-04-25 12:13:36 +00:00
/// </summary>
2024-06-20 10:30:22 +00:00
/// <param name="callback"></param>
public static void RequestNotificationPermission ( Action < string > callback = null )
2024-04-25 12:13:36 +00:00
{
2024-07-26 03:53:21 +00:00
FirebaseUtil . StartFetchFcmToken ( ) ;
2024-07-31 04:56:01 +00:00
Debug . Log ( $"[SDK] ---- RequestNotificationPermission" ) ;
2024-06-20 10:30:22 +00:00
NotificationService . RequestPermission ( status = >
2024-04-25 12:13:36 +00:00
{
2024-07-31 04:56:01 +00:00
Debug . Log ( $"[SDK] ---- Set Notification Permission: {status}" ) ;
2024-08-07 14:10:22 +00:00
if ( ! string . IsNullOrEmpty ( status ) ) Analytics . SetNotiPerm ( status ) ;
2024-06-21 08:52:11 +00:00
2024-06-20 10:30:22 +00:00
callback ? . Invoke ( status ) ;
} ) ;
2024-04-25 12:13:36 +00:00
}
2024-06-21 08:52:11 +00:00
/// <summary>
/// 获取 Notification 状态值
/// </summary>
/// <returns></returns>
public static string GetNotificationStatus ( )
{
return NotificationService . GetStatus ( ) ;
}
/// <summary>
/// 用户是否已经获取了 Notification 授权了
/// </summary>
/// <returns></returns>
public static bool IsNotificationPermissionGranted ( )
{
return NotificationService . IsPermissionGranted ( ) ;
}
2024-04-25 12:13:36 +00:00
# endregion
2024-01-30 02:23:49 +00:00
2023-12-26 03:40:48 +00:00
#region Ad Services
private static bool _initAdsCompleted = false ;
2024-05-07 12:37:57 +00:00
public static bool IsAdsReady = > _initAdsCompleted ;
2024-06-05 09:48:01 +00:00
private static int _preBannerAction = 0 ;
2023-12-26 03:40:48 +00:00
2024-03-31 10:08:26 +00:00
public static AdsInitSpec GetDefaultAdsSpec ( )
{
return AdsInitSpec . BuildDefault ( InitConfig . AutoLoadWhenAdsReady , IsDebugMode ) ;
}
2023-12-26 03:40:48 +00:00
/// <summary>
/// 启动广告服务
/// </summary>
2024-08-07 14:10:22 +00:00
private static void StartAdService ( AdsInitSpec spec = null )
2023-12-26 03:40:48 +00:00
{
2024-03-31 10:36:47 +00:00
//---------- Using InitConfig ----------
if ( InitConfig is { IsBuyNoAds : true } ) SetBuyNoAds ( true ) ;
2023-12-26 03:40:48 +00:00
LogI ( $"StartAdService" ) ;
2024-03-15 09:12:36 +00:00
if ( spec = = null )
{
spec = AdsInitSpec . BuildDefault ( InitConfig . AutoLoadWhenAdsReady , IsDebugMode ) ;
if ( ADService . Instance . IsBuyNoAds )
{
spec = AdsInitSpec . BuildWithNoAds ( InitConfig . AutoLoadWhenAdsReady , IsDebugMode ) ;
}
}
2023-12-26 03:40:48 +00:00
2024-03-31 10:36:47 +00:00
if ( InitConfig ! = null & & ! string . IsNullOrEmpty ( InitConfig . BannerBackgroundColor ) )
spec . bannerColorHex = InitConfig . BannerBackgroundColor ;
//--------- Add Callbacks -----------
2024-05-07 12:37:57 +00:00
// BADS
2024-07-31 04:56:01 +00:00
ADService . Instance . OnBannerStartLoad = OnBannerStartLoad ;
ADService . Instance . OnBannerLoaded = OnBannerLoaded ;
2024-05-07 12:37:57 +00:00
// IADS
2024-07-31 04:56:01 +00:00
ADService . Instance . OnInterstitialStartLoad = OnInterstitialStartLoad ;
ADService . Instance . OnInterstitialLoaded = OnInterstitialLoaded ;
ADService . Instance . OnInterstitialFailed = OnInterstitialFailed ;
ADService . Instance . OnInterstitialClosed = OnInterstitialClosed ;
2024-05-07 12:37:57 +00:00
// RADS
2024-07-31 04:56:01 +00:00
ADService . Instance . OnRewardedStartLoad = OnRewardStartLoad ;
ADService . Instance . OnRewardLoaded = OnRewardLoaded ;
ADService . Instance . OnRewardFailed = OnRewardFailed ;
ADService . Instance . OnRewardClosed = OnRewardClosed ;
2024-03-31 10:36:47 +00:00
// ---------- Start Services ----------
ADService . Instance . StartService ( OnAdsInitComplete , spec ) ;
2024-04-17 11:57:11 +00:00
// ---------- Life Cycle ----------
Callbacks . App . OnAppPaused + = OnAppPaused ;
}
/// <summary>
/// 生命周期回调
/// </summary>
/// <param name="paused"></param>
private static void OnAppPaused ( bool paused )
{
if ( ADService . Instance . IsInitialized )
ADService . Instance . OnAppPaused ( paused ) ;
2023-12-26 03:40:48 +00:00
}
2024-05-07 12:37:57 +00:00
private static void OnBannerStartLoad ( string adUnitId )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnBannerADStartLoad ( adUnitId ) ;
2024-01-17 09:51:08 +00:00
private static void OnBannerLoaded ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnBannerADLoaded ( ) ;
2024-05-07 12:37:57 +00:00
private static void OnInterstitialStartLoad ( string adUnitId )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnInterstitialADStartLoad ( adUnitId ) ;
2023-12-26 03:40:48 +00:00
private static void OnInterstitialLoaded ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnInterstitialADLoaded ( ) ;
2023-12-26 03:40:48 +00:00
private static void OnInterstitialFailed ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnInterstitialADFailed ( ) ;
2024-07-02 04:36:15 +00:00
private static void OnInterstitialClosed ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnInterstitialADClosed ( ) ;
2024-07-02 04:36:15 +00:00
private static void OnRewardStartLoad ( string adUnitId )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnRewardedADStartLoad ( adUnitId ) ;
2024-07-02 04:36:15 +00:00
private static void OnRewardLoaded ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnRewardedADLoaded ( ) ;
2024-07-02 04:36:15 +00:00
private static void OnRewardFailed ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnRewardADFailed ( ) ;
2024-07-02 04:36:15 +00:00
private static void OnRewardClosed ( )
2024-07-31 04:56:01 +00:00
= > Callbacks . Ads . InvokeOnRewardADClosed ( ) ;
2023-12-26 03:40:48 +00:00
private static void OnAdsInitComplete ( )
{
_initAdsCompleted = true ;
2024-06-05 09:48:01 +00:00
if ( _adInitSpec ! = null & & _adInitSpec . loadBanner )
{
// 预制动作处理
if ( _preBannerAction = = 1 )
{
_preBannerAction = 0 ;
ShowBanner ( ) ;
}
else if ( _preBannerAction = = - 1 )
{
_preBannerAction = 0 ;
HideBanner ( ) ;
}
}
2024-07-31 04:56:01 +00:00
Callbacks . Ads . InvokeOnAdsInitComplete ( ) ;
2023-12-26 03:40:48 +00:00
}
private static bool CheckAdsReady ( )
{
2024-05-07 12:37:57 +00:00
if ( ! IsAdsReady )
2023-12-26 03:40:48 +00:00
{
2024-06-05 09:48:01 +00:00
LogW ( "[SDK] Ads is not ready. Call <GuruSDk.StartAdService> first." ) ;
2023-12-26 03:40:48 +00:00
return false ;
}
return true ;
}
/// <summary>
/// 显示Banner广告
/// </summary>
/// <param name="placement"></param>
public static void ShowBanner ( string placement = "" )
{
2024-06-05 09:48:01 +00:00
if ( ! CheckAdsReady ( ) )
{
_preBannerAction = 1 ;
return ;
}
2023-12-26 03:40:48 +00:00
ADService . Instance . ShowBanner ( placement ) ;
}
2024-03-31 09:18:43 +00:00
/// <summary>
/// 设置 Banner 背景颜色
/// </summary>
/// <param name="color"></param>
public static void SetBannerBackgroundColor ( Color color )
{
// if (!CheckAdsReady()) return;
ADService . Instance . SetBannerBackgroundColor ( color ) ;
}
2024-04-17 13:44:09 +00:00
public static void SetBannerAutoRefresh ( bool value = true )
{
if ( ! CheckAdsReady ( ) ) return ;
ADService . Instance . SetBannerAutoRefresh ( value ) ;
}
2023-12-26 03:40:48 +00:00
/// <summary>
/// 隐藏Banner广告
/// </summary>
public static void HideBanner ( )
{
2024-06-05 09:48:01 +00:00
if ( ! CheckAdsReady ( ) )
{
_preBannerAction = - 1 ;
return ;
}
2023-12-26 03:40:48 +00:00
ADService . Instance . HideBanner ( ) ;
}
public static void LoadInterstitialAd ( )
{
if ( ! CheckAdsReady ( ) ) return ;
ADService . Instance . RequestInterstitialAD ( ) ;
}
2023-12-28 07:35:35 +00:00
public static bool IsInterstitialAdReady = > ADService . Instance . IsInterstitialADReady ( ) ;
2023-12-26 03:40:48 +00:00
/// <summary>
/// 显示插屏广告
/// </summary>
/// <param name="placement"></param>
/// <param name="onDismissed"></param>
public static void ShowInterstitialAd ( string placement = "" , Action onDismissed = null )
{
if ( ! CheckAdsReady ( ) ) return ;
if ( ! ADService . Instance . IsInterstitialADReady ( ) )
{
LogE ( "Interstitial is not ready. Call <GuruSDk.ShowInterstitialAd> again." ) ;
LoadInterstitialAd ( ) ;
return ;
}
ADService . Instance . ShowInterstitialAD ( placement , onDismissed ) ;
}
public static void LoadRewardAd ( )
{
if ( ! CheckAdsReady ( ) ) return ;
ADService . Instance . RequestRewardedAD ( ) ;
}
2023-12-28 07:35:35 +00:00
public static bool IsRewardAdReady = > ADService . Instance . IsRewardedADReady ( ) ;
2023-12-26 03:40:48 +00:00
/// <summary>
/// 显示激励视频广告
/// </summary>
/// <param name="placement"></param>
/// <param name="onRewarded"></param>
/// <param name="onFailed"></param>
public static void ShowRewardAd ( string placement = "" , Action onRewarded = null , Action < string > onFailed = null )
{
if ( ! CheckAdsReady ( ) ) return ;
if ( ! ADService . Instance . IsRewardedADReady ( ) )
{
LogE ( "RewardAd is not ready. Call <GuruSDk.LoadRewardAd> again." ) ;
LoadRewardAd ( ) ;
return ;
}
ADService . Instance . ShowRewardedAD ( placement , onRewarded , onFailed ) ;
}
# endregion
#region MaxServices
/// <summary>
/// 显示Max调试菜单
/// </summary>
public static void ShowMaxDebugPanel ( )
{
#if UNITY_EDITOR
LogI ( $"Can not show Max Debug Panel in Editor, skipped." ) ;
return ;
# endif
if ( ! ADService . Instance . IsInitialized )
{
LogI ( $"ADService is not initialized, call <GuruSDK.StartAds> first." ) ;
return ;
}
ADService . Instance . ShowMaxDebugPanel ( ) ;
}
# endregion
2024-06-24 02:17:26 +00:00
2023-12-26 03:40:48 +00:00
}
2024-03-15 09:00:40 +00:00
2023-12-26 03:40:48 +00:00
}