You've already forked Commercialization.topon
release: 1.4.8
This commit is contained in:
@@ -1,78 +1,76 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AnyThinkAds.Api;
|
||||
using AnyThinkAds.Common;
|
||||
using AnyThinkAds.ThirdParty.LitJson;
|
||||
using Runtime.ADAggregator;
|
||||
using UnityEngine;
|
||||
|
||||
public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
public class AwardVideoPlayer : ADPlayer, ATRewardedVideoListener
|
||||
{
|
||||
private ATRewardedVideo _atRewardedVideo;
|
||||
private ATRewardedAutoVideo _atRewardedAutoVideo;
|
||||
private Action<bool> _onVideoComplete;
|
||||
private IATRewardedVideoAdClient _client;
|
||||
private Action<bool> _onVideoComplete;
|
||||
private ADListenerAggregator _aggregator;
|
||||
private bool _autoLoadRegistered;
|
||||
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);
|
||||
// var adClient = this._atRewardedVideo.client;
|
||||
// adClient.on
|
||||
_client = AnyThinkAds.ATAdsClientFactory.BuildRewardedVideoAdClient();
|
||||
_aggregator = new ADListenerAggregator();
|
||||
_aggregator.BindAwardVideoListener(_client, this);
|
||||
}
|
||||
|
||||
|
||||
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
|
||||
{
|
||||
if (this.IsReadly())
|
||||
if (!IsReadly())
|
||||
{
|
||||
this.curState = 0;
|
||||
this._onVideoComplete = onVideoComplete;
|
||||
this.adListener.onClose = onClose;
|
||||
this.adListener.onVideoComplete = this.OnVideoComplete;
|
||||
var json = new Dictionary<string, string> { { AnyThinkAds.Api.ATConst.SCENARIO, this.AdScene } };
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo.showAutoAd(this.Key, json);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._atRewardedVideo.showAd(this.Key , json);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
curState = 0;
|
||||
_onVideoComplete = onVideoComplete;
|
||||
adListener.onClose = onClose;
|
||||
adListener.onVideoComplete = OnVideoComplete;
|
||||
var json = new Dictionary<string, string> { { ATConst.SCENARIO, AdScene } };
|
||||
var mapJson = JsonMapper.ToJson(json);
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.showAutoAd(Key, mapJson);
|
||||
return;
|
||||
}
|
||||
|
||||
_client.showAd(Key, mapJson);
|
||||
}
|
||||
|
||||
|
||||
private void OnVideoComplete(bool obj)
|
||||
{
|
||||
this._onVideoComplete?.Invoke(obj);
|
||||
this._onVideoComplete = null;
|
||||
_onVideoComplete?.Invoke(obj);
|
||||
_onVideoComplete = null;
|
||||
}
|
||||
|
||||
public override bool IsReadly()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
if (this._atRewardedAutoVideo != null &&
|
||||
this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key))
|
||||
if (_client != null && _client.autoLoadRewardedVideoReadyForPlacementID(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.curState == 2;
|
||||
return curState == 2;
|
||||
}
|
||||
|
||||
if (this.curState == 2)
|
||||
if (curState == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
|
||||
if (_client != null && _client.hasAdReady(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,74 +79,75 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
|
||||
public override void LoadAD()
|
||||
{
|
||||
if (curState == 0)
|
||||
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 = BuildRewardedExtra();
|
||||
curState = 1;
|
||||
this._atRewardedVideo.loadVideoAd(this.Key, jsonmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#region SDK
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildRewardedExtra()));
|
||||
curState = _client.autoLoadRewardedVideoReadyForPlacementID(Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_client != null && _client.hasAdReady(Key))
|
||||
{
|
||||
curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
curState = 1;
|
||||
_client.loadVideoAd(Key, JsonMapper.ToJson(BuildRewardedExtra()));
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdLoaded(string placementId)
|
||||
{
|
||||
this.curState = 2;
|
||||
Debug.Log($"[Topon] Rewarded loaded. placementId={placementId}");
|
||||
curState = 2;
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdLoadFail(string placementId, string code, string message)
|
||||
{
|
||||
Debug.LogError($"激励视频加载失败: {message} , code:{code} , placementId: {placementId}");
|
||||
this.curState = 0;
|
||||
curState = 0;
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayStart(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Rewarded play start. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayEnd(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Rewarded play end. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayFail(string placementId, string code, string message)
|
||||
{
|
||||
Debug.LogError($"激励视频播放失败: {message} , code:{code} , placementId: {placementId}");
|
||||
curState = 0;
|
||||
this.adListener.OnShowError();
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayClosed(string placementId, bool isReward, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
this.adListener.OnRewardVerify(isReward , 1 , "");
|
||||
this.adListener.OnAdClose();
|
||||
Debug.Log($"[Topon] Rewarded closed. placementId={placementId}, reward={isReward}");
|
||||
adListener.OnRewardVerify(isReward, 1, "");
|
||||
adListener.OnAdClose();
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayClicked(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Rewarded clicked. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onReward(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
this.adListener.OnRewardVerify(true , 1 , "");
|
||||
this.adListener.OnAdClose();
|
||||
Debug.Log($"[Topon] Rewarded reward callback. placementId={placementId}");
|
||||
adListener.OnRewardVerify(true, 1, "");
|
||||
adListener.OnAdClose();
|
||||
}
|
||||
|
||||
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -161,7 +160,7 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
|
||||
public void failToLoadADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
|
||||
{
|
||||
this.OnError(code , message);
|
||||
OnError(code, message);
|
||||
}
|
||||
|
||||
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -176,14 +175,12 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo?.setAutoLocalExtra(this.Key, BuildRewardedExtra());
|
||||
_client?.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildRewardedExtra()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +203,7 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
return;
|
||||
}
|
||||
|
||||
this._atRewardedAutoVideo?.addAutoLoadAdPlacementID(new[] { this.Key });
|
||||
_client?.addAutoLoadAdPlacementID(new[] { Key });
|
||||
_autoLoadRegistered = true;
|
||||
}
|
||||
|
||||
@@ -229,11 +226,10 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryAutoAdScenarioWithPlacementID(Key, scenario);
|
||||
return;
|
||||
}
|
||||
|
||||
this._atRewardedVideo?.entryScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryScenarioWithPlacementID(Key, scenario);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user