You've already forked Commercialization.topon
release: 1.4.8
This commit is contained in:
@@ -1,147 +1,153 @@
|
||||
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 InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
public class InteractionPlayer : ADPlayer, ATInterstitialAdListener
|
||||
{
|
||||
private ATInterstitialAd _atInterstitialAd;
|
||||
private ATInterstitialAutoAd _atInterstitialAutoAd;
|
||||
private IATInterstitialAdClient _client;
|
||||
private ADListenerAggregator _aggregator;
|
||||
private bool _autoLoadRegistered;
|
||||
|
||||
private bool _autoLoadRegistered;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
this._atInterstitialAd = ATInterstitialAd.Instance;
|
||||
this._atInterstitialAutoAd = ATInterstitialAutoAd.Instance;
|
||||
this._aggregator = new ADListenerAggregator();
|
||||
this._aggregator.BindInterstitialAdListener(this._atInterstitialAd.client,this);
|
||||
_client = AnyThinkAds.ATAdsClientFactory.BuildInterstitialAdClient();
|
||||
_aggregator = new ADListenerAggregator();
|
||||
_aggregator.BindInterstitialAdListener(_client, this);
|
||||
}
|
||||
|
||||
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
|
||||
{
|
||||
if (this.IsReadly())
|
||||
if (!IsReadly())
|
||||
{
|
||||
this.adListener.onClose = onClose;
|
||||
this.adListener.onVideoComplete = onVideoComplete;
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd.showAutoAd(this.Key, BuildInterstitialExtra());
|
||||
}
|
||||
else
|
||||
{
|
||||
ATInterstitialAd.Instance.showInterstitialAd(this.Key);
|
||||
}
|
||||
curState = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
adListener.onClose = onClose;
|
||||
adListener.onVideoComplete = onVideoComplete;
|
||||
var mapJson = JsonMapper.ToJson(BuildInterstitialExtra());
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.showAutoAd(Key, mapJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
_client.showInterstitialAd(Key, mapJson);
|
||||
}
|
||||
|
||||
curState = 0;
|
||||
}
|
||||
|
||||
public override bool IsReadly()
|
||||
{
|
||||
if (this.curState == 2)
|
||||
if (curState == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
if (this._atInterstitialAutoAd != null &&
|
||||
this._atInterstitialAutoAd.autoLoadInterstitialAdReadyForPlacementID(this.Key))
|
||||
if (_client != null && _client.autoLoadInterstitialAdReadyForPlacementID(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._atInterstitialAd != null && this._atInterstitialAd.hasInterstitialAdReady(this.Key))
|
||||
if (_client != null && _client.hasInterstitialAdReady(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override void LoadAD()
|
||||
{
|
||||
if (curState == 0)
|
||||
if (curState != 0)
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd.setAutoLocalExtra(this.Key, BuildInterstitialExtra());
|
||||
this.curState = this._atInterstitialAutoAd.autoLoadInterstitialAdReadyForPlacementID(this.Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._atInterstitialAd != null && this._atInterstitialAd.hasInterstitialAdReady(this.Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
//加载广告
|
||||
Dictionary<string, object> jsonmap = new Dictionary<string, object>();
|
||||
//只针对Sigmob,Sigmob的激励视频广告源当做插屏使用
|
||||
// jsonmap.Add(AnyThinkAds.Api.ATConst.USE_REWARDED_VIDEO_AS_INTERSTITIAL, AnyThinkAds.Api.ATConst.USE_REWARDED_VIDEO_AS_INTERSTITIAL_NO);
|
||||
var width = (int) (Screen.width * 0.7f);
|
||||
ATSize atSize = new ATSize(width, (int) (width * 1.5f));
|
||||
jsonmap.Add(ATInterstitialAdLoadingExtra.kATInterstitialAdLoadingExtraInterstitialAdSizeStruct , atSize);
|
||||
curState = 1;
|
||||
this._atInterstitialAd.loadInterstitialAd(this.Key, jsonmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#region SDK
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildInterstitialExtra()));
|
||||
curState = _client.autoLoadInterstitialAdReadyForPlacementID(Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_client != null && _client.hasInterstitialAdReady(Key))
|
||||
{
|
||||
curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonmap = new Dictionary<string, object>();
|
||||
var width = (int)(Screen.width * 0.7f);
|
||||
var atSize = new ATSize(width, (int)(width * 1.5f));
|
||||
jsonmap.Add(ATInterstitialAdLoadingExtra.kATInterstitialAdLoadingExtraInterstitialAdSizeStruct, atSize);
|
||||
curState = 1;
|
||||
_client.loadInterstitialAd(Key, JsonMapper.ToJson(jsonmap));
|
||||
}
|
||||
|
||||
public void onInterstitialAdLoad(string placementId)
|
||||
{
|
||||
this.curState = 2;
|
||||
Debug.Log($"[Topon] Interstitial loaded. placementId={placementId}");
|
||||
curState = 2;
|
||||
}
|
||||
|
||||
public void onInterstitialAdLoadFail(string placementId, string code, string message)
|
||||
{
|
||||
this.curState = 0;
|
||||
Debug.LogError($"插屏加载失败: {message} , code:{code} , placementId: {placementId}");
|
||||
curState = 0;
|
||||
}
|
||||
|
||||
public void onInterstitialAdShow(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial show. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdFailedToShow(string placementId)
|
||||
{
|
||||
this.curState = 0;
|
||||
this.adListener.OnShowError();
|
||||
curState = 0;
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void onInterstitialAdClose(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
this.adListener.OnAdClose();
|
||||
this.adListener.OnShowComplete();
|
||||
Debug.Log($"[Topon] Interstitial close. placementId={placementId}");
|
||||
adListener.OnAdClose();
|
||||
adListener.OnShowComplete();
|
||||
}
|
||||
|
||||
public void onInterstitialAdClick(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial clicked. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdStartPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial video start. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdEndPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial video end. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdFailedToPlayVideo(string placementId, string code, string message)
|
||||
{
|
||||
this.curState = 0;
|
||||
this.adListener.OnShowError();
|
||||
curState = 0;
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -154,7 +160,7 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
|
||||
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)
|
||||
@@ -167,17 +173,15 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
|
||||
public void failBiddingADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
|
||||
{
|
||||
this.OnError(code , message);
|
||||
OnError(code, message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd?.setAutoLocalExtra(this.Key, BuildInterstitialExtra());
|
||||
_client?.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildInterstitialExtra()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +204,7 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
return;
|
||||
}
|
||||
|
||||
this._atInterstitialAutoAd?.addAutoLoadAdPlacementID(new[] { this.Key });
|
||||
_client?.addAutoLoadAdPlacementID(new[] { Key });
|
||||
_autoLoadRegistered = true;
|
||||
}
|
||||
|
||||
@@ -208,7 +212,7 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ ATConst.SCENARIO, this.AdScene ?? string.Empty }
|
||||
{ ATConst.SCENARIO, AdScene ?? string.Empty }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -222,10 +226,10 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryAutoAdScenarioWithPlacementID(Key, scenario);
|
||||
return;
|
||||
}
|
||||
|
||||
this._atInterstitialAd?.entryScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryScenarioWithPlacementID(Key, scenario);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user