220 lines
6.1 KiB
C#
220 lines
6.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BigoAds.Scripts.Api;
|
|
using Script.Common;
|
|
using Script.Utils;
|
|
using SDK.Utils;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace Script.SDKManager.AdsSDKManager.BigoAdsManager
|
|
{
|
|
public class BigoAdsManager : NormalSingleton<BigoAdsManager>, IAdService
|
|
{
|
|
public string ClientName => "BigoAds";
|
|
private BigoRewardedAdManager _rewardedAdManager;
|
|
private BigoInterstitialAdManager _interstitialAdManager;
|
|
private List<string> _interstitialAdUnits;
|
|
private List<string> _rewardedAdUnits;
|
|
public string bigo_app_id;
|
|
|
|
public void Initialize()
|
|
{
|
|
if (string.IsNullOrEmpty(bigo_app_id)) return;
|
|
_rewardedAdUnits = GetRewardedAdUnitsFromServer();
|
|
_interstitialAdUnits = GetInterstitialAdUnitsFromServer();
|
|
BigoAdSdk.OnInitFinish += () =>
|
|
{
|
|
LoggerUtils.Debug($" bigo sdk init success");
|
|
_rewardedAdManager = new BigoRewardedAdManager();
|
|
_rewardedAdManager.InitializeAdUnits(
|
|
_rewardedAdUnits,
|
|
onAdLoaded: OnRewardedAdLoaded,
|
|
onAdLoadFailed: OnRewardedAdLoadFailed,
|
|
onAdShowed: OnRewardedAdShowed,
|
|
onAdDismissed: OnRewardedAdDismissed,
|
|
onAdError: OnRewardedAdError,
|
|
onAdClicked: OnRewardedAdClicked
|
|
);
|
|
_interstitialAdManager = new BigoInterstitialAdManager();
|
|
_interstitialAdManager.InitializeAdUnits(
|
|
_interstitialAdUnits,
|
|
onAdLoaded: OnInterstitialAdLoaded,
|
|
onAdLoadFailed: OnInterstitialAdLoadFailed,
|
|
onAdShowed: OnInterstitialAdShowed,
|
|
onAdDismissed: OnInterstitialAdDismissed,
|
|
onAdError: OnInterstitialAdError,
|
|
onAdClicked: OnInterstitialAdClicked
|
|
);
|
|
};
|
|
// todo
|
|
var config = new BigoAdConfig.Builder()
|
|
.SetAppId(bigo_app_id)
|
|
.SetDebugLog(false)
|
|
.Build();
|
|
BigoAdSdk.Initialize(config);
|
|
}
|
|
|
|
#region Rewarded
|
|
// 各个回调处理方法
|
|
private void OnRewardedAdLoaded(string adUnitId)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnRewardedAdLoadFailed(string adUnitId, int code, string msg)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnRewardedAdShowed(string adUnitId)
|
|
{
|
|
|
|
}
|
|
private void OnRewardedAdDismissed(string adUnitId)
|
|
{
|
|
_rewardedAdManager.Destroy();
|
|
LoadRewarded();
|
|
}
|
|
|
|
private void OnRewardedAdError(string adUnitId, int code, string msg)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnRewardedAdClicked()
|
|
{
|
|
|
|
}
|
|
|
|
public void LoadRewarded()
|
|
{
|
|
|
|
foreach (var adUnitId in _rewardedAdUnits)
|
|
{
|
|
_rewardedAdManager.LoadAd(adUnitId);
|
|
}
|
|
}
|
|
|
|
public bool IsRewardedAvailable()
|
|
{
|
|
return _rewardedAdManager.GetAvailableAdUnits().Count > 0;
|
|
}
|
|
|
|
public void DisplayRewarded()
|
|
{
|
|
_rewardedAdManager.ShowHighestPayingAd();
|
|
}
|
|
|
|
public double GetRewardedRevenue()
|
|
{
|
|
return _rewardedAdManager.GetHighestPayingAdRevenue();
|
|
}
|
|
|
|
// 从服务器获取广告位配置
|
|
private List<string> GetRewardedAdUnitsFromServer()
|
|
{
|
|
// todo
|
|
return new List<string> { "bigo_reward_unit_1", "bigo_reward_unit_2", "bigo_reward_unit_3" };
|
|
}
|
|
|
|
#region Interstitial
|
|
private void OnInterstitialAdLoaded(string adUnitId)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnInterstitialAdLoadFailed(string adUnitId, int code, string msg)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnInterstitialAdShowed(string adUnitId)
|
|
{
|
|
|
|
}
|
|
private void OnInterstitialAdDismissed(string adUnitId)
|
|
{
|
|
_interstitialAdManager.Destroy();
|
|
LoadInterstitial();
|
|
}
|
|
|
|
private void OnInterstitialAdError(string adUnitId, int code, string msg)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnInterstitialAdClicked()
|
|
{
|
|
|
|
}
|
|
|
|
public void LoadInterstitial()
|
|
{
|
|
foreach (var adUnitId in _interstitialAdUnits)
|
|
{
|
|
_interstitialAdManager.LoadAd(adUnitId);
|
|
}
|
|
}
|
|
|
|
public bool IsInterstitialAvailable()
|
|
{
|
|
// 检查是否有任意一个广告位可用
|
|
return _interstitialAdManager.GetAvailableAdUnits().Count > 0;
|
|
}
|
|
|
|
public void DisplayInterstitial()
|
|
{
|
|
_interstitialAdManager.ShowHighestPayingAd();
|
|
}
|
|
|
|
public double GetInterstitialRevenue()
|
|
{
|
|
return _interstitialAdManager.GetHighestPayingAdRevenue();
|
|
}
|
|
|
|
// 从服务器获取广告位配置
|
|
private List<string> GetInterstitialAdUnitsFromServer()
|
|
{
|
|
// 实现从服务器获取广告位ID列表的逻辑
|
|
// todo
|
|
return new List<string> { "bigo_interstitial_unit_1", "bigo_interstitial_unit_2", "bigo_interstitial_unit_3" };
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 开屏广告
|
|
|
|
public void LoadSplash() { }
|
|
public bool IsSplashAvailable() { return false; }
|
|
public void DisplaySplash() { }
|
|
public double GetSplashRevenue() { return 0; }
|
|
|
|
#endregion
|
|
|
|
#region 原生广告功能
|
|
public void LoadNative() { }
|
|
public bool IsNativeAvailable() { return false; }
|
|
public void DisplayNative(NativeAdPosition position) { }
|
|
public void RemoveNative() { }
|
|
public double GetNativeRevenue() { return 0; }
|
|
|
|
#endregion
|
|
|
|
#region 横幅广告功能
|
|
public void LoadBanner() { }
|
|
public bool IsBannerAvailable() { return false; }
|
|
public void DisplayBanner() { }
|
|
public void HideBanner() { }
|
|
public double GetBannerRevenue() { return 0; }
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|