修复bigo广告源提前关闭广告后获取奖励问题

This commit is contained in:
juncong lee 2025-09-03 21:37:02 +08:00
parent 33837645b5
commit 1a5d0ac88c
2 changed files with 26 additions and 9 deletions

View File

@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using BigoAds.Scripts.Api;
using NUnit.Framework.Constraints;
using UnityEngine;
@ -25,18 +26,19 @@ namespace WZ
private float _rvStartLoadTime = 0;
private float _ivStartLoadTime = 0;
private bool _receivedReward = false;
public void Initialize()
{
LoggerUtils.Debug("[Bigo] sdk init start"+_bigo_app_id+" rvid:"+_rewardedAdUnits+" ivid:"+_interstitialAdUnits);
if (string.IsNullOrEmpty(_bigo_app_id)|| _initialized) return;
LoggerUtils.Debug("[Bigo] sdk init start" + _bigo_app_id + " rvid:" + _rewardedAdUnits + " ivid:" + _interstitialAdUnits);
if (string.IsNullOrEmpty(_bigo_app_id) || _initialized) return;
BigoAdSdk.OnInitFinish += () =>
{
LoggerUtils.Debug($"[Bigo] sdk init success");
_initialized = true;
LoadRewarded();
LoadInterstitial();
};
var config = new BigoAdConfig.Builder()
@ -72,12 +74,18 @@ namespace WZ
private void OnRewardedAdDismissed(string adUnitId,double revenue)
{
AdsActionEvents.TrackAdClosed(Platfrom,ClientName, adUnitId, AdsType.Rewarded, _rvPos, revenue);
_rvCloseCallback?.Invoke(true,revenue);
_rvCloseCallback?.Invoke(_receivedReward,revenue);
_rvCloseCallback = null;
_receivedReward = false;
LoadRewarded();
}
private void OnRewardEarnReward(bool reward)
{
_receivedReward = true;
}
private void OnRewardedAdError(string adUnitId, int code, string msg)
{
AdsActionEvents.TrackAdFailToShow(Platfrom, AdsType.Rewarded, msg, _rvPos);
@ -104,7 +112,8 @@ namespace WZ
onAdShowed: OnRewardedAdShowed,
onAdDismissed: OnRewardedAdDismissed,
onAdError: OnRewardedAdError,
onAdClicked: OnRewardedAdClicked
onAdClicked: OnRewardedAdClicked,
onEarnRewarded: OnRewardEarnReward
);
_rvStartLoadTime = Time.realtimeSinceStartup;
// todo 暂时支持一个广告位,后续支持多个广告位

View File

@ -19,11 +19,12 @@ namespace WZ
Action<string> onAdShowed = null,
Action<string,double> onAdDismissed = null,
Action<string, int, string> onAdError = null,
Action<string,double> onAdClicked = null)
Action<string,double> onAdClicked = null,
Action<bool> onEarnRewarded = null)
{
foreach (var adUnitId in adUnitIds)
{
CreateRewardedAd(adUnitId, onAdLoaded, onAdLoadFailed, onAdShowed, onAdDismissed, onAdError, onAdClicked);
CreateRewardedAd(adUnitId, onAdLoaded, onAdLoadFailed, onAdShowed, onAdDismissed, onAdError, onAdClicked, onEarnRewarded);
}
}
@ -32,7 +33,8 @@ namespace WZ
Action<string> onAdShowed,
Action<string, double> onAdDismissed,
Action<string, int, string> onAdError,
Action<string,double> onAdClicked)
Action<string,double> onAdClicked,
Action<bool> onEarnRewarded = null)
{
if (_rewardedAds.ContainsKey(adUnitId))
{
@ -53,7 +55,13 @@ namespace WZ
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded);
onAdLoaded?.Invoke(adUnitId);
};
rewardedAd.OnUserEarnedReward += () =>
{
LoggerUtils.Debug("[Bigo] Rewarded-[interaction]: {adUnitId} earn reward");
onEarnRewarded?.Invoke(true);
};
rewardedAd.OnLoadFailed += ((code, msg) =>
{
_retryCounters[adUnitId]++;