163 lines
5.1 KiB
C#
163 lines
5.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using DKManager.AdsSDKManager.Constant;
|
||
using Script.Common;
|
||
using Script.SDKManager.AdsSDKManager.AdmobAdsManager;
|
||
using Script.SDKManager.AdsSDKManager.BigoAdsManager;
|
||
using Script.SDKManager.AdsSDKManager.MaxAdsManager;
|
||
using Script.SDKManager.AdsSDKManager.TpnAdsManager;
|
||
using Script.SDKManager.AdsSDKManager.Utils;
|
||
using SDK.Utils;
|
||
using SDKManager.AdsSDKManager.Constant;
|
||
using UnityEngine;
|
||
|
||
public class AdsSDKManager : NormalSingleton<AdsSDKManager>
|
||
{
|
||
private List<IAdService> _adNetworks = new List<IAdService>();
|
||
/// <summary>
|
||
/// 看完广告的回调
|
||
/// </summary>
|
||
private Action<double> AdRewardCallback;
|
||
|
||
/// <summary>
|
||
/// 广告竞价开关:激励、插屏、全屏Native广告竞价
|
||
/// </summary>
|
||
public bool IsMoreAdsBidding = false;
|
||
|
||
private void InitSDK()
|
||
{
|
||
KwaiAdsManager.Instance.Init();
|
||
AdmobAdsManager.Instance.Initialize();
|
||
BigoAdsManager.Instance.Initialize();
|
||
TpnAdsManager.Instance.Initialize();
|
||
MaxAdsManager.Instance.Initialize();
|
||
_adNetworks.Add(AdmobAdsManager.Instance);
|
||
_adNetworks.Add(BigoAdsManager.Instance);
|
||
_adNetworks.Add(TpnAdsManager.Instance);
|
||
_adNetworks.Add(MaxAdsManager.Instance);
|
||
}
|
||
|
||
public bool IsRewardAdReady()
|
||
{
|
||
return _adNetworks.Any(network => network.IsRewardedAvailable());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 展示激励广告
|
||
/// </summary>
|
||
/// <param name="callback"></param>
|
||
public void ShowRewardAd(string _adPos, Action<bool> _rewardCallback = null, Action _showFailedCallback = null)
|
||
{
|
||
if (!IsRewardAdReady())
|
||
{
|
||
_showFailedCallback?.Invoke();
|
||
return;
|
||
}
|
||
|
||
PlatformType result = GetBestPlatformType(false);
|
||
if (result == PlatformType.Max)
|
||
{
|
||
MaxAdsManager.Instance.DisplayRewarded(_adPos, _rewardCallback, _showFailedCallback);
|
||
}
|
||
else if (result == PlatformType.Admob)
|
||
{
|
||
AdmobAdsManager.Instance.DisplayRewarded(_adPos, _rewardCallback, _showFailedCallback);
|
||
}
|
||
else if (result == PlatformType.Bigo)
|
||
{
|
||
BigoAdsManager.Instance.DisplayRewarded(_adPos, _rewardCallback, _showFailedCallback);
|
||
}
|
||
else if (result == PlatformType.Tpn)
|
||
{
|
||
TpnAdsManager.Instance.DisplayRewarded(_adPos, _rewardCallback, _showFailedCallback);
|
||
}
|
||
else if (result == PlatformType.Kwai)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
_showFailedCallback?.Invoke();
|
||
}
|
||
}
|
||
|
||
public bool IsInterstitialReady()
|
||
{
|
||
return _adNetworks.Any(network => network.IsInterstitialAvailable());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 展示激励广告
|
||
/// </summary>
|
||
/// <param name="callback"></param>
|
||
public void ShowInterstitialAd(string _adPos, IvType _IvType = IvType.IV1, Action _closeCallback = null)
|
||
{
|
||
if (!IsRewardAdReady())
|
||
{
|
||
_closeCallback?.Invoke();
|
||
_closeCallback = null;
|
||
return;
|
||
}
|
||
|
||
PlatformType result = GetBestPlatformType(true);
|
||
if (result == PlatformType.Max)
|
||
{
|
||
MaxAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
||
}
|
||
else if (result == PlatformType.Admob)
|
||
{
|
||
AdmobAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
||
}
|
||
else if (result == PlatformType.Bigo)
|
||
{
|
||
BigoAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
||
}
|
||
else if (result == PlatformType.Tpn)
|
||
{
|
||
TpnAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
||
}
|
||
else if (result == PlatformType.Kwai)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
_closeCallback?.Invoke();
|
||
}
|
||
}
|
||
|
||
private PlatformType GetBestPlatformType(bool isInterstitial)
|
||
{
|
||
if (isInterstitial)
|
||
{
|
||
AdPriceInfo priceInfo = new AdPriceInfo(
|
||
maxPrice: MaxAdsManager.Instance.GetInterstitialRevenue(),
|
||
admobPrice: AdmobAdsManager.Instance.GetInterstitialRevenue(),
|
||
bigoPrice: BigoAdsManager.Instance.GetInterstitialRevenue(),
|
||
toponAdUnitId: TpnAdsManager.Instance.topon_interstitial_units
|
||
);
|
||
return AdsBidResult.GetPlatformType(priceInfo);
|
||
}
|
||
else
|
||
{
|
||
AdPriceInfo priceInfo = new AdPriceInfo(
|
||
maxPrice: MaxAdsManager.Instance.GetRewardedRevenue(),
|
||
admobPrice: AdmobAdsManager.Instance.GetRewardedRevenue(),
|
||
bigoPrice: BigoAdsManager.Instance.GetRewardedRevenue(),
|
||
toponAdUnitId: TpnAdsManager.Instance.topon_rewarded_units
|
||
);
|
||
return AdsBidResult.GetPlatformType(priceInfo);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 广告看完回调
|
||
/// </summary>
|
||
public void OnRewardAdCallback(double price)
|
||
{
|
||
AdRewardCallback?.Invoke(price);
|
||
AdRewardCallback = null;
|
||
}
|
||
}
|