update: 添加广告启动初始化配置对象

deeplink
胡宇飞 2024-03-15 17:00:40 +08:00
parent 1f71522fa6
commit 4fadb2b469
3 changed files with 31 additions and 14 deletions

View File

@ -9,20 +9,22 @@ namespace Guru
public partial class GuruSDK public partial class GuruSDK
{ {
private static AdsInitSpec _adInitSpec;
/// <summary> /// <summary>
/// 启动广告服务 /// 启动广告服务
/// </summary> /// </summary>
public static void StartAds() public static void StartAds(AdsInitSpec spec = null)
{ {
_adInitSpec = spec;
if (InitConfig.UseCustomConsent) if (InitConfig.UseCustomConsent)
{ {
Debug.Log($"{Tag} --- Call <color=orange>StartAdsWithCustomConsent</color> when you use custom consent, and pass the result (boolean) to the method."); Debug.Log($"{Tag} --- Call <color=orange>StartAdsWithCustomConsent</color> when you use custom consent, and pass the result (boolean) to the method.");
return;
} }
else
{ // 默认的启动顺序是先启动Consent后, 根据用户回调的结果来启动广告
// 默认的启动顺序是先启动Consent后, 根据用户回调的结果来启动广告 Instance.StartConsentFlow();
Instance.StartConsentFlow();
}
} }
/// <summary> /// <summary>
@ -30,7 +32,7 @@ namespace Guru
/// </summary> /// </summary>
/// <param name="userAllow"></param> /// <param name="userAllow"></param>
/// <param name="guideType">Consent 引导的类型, 如果使用了 MAX 的 consent 请填写 max </param> /// <param name="guideType">Consent 引导的类型, 如果使用了 MAX 的 consent 请填写 max </param>
public static void StartAdsWithCustomConsent(bool userAllow = true, string guideType = "custom") public static void StartAdsWithCustomConsent(bool userAllow = true, string guideType = "custom", AdsInitSpec spec = null)
{ {
#if UNITY_IOS #if UNITY_IOS
_attType = guideType; _attType = guideType;
@ -41,7 +43,7 @@ namespace Guru
#if UNITY_IOS #if UNITY_IOS
CheckAttStatus(); CheckAttStatus();
#else #else
StartAdService(); StartAdService(spec);
#endif #endif
} }
else else
@ -87,7 +89,7 @@ namespace Guru
private void OnGuruConsentOver(int code) private void OnGuruConsentOver(int code)
{ {
// 无论状态如何, 都在回调内启动广告初始化 // 无论状态如何, 都在回调内启动广告初始化
StartAdService(); StartAdService(_adInitSpec);
// 调用回调 // 调用回调
Callbacks.ConsentFlow._onConsentResult?.Invoke(code); Callbacks.ConsentFlow._onConsentResult?.Invoke(code);
@ -187,11 +189,11 @@ namespace Guru
/// <summary> /// <summary>
/// 启动广告服务 /// 启动广告服务
/// </summary> /// </summary>
public static void StartAdService() internal static void StartAdService(AdsInitSpec spec = null)
{ {
LogI($"StartAdService"); LogI($"StartAdService");
ADService.Instance.StartService(OnAdsInitComplete, if(spec == null) spec = AdsInitSpec.BuildDefault(InitConfig.AutoLoadWhenAdsReady, IsDebugMode);
InitConfig.AutoLoadWhenAdsReady, IsDebugMode); ADService.Instance.StartService(OnAdsInitComplete, spec);
//--------- Callbacks ----------- //--------- Callbacks -----------
ADService.OnBannerLoaded = OnBannerLoaded; ADService.OnBannerLoaded = OnBannerLoaded;
@ -203,7 +205,6 @@ namespace Guru
private static void OnBannerLoaded() private static void OnBannerLoaded()
=> Callbacks.Ads._onBannerADLoaded?.Invoke(); => Callbacks.Ads._onBannerADLoaded?.Invoke();
private static void OnInterstitialLoaded() private static void OnInterstitialLoaded()
=> Callbacks.Ads._onInterstitialADLoaded?.Invoke(); => Callbacks.Ads._onInterstitialADLoaded?.Invoke();
private static void OnInterstitialFailed() private static void OnInterstitialFailed()
@ -323,4 +324,8 @@ namespace Guru
#endregion #endregion
} }
} }

View File

@ -167,6 +167,15 @@ namespace Guru
add => _onFirebaseReady += value; add => _onFirebaseReady += value;
remove => _onFirebaseReady -= value; remove => _onFirebaseReady -= value;
} }
internal static Action _onGuruServiceReady;
public static event Action OnGuruServiceReady
{
add => _onGuruServiceReady += value;
remove => _onGuruServiceReady -= value;
}
} }
} }

View File

@ -332,6 +332,9 @@ namespace Guru
Debug.LogError($"--- ERROR on StartConsentFlow: {ex.Message}"); Debug.LogError($"--- ERROR on StartConsentFlow: {ex.Message}");
}); });
} }
// 中台服务初始化结束
Callbacks.SDK._onGuruServiceReady?.Invoke();
} }
/// <summary> /// <summary>