You've already forked Commercialization.topon
release: 1.4.7
This commit is contained in:
@@ -7,12 +7,15 @@ using UnityEngine;
|
||||
public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
{
|
||||
private ATRewardedVideo _atRewardedVideo;
|
||||
private ATRewardedAutoVideo _atRewardedAutoVideo;
|
||||
private Action<bool> _onVideoComplete;
|
||||
private ADListenerAggregator _aggregator;
|
||||
private bool _autoLoadRegistered;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
this._atRewardedVideo = ATRewardedVideo.Instance;
|
||||
this._atRewardedAutoVideo = ATRewardedAutoVideo.Instance;
|
||||
// this._atRewardedVideo.client.setListener(this); //由于新版本广告sdk弃用该方式,通过以下方式重新桥接监听事件
|
||||
this._aggregator = new ADListenerAggregator();
|
||||
this._aggregator.BindAwardVideoListener(this._atRewardedVideo.client , this);
|
||||
@@ -30,7 +33,15 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
this.adListener.onClose = onClose;
|
||||
this.adListener.onVideoComplete = this.OnVideoComplete;
|
||||
var json = new Dictionary<string, string> { { AnyThinkAds.Api.ATConst.SCENARIO, this.AdScene } };
|
||||
this._atRewardedVideo.showAd(this.Key , json);
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo.showAutoAd(this.Key, json);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._atRewardedVideo.showAd(this.Key , json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,18 +53,54 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
|
||||
public override bool IsReadly()
|
||||
{
|
||||
return this.curState == 2;
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
if (this._atRewardedAutoVideo != null &&
|
||||
this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.curState == 2;
|
||||
}
|
||||
|
||||
if (this.curState == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void LoadAD()
|
||||
{
|
||||
if (curState == 0)
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo.setAutoLocalExtra(this.Key, BuildRewardedExtra());
|
||||
this.curState = this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
Dictionary<string,string> jsonmap = new Dictionary<string,string>();
|
||||
//ATConst.USERID_KEY必传,用于标识每个用户;ATConst.USER_EXTRA_DATA为可选参数,传入后将透传到开发者的服务器
|
||||
jsonmap.Add(ATConst.USERID_KEY, ADManager.Instance.UserId);
|
||||
jsonmap.Add(ATConst.USER_EXTRA_DATA, "user_extra_data");
|
||||
jsonmap = BuildRewardedExtra();
|
||||
curState = 1;
|
||||
this._atRewardedVideo.loadVideoAd(this.Key, jsonmap);
|
||||
}
|
||||
@@ -130,5 +177,63 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo?.setAutoLocalExtra(this.Key, BuildRewardedExtra());
|
||||
}
|
||||
}
|
||||
|
||||
public override int MaxLoadAttempts => ToponAdController.CurrentOptions?.RewardedMaxLoadAttempts ?? base.MaxLoadAttempts;
|
||||
|
||||
public override float LoadRetryDelaySeconds =>
|
||||
Math.Max(0f, (ToponAdController.CurrentOptions?.RewardedLoadRetryDelayMs ?? 750) / 1000f);
|
||||
|
||||
public override bool AutoPreloadOnInit => ToponAdController.CurrentOptions?.RewardedPrewarmOnInit ?? true;
|
||||
|
||||
private bool UseAutoLoad()
|
||||
{
|
||||
return ToponAdController.CurrentOptions?.RewardedAutoLoad ?? true;
|
||||
}
|
||||
|
||||
private void EnsureAutoLoadRegistered()
|
||||
{
|
||||
if (_autoLoadRegistered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._atRewardedAutoVideo?.addAutoLoadAdPlacementID(new[] { this.Key });
|
||||
_autoLoadRegistered = true;
|
||||
}
|
||||
|
||||
private Dictionary<string, string> BuildRewardedExtra()
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ ATConst.USERID_KEY, ADManager.Instance.UserId },
|
||||
{ ATConst.USER_EXTRA_DATA, "user_extra_data" }
|
||||
};
|
||||
}
|
||||
|
||||
public override void EnterAdScenario(string scenario)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(scenario) || string.Equals(scenario, "__default__", StringComparison.Ordinal))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
|
||||
return;
|
||||
}
|
||||
|
||||
this._atRewardedVideo?.entryScenarioWithPlacementID(this.Key, scenario);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user