ATInterstitialAdClient.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using AnyThinkAds.Common;
  6. using AnyThinkAds.Api;
  7. using AnyThinkAds.ThirdParty.LitJson;
  8. namespace AnyThinkAds.iOS {
  9. public class ATInterstitialAdClient : IATInterstitialAdClient {
  10. private ATInterstitialAdListener anyThinkListener;
  11. public event EventHandler<ATAdEventArgs> onAdLoadEvent;
  12. public event EventHandler<ATAdErrorEventArgs> onAdLoadFailureEvent;
  13. public event EventHandler<ATAdEventArgs> onAdShowEvent;
  14. public event EventHandler<ATAdErrorEventArgs> onAdShowFailureEvent;
  15. public event EventHandler<ATAdEventArgs> onAdCloseEvent;
  16. public event EventHandler<ATAdEventArgs> onAdClickEvent;
  17. public event EventHandler<ATAdEventArgs> onAdVideoStartEvent;
  18. public event EventHandler<ATAdErrorEventArgs> onAdVideoFailureEvent;
  19. public event EventHandler<ATAdEventArgs> onAdVideoEndEvent;
  20. public event EventHandler<ATAdEventArgs> onAdSourceAttemptEvent;
  21. public event EventHandler<ATAdEventArgs> onAdSourceFilledEvent;
  22. public event EventHandler<ATAdErrorEventArgs> onAdSourceLoadFailureEvent;
  23. public event EventHandler<ATAdEventArgs> onAdSourceBiddingAttemptEvent;
  24. public event EventHandler<ATAdEventArgs> onAdSourceBiddingFilledEvent;
  25. public event EventHandler<ATAdErrorEventArgs> onAdSourceBiddingFailureEvent;
  26. public void addsetting(string placementId,string json){
  27. //todo...
  28. }
  29. public void setListener(ATInterstitialAdListener listener) {
  30. Debug.Log("Unity: ATInterstitialAdClient::setListener()");
  31. anyThinkListener = listener;
  32. }
  33. public void loadInterstitialAd(string placementId, string mapJson) {
  34. Debug.Log("Unity: ATInterstitialAdClient::loadInterstitialAd()");
  35. ATInterstitialAdWrapper.setClientForPlacementID(placementId, this);
  36. ATInterstitialAdWrapper.loadInterstitialAd(placementId, mapJson);
  37. }
  38. public bool hasInterstitialAdReady(string placementId) {
  39. Debug.Log("Unity: ATInterstitialAdClient::hasInterstitialAdReady()");
  40. return ATInterstitialAdWrapper.hasInterstitialAdReady(placementId);
  41. }
  42. public void showInterstitialAd(string placementId, string mapJson) {
  43. Debug.Log("Unity: ATInterstitialAdClient::showInterstitialAd()");
  44. ATInterstitialAdWrapper.showInterstitialAd(placementId, mapJson);
  45. }
  46. public void cleanCache(string placementId) {
  47. Debug.Log("Unity: ATInterstitialAdClient::cleanCache()");
  48. ATInterstitialAdWrapper.clearCache(placementId);
  49. }
  50. public string checkAdStatus(string placementId) {
  51. Debug.Log("Unity: ATInterstitialAdClient::checkAdStatus()");
  52. return ATInterstitialAdWrapper.checkAdStatus(placementId);
  53. }
  54. public string getValidAdCaches(string placementId)
  55. {
  56. Debug.Log("Unity: ATInterstitialAdClient::getValidAdCaches()");
  57. return ATInterstitialAdWrapper.getValidAdCaches(placementId);
  58. }
  59. public void entryScenarioWithPlacementID(string placementId, string scenarioID){
  60. Debug.Log("Unity: ATInterstitialAdClient::entryScenarioWithPlacementID()");
  61. ATInterstitialAdWrapper.entryScenarioWithPlacementID(placementId,scenarioID);
  62. }
  63. //Callbacks
  64. public void OnInterstitialAdLoaded(string placementID) {
  65. Debug.Log("onInterstitialAdLoaded...unity3d.");
  66. onAdLoadEvent?.Invoke(this, new ATAdEventArgs(placementID));
  67. }
  68. public void OnInterstitialAdLoadFailure(string placementID, string code, string error) {
  69. Debug.Log("onInterstitialAdFailed...unity3d.");
  70. onAdLoadFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementID, code, error));
  71. }
  72. public void OnInterstitialAdVideoPlayFailure(string placementID, string code, string error) {
  73. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdVideoPlayFailure()");
  74. onAdVideoFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementID, code, error));
  75. }
  76. public void OnInterstitialAdVideoPlayStart(string placementID, string callbackJson) {
  77. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdPlayStart()");
  78. onAdVideoStartEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  79. }
  80. public void OnInterstitialAdVideoPlayEnd(string placementID, string callbackJson) {
  81. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdVideoPlayEnd()");
  82. onAdVideoEndEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  83. }
  84. public void OnInterstitialAdShow(string placementID, string callbackJson) {
  85. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdShow()");
  86. onAdShowEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  87. }
  88. public void OnInterstitialAdFailedToShow(string placementID) {
  89. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdFailedToShow()");
  90. onAdShowFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementID, "-1", "Failed to show video ad"));
  91. }
  92. public void OnInterstitialAdClick(string placementID, string callbackJson) {
  93. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdClick()");
  94. onAdClickEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  95. }
  96. public void OnInterstitialAdClose(string placementID, string callbackJson) {
  97. Debug.Log("Unity: ATInterstitialAdClient::OnInterstitialAdClose()");
  98. onAdCloseEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  99. }
  100. //auto callbacks
  101. public void startLoadingADSource(string placementId, string callbackJson)
  102. {
  103. Debug.Log("Unity: ATInterstitialAdClient::startLoadingADSource()");
  104. onAdSourceAttemptEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  105. }
  106. public void finishLoadingADSource(string placementId, string callbackJson)
  107. {
  108. Debug.Log("Unity: ATInterstitialAdClient::finishLoadingADSource()");
  109. onAdSourceFilledEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  110. }
  111. public void failToLoadADSource(string placementId, string callbackJson,string code, string error)
  112. {
  113. Debug.Log("Unity: ATInterstitialAdClient::failToLoadADSource()");
  114. onAdSourceLoadFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, callbackJson, code, error));
  115. }
  116. public void startBiddingADSource(string placementId, string callbackJson)
  117. {
  118. Debug.Log("Unity: ATInterstitialAdClient::startBiddingADSource()");
  119. onAdSourceBiddingAttemptEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  120. }
  121. public void finishBiddingADSource(string placementId, string callbackJson)
  122. {
  123. Debug.Log("Unity: ATInterstitialAdClient::finishBiddingADSource()");
  124. onAdSourceBiddingFilledEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  125. }
  126. public void failBiddingADSource(string placementId,string callbackJson, string code, string error)
  127. {
  128. Debug.Log("Unity: ATInterstitialAdClient::failBiddingADSource()");
  129. onAdSourceBiddingFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, callbackJson, code, error));
  130. }
  131. // Auto
  132. public void addAutoLoadAdPlacementID(string[] placementIDList)
  133. {
  134. Debug.Log("Unity: ATInterstitialAdClient:addAutoLoadAdPlacementID()");
  135. if (placementIDList != null && placementIDList.Length > 0)
  136. {
  137. foreach (string placementID in placementIDList)
  138. {
  139. ATInterstitialAdWrapper.setClientForPlacementID(placementID, this);
  140. }
  141. string placementIDListString = JsonMapper.ToJson(placementIDList);
  142. ATInterstitialAdWrapper.addAutoLoadAdPlacementID(placementIDListString);
  143. Debug.Log("addAutoLoadAdPlacementID, placementIDList === " + placementIDListString);
  144. }
  145. else
  146. {
  147. Debug.Log("addAutoLoadAdPlacementID, placementIDList = null");
  148. }
  149. }
  150. public void removeAutoLoadAdPlacementID(string placementId)
  151. {
  152. Debug.Log("Unity: ATInterstitialAdClient:removeAutoLoadAdPlacementID()");
  153. ATInterstitialAdWrapper.removeAutoLoadAdPlacementID(placementId);
  154. }
  155. public bool autoLoadInterstitialAdReadyForPlacementID(string placementId)
  156. {
  157. Debug.Log("Unity: ATInterstitialAdClient:autoLoadInterstitialAdReadyForPlacementID()");
  158. return ATInterstitialAdWrapper.autoLoadInterstitialAdReadyForPlacementID(placementId);
  159. }
  160. public string getAutoValidAdCaches(string placementId)
  161. {
  162. Debug.Log("Unity: ATInterstitialAdClient:getAutoValidAdCaches()");
  163. return ATInterstitialAdWrapper.getAutoValidAdCaches(placementId);
  164. }
  165. public string checkAutoAdStatus(string placementId) {
  166. Debug.Log("Unity: ATInterstitialAdClient::checkAutoAdStatus()");
  167. return ATInterstitialAdWrapper.checkAutoAdStatus(placementId);
  168. }
  169. public void setAutoLocalExtra(string placementId, string mapJson)
  170. {
  171. Debug.Log("Unity: ATInterstitialAdClient:setAutoLocalExtra()");
  172. ATInterstitialAdWrapper.setAutoLocalExtra(placementId, mapJson);
  173. }
  174. public void entryAutoAdScenarioWithPlacementID(string placementId, string scenarioID)
  175. {
  176. Debug.Log("Unity: ATInterstitialAdClient:entryAutoAdScenarioWithPlacementID()");
  177. ATInterstitialAdWrapper.entryAutoAdScenarioWithPlacementID(placementId, scenarioID);
  178. }
  179. public void showAutoAd(string placementId, string mapJson)
  180. {
  181. Debug.Log("Unity: ATInterstitialAdClient::showAutoAd()");
  182. ATInterstitialAdWrapper.showAutoInterstitialAd(placementId, mapJson);
  183. }
  184. }
  185. }