ATSplashAdClient.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 ATSplashAdClient : IATSplashAdClient {
  10. private ATSplashAdListener 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 event EventHandler<ATAdEventArgs> onAdLoadTimeoutEvent;
  27. public event EventHandler<ATAdEventArgs> onDeeplinkEvent;
  28. public event EventHandler<ATAdEventArgs> onDownloadConfirmEvent;
  29. public void addsetting(string placementId,string json){
  30. //todo...
  31. }
  32. public void setListener(ATSplashAdListener listener) {
  33. Debug.Log("Unity: ATSplashAdAdClient::setListener()");
  34. anyThinkListener = listener;
  35. }
  36. public void loadSplashAd(string placementId, int fetchAdTimeout, string defaultAdSourceConfig, string mapJson) {
  37. Debug.Log("Unity: ATSplashAdAdClient::loadSplashAd()");
  38. ATSplashAdWrapper.setClientForPlacementID(placementId, this);
  39. ATSplashAdWrapper.loadSplashAd(placementId, mapJson);
  40. }
  41. public bool hasSplashAdReady(string placementId) {
  42. Debug.Log("Unity: ATSplashAdAdClient::hasSplashAdReady()");
  43. return ATSplashAdWrapper.hasSplashAdReady(placementId);
  44. }
  45. public void showSplashAd(string placementId, string mapJson) {
  46. Debug.Log("Unity: ATSplashAdAdClient::showSplashAd()");
  47. ATSplashAdWrapper.showSplashAd(placementId, mapJson);
  48. }
  49. public void cleanCache(string placementId) {
  50. Debug.Log("Unity: ATSplashAdAdClient::cleanCache()");
  51. ATSplashAdWrapper.clearCache(placementId);
  52. }
  53. public string checkAdStatus(string placementId) {
  54. Debug.Log("Unity: ATSplashAdAdClient::checkAdStatus()");
  55. return ATSplashAdWrapper.checkAdStatus(placementId);
  56. }
  57. public string getValidAdCaches(string placementId)
  58. {
  59. Debug.Log("Unity: ATSplashAdAdClient::getValidAdCaches()");
  60. return ATSplashAdWrapper.getValidAdCaches(placementId);
  61. }
  62. public void entryScenarioWithPlacementID(string placementId, string scenarioID){
  63. Debug.Log("Unity: ATSplashAdAdClient::entryScenarioWithPlacementID()");
  64. ATSplashAdWrapper.entryScenarioWithPlacementID(placementId,scenarioID);
  65. }
  66. //Callbacks
  67. public void OnSplashAdDeeplink(string placementID, String callbackJson, bool isSuccess) {
  68. onDeeplinkEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson, false, isSuccess));
  69. }
  70. public void OnSplashAdLoadTimeout(string placementID) {
  71. Debug.Log("OnSplashAdLoadTimeout...unity3d.");
  72. onAdLoadTimeoutEvent?.Invoke(this, new ATAdEventArgs(placementID, "", true));
  73. }
  74. public void OnSplashAdLoaded(string placementID) {
  75. Debug.Log("onSplashAdLoaded...unity3d.");
  76. onAdLoadEvent?.Invoke(this, new ATAdEventArgs(placementID));
  77. }
  78. public void OnSplashAdLoadFailure(string placementID, string code, string error) {
  79. Debug.Log("onSplashAdFailed...unity3d.");
  80. onAdLoadFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementID, code, error));
  81. }
  82. public void OnSplashAdVideoPlayFailure(string placementID, string code, string error) {
  83. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdVideoPlayFailure()");
  84. onAdVideoFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementID, code, error));
  85. }
  86. public void OnSplashAdVideoPlayStart(string placementID, string callbackJson) {
  87. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdPlayStart()");
  88. onAdVideoStartEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  89. }
  90. public void OnSplashAdVideoPlayEnd(string placementID, string callbackJson) {
  91. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdVideoPlayEnd()");
  92. onAdVideoEndEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  93. }
  94. public void OnSplashAdShow(string placementID, string callbackJson) {
  95. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdShow()");
  96. onAdShowEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  97. }
  98. public void OnSplashAdFailedToShow(string placementID) {
  99. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdFailedToShow()");
  100. onAdShowFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementID, "-1", "Failed to show video ad"));
  101. }
  102. public void OnSplashAdClick(string placementID, string callbackJson) {
  103. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdClick()");
  104. onAdClickEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  105. }
  106. public void OnSplashAdClose(string placementID, string callbackJson) {
  107. Debug.Log("Unity: ATSplashAdAdClient::OnSplashAdClose()");
  108. onAdCloseEvent?.Invoke(this, new ATAdEventArgs(placementID, callbackJson));
  109. }
  110. //auto callbacks
  111. public void startLoadingADSource(string placementId, string callbackJson)
  112. {
  113. Debug.Log("Unity: ATSplashAdAdClient::startLoadingADSource()");
  114. onAdSourceAttemptEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  115. }
  116. public void finishLoadingADSource(string placementId, string callbackJson)
  117. {
  118. Debug.Log("Unity: ATSplashAdAdClient::finishLoadingADSource()");
  119. onAdSourceFilledEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  120. }
  121. public void failToLoadADSource(string placementId, string callbackJson,string code, string error)
  122. {
  123. Debug.Log("Unity: ATSplashAdAdClient::failToLoadADSource()");
  124. onAdSourceLoadFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, callbackJson, code, error));
  125. }
  126. public void startBiddingADSource(string placementId, string callbackJson)
  127. {
  128. Debug.Log("Unity: ATSplashAdAdClient::startBiddingADSource()");
  129. onAdSourceBiddingAttemptEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  130. }
  131. public void finishBiddingADSource(string placementId, string callbackJson)
  132. {
  133. Debug.Log("Unity: ATSplashAdAdClient::finishBiddingADSource()");
  134. onAdSourceBiddingFilledEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  135. }
  136. public void failBiddingADSource(string placementId,string callbackJson, string code, string error)
  137. {
  138. Debug.Log("Unity: ATSplashAdAdClient::failBiddingADSource()");
  139. onAdSourceBiddingFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, callbackJson, code, error));
  140. }
  141. // Auto
  142. public void addAutoLoadAdPlacementID(string[] placementIDList)
  143. {
  144. Debug.Log("Unity: ATSplashAdAdClient:addAutoLoadAdPlacementID()");
  145. if (placementIDList != null && placementIDList.Length > 0)
  146. {
  147. foreach (string placementID in placementIDList)
  148. {
  149. ATSplashAdWrapper.setClientForPlacementID(placementID, this);
  150. }
  151. string placementIDListString = JsonMapper.ToJson(placementIDList);
  152. ATSplashAdWrapper.addAutoLoadAdPlacementID(placementIDListString);
  153. Debug.Log("addAutoLoadAdPlacementID, placementIDList === " + placementIDListString);
  154. }
  155. else
  156. {
  157. Debug.Log("addAutoLoadAdPlacementID, placementIDList = null");
  158. }
  159. }
  160. public void removeAutoLoadAdPlacementID(string placementId)
  161. {
  162. Debug.Log("Unity: ATSplashAdAdClient:removeAutoLoadAdPlacementID()");
  163. ATSplashAdWrapper.removeAutoLoadAdPlacementID(placementId);
  164. }
  165. public bool autoLoadSplashAdReadyForPlacementID(string placementId)
  166. {
  167. Debug.Log("Unity: ATSplashAdAdClient:autoLoadSplashAdReadyForPlacementID()");
  168. return ATSplashAdWrapper.autoLoadSplashAdReadyForPlacementID(placementId);
  169. }
  170. public string getAutoValidAdCaches(string placementId)
  171. {
  172. Debug.Log("Unity: ATSplashAdAdClient:getAutoValidAdCaches()");
  173. return ATSplashAdWrapper.getAutoValidAdCaches(placementId);
  174. }
  175. public string checkAutoAdStatus(string placementId) {
  176. Debug.Log("Unity: ATSplashAdAdClient::checkAutoAdStatus()");
  177. return ATSplashAdWrapper.checkAutoAdStatus(placementId);
  178. }
  179. public void setAutoLocalExtra(string placementId, string mapJson)
  180. {
  181. Debug.Log("Unity: ATSplashAdAdClient:setAutoLocalExtra()");
  182. ATSplashAdWrapper.setAutoLocalExtra(placementId, mapJson);
  183. }
  184. public void entryAutoAdScenarioWithPlacementID(string placementId, string scenarioID)
  185. {
  186. Debug.Log("Unity: ATSplashAdAdClient:entryAutoAdScenarioWithPlacementID()");
  187. ATSplashAdWrapper.entryAutoAdScenarioWithPlacementID(placementId, scenarioID);
  188. }
  189. public void showAutoAd(string placementId, string mapJson)
  190. {
  191. Debug.Log("Unity: ATSplashAdAdClient::showAutoAd()");
  192. ATSplashAdWrapper.showAutoSplashAd(placementId, mapJson);
  193. }
  194. }
  195. }