ATRewardedVideoAdClient.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 ATRewardedVideoAdClient : IATRewardedVideoAdClient {
  10. public event EventHandler<ATAdEventArgs> onAdLoadEvent;
  11. public event EventHandler<ATAdErrorEventArgs> onAdLoadFailureEvent;
  12. public event EventHandler<ATAdEventArgs> onAdVideoStartEvent;
  13. public event EventHandler<ATAdEventArgs> onAdVideoEndEvent;
  14. public event EventHandler<ATAdErrorEventArgs> onAdVideoFailureEvent;
  15. public event EventHandler<ATAdRewardEventArgs> onAdVideoCloseEvent;
  16. public event EventHandler<ATAdEventArgs> onAdClickEvent;
  17. public event EventHandler<ATAdEventArgs> onRewardEvent;
  18. public event EventHandler<ATAdEventArgs> onAdSourceAttemptEvent;
  19. public event EventHandler<ATAdEventArgs> onAdSourceFilledEvent;
  20. public event EventHandler<ATAdErrorEventArgs> onAdSourceLoadFailureEvent;
  21. public event EventHandler<ATAdEventArgs> onAdSourceBiddingAttemptEvent;
  22. public event EventHandler<ATAdEventArgs> onAdSourceBiddingFilledEvent;
  23. public event EventHandler<ATAdErrorEventArgs> onAdSourceBiddingFailureEvent;
  24. public event EventHandler<ATAdEventArgs> onPlayAgainStart;
  25. public event EventHandler<ATAdEventArgs> onPlayAgainEnd;
  26. public event EventHandler<ATAdErrorEventArgs> onPlayAgainFailure;
  27. public event EventHandler<ATAdEventArgs> onPlayAgainClick;
  28. public event EventHandler<ATAdEventArgs> onPlayAgainReward;
  29. private ATRewardedVideoListener anyThinkListener;
  30. public void addsetting (string placementId,string json){
  31. //todo...
  32. }
  33. public void setListener(ATRewardedVideoListener listener) {
  34. Debug.Log("Unity: ATRewardedVideoAdClient::setListener()");
  35. anyThinkListener = listener;
  36. }
  37. public void loadVideoAd(string placementId, string mapJson) {
  38. Debug.Log("Unity: ATRewardedVideoAdClient::loadVideoAd()");
  39. ATRewardedVideoWrapper.setClientForPlacementID(placementId, this);
  40. ATRewardedVideoWrapper.loadRewardedVideo(placementId, mapJson);
  41. }
  42. public bool hasAdReady(string placementId) {
  43. Debug.Log("Unity: ATRewardedVideoAdClient::hasAdReady()");
  44. return ATRewardedVideoWrapper.isRewardedVideoReady(placementId);
  45. }
  46. //To be implemented
  47. public void setUserData(string placementId, string userId, string customData) {
  48. Debug.Log("Unity: ATRewardedVideoAdClient::setUserData()");
  49. }
  50. public void showAd(string placementId, string mapJson) {
  51. Debug.Log("Unity: ATRewardedVideoAdClient::showAd()");
  52. ATRewardedVideoWrapper.showRewardedVideo(placementId, mapJson);
  53. }
  54. public void cleanAd(string placementId) {
  55. Debug.Log("Unity: ATRewardedVideoAdClient::cleanAd()");
  56. ATRewardedVideoWrapper.clearCache();
  57. }
  58. public void onApplicationForces(string placementId) {
  59. Debug.Log("Unity: ATRewardedVideoAdClient::onApplicationForces()");
  60. }
  61. public void onApplicationPasue(string placementId) {
  62. Debug.Log("Unity: ATRewardedVideoAdClient::onApplicationPasue()");
  63. }
  64. public string checkAdStatus(string placementId) {
  65. Debug.Log("Unity: ATRewardedVideoAdClient::checkAdStatus()");
  66. return ATRewardedVideoWrapper.checkAdStatus(placementId);
  67. }
  68. public void entryScenarioWithPlacementID(string placementId, string scenarioID){
  69. Debug.Log("Unity: ATRewardedVideoAdClient::entryScenarioWithPlacementID()");
  70. ATRewardedVideoWrapper.entryScenarioWithPlacementID(placementId,scenarioID);
  71. }
  72. public string getValidAdCaches(string placementId)
  73. {
  74. Debug.Log("Unity: ATRewardedVideoAdClient::getValidAdCaches()");
  75. return ATRewardedVideoWrapper.getValidAdCaches(placementId);
  76. }
  77. // Auto
  78. public void addAutoLoadAdPlacementID(string[] placementIDList)
  79. {
  80. Debug.Log("Unity: ATRewardedVideoAdClient:addAutoLoadAdPlacementID()");
  81. if (placementIDList != null && placementIDList.Length > 0)
  82. {
  83. foreach (string placementID in placementIDList)
  84. {
  85. ATRewardedVideoWrapper.setClientForPlacementID(placementID, this);
  86. }
  87. string placementIDListString = JsonMapper.ToJson(placementIDList);
  88. ATRewardedVideoWrapper.addAutoLoadAdPlacementID(placementIDListString);
  89. Debug.Log("addAutoLoadAdPlacementID, placementIDList === " + placementIDListString);
  90. }
  91. else
  92. {
  93. Debug.Log("addAutoLoadAdPlacementID, placementIDList = null");
  94. }
  95. }
  96. public void removeAutoLoadAdPlacementID(string placementId)
  97. {
  98. Debug.Log("Unity: ATRewardedVideoAdClient:removeAutoLoadAdPlacementID()");
  99. ATRewardedVideoWrapper.removeAutoLoadAdPlacementID(placementId);
  100. }
  101. public bool autoLoadRewardedVideoReadyForPlacementID(string placementId)
  102. {
  103. Debug.Log("Unity: ATRewardedVideoAdClient:autoLoadRewardedVideoReadyForPlacementID()");
  104. return ATRewardedVideoWrapper.autoLoadRewardedVideoReadyForPlacementID(placementId);
  105. }
  106. public string getAutoValidAdCaches(string placementId)
  107. {
  108. Debug.Log("Unity: ATRewardedVideoAdClient:getAutoValidAdCaches()");
  109. return ATRewardedVideoWrapper.getAutoValidAdCaches(placementId);
  110. }
  111. public string checkAutoAdStatus(string placementId) {
  112. Debug.Log("Unity: ATRewardedVideoAdClient::checkAutoAdStatus()");
  113. return ATRewardedVideoWrapper.checkAutoAdStatus(placementId);
  114. }
  115. public void setAutoLocalExtra(string placementId, string mapJson)
  116. {
  117. Debug.Log("Unity: ATRewardedVideoAdClient:setAutoLocalExtra()");
  118. ATRewardedVideoWrapper.setAutoLocalExtra(placementId, mapJson);
  119. }
  120. public void entryAutoAdScenarioWithPlacementID(string placementId, string scenarioID)
  121. {
  122. Debug.Log("Unity: ATRewardedVideoAdClient:entryAutoAdScenarioWithPlacementID()");
  123. ATRewardedVideoWrapper.entryAutoAdScenarioWithPlacementID(placementId, scenarioID);
  124. }
  125. public void showAutoAd(string placementId, string mapJson)
  126. {
  127. Debug.Log("Unity: ATRewardedVideoAdClient::showAutoAd()");
  128. ATRewardedVideoWrapper.showAutoRewardedVideo(placementId, mapJson);
  129. }
  130. //auto callbacks
  131. public void startLoadingADSource(string placementId, string callbackJson)
  132. {
  133. Debug.Log("Unity: ATRewardedVideoAdClient::startLoadingADSource()");
  134. onAdSourceAttemptEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  135. }
  136. public void finishLoadingADSource(string placementId, string callbackJson)
  137. {
  138. Debug.Log("Unity: ATRewardedVideoAdClient::finishLoadingADSource()");
  139. onAdSourceFilledEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  140. }
  141. public void failToLoadADSource(string placementId, string callbackJson,string code, string error)
  142. {
  143. Debug.Log("Unity: ATRewardedVideoAdClient::failToLoadADSource()");
  144. onAdSourceLoadFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, callbackJson, code, error));
  145. }
  146. public void startBiddingADSource(string placementId, string callbackJson)
  147. {
  148. Debug.Log("Unity: ATRewardedVideoAdClient::startBiddingADSource()");
  149. onAdSourceBiddingAttemptEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  150. }
  151. public void finishBiddingADSource(string placementId, string callbackJson)
  152. {
  153. Debug.Log("Unity: ATRewardedVideoAdClient::finishBiddingADSource()");
  154. onAdSourceBiddingFilledEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  155. }
  156. public void failBiddingADSource(string placementId, string callbackJson,string code, string error)
  157. {
  158. Debug.Log("Unity: ATRewardedVideoAdClient::failBiddingADSource()");
  159. onAdSourceBiddingFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, callbackJson, code, error));
  160. }
  161. //Callbacks
  162. public void onRewardedVideoAdLoaded(string placementId) {
  163. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdLoaded()");
  164. onAdLoadEvent?.Invoke(this, new ATAdEventArgs(placementId));
  165. }
  166. public void onRewardedVideoAdFailed(string placementId, string code, string error) {
  167. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdFailed()");
  168. onAdLoadFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, code, error));
  169. }
  170. public void onRewardedVideoAdPlayStart(string placementId, string callbackJson) {
  171. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdPlayStart()");
  172. onAdVideoStartEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  173. }
  174. public void onRewardedVideoAdPlayEnd(string placementId, string callbackJson) {
  175. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdPlayEnd()");
  176. onAdVideoEndEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  177. }
  178. public void onRewardedVideoAdPlayFailed(string placementId, string code, string error) {
  179. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdPlayFailed()");
  180. onAdVideoFailureEvent?.Invoke(this, new ATAdErrorEventArgs(placementId, code, error));
  181. }
  182. public void onRewardedVideoAdClosed(string placementId, bool isRewarded, string callbackJson) {
  183. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdClosed()");
  184. onAdVideoCloseEvent?.Invoke(this, new ATAdRewardEventArgs(placementId, callbackJson, isRewarded));
  185. }
  186. public void onRewardedVideoAdPlayClicked(string placementId, string callbackJson) {
  187. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdPlayClicked()");
  188. onAdClickEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  189. }
  190. public void onRewardedVideoReward(string placementId, string callbackJson) {
  191. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoReward()");
  192. onRewardEvent?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  193. }
  194. //--------again callback-------
  195. public void onRewardedVideoAdAgainPlayStart(string placementId, string callbackJson)
  196. {
  197. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdAgainPlayStart()");
  198. onPlayAgainStart?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  199. }
  200. public void onRewardedVideoAdAgainPlayEnd(string placementId, string callbackJson)
  201. {
  202. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdAgainPlayEnd()");
  203. onPlayAgainEnd?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  204. }
  205. public void onRewardedVideoAdAgainPlayFailed(string placementId, string code, string error)
  206. {
  207. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdAgainPlayFailed()");
  208. onPlayAgainFailure?.Invoke(this, new ATAdErrorEventArgs(placementId, code, error));
  209. }
  210. public void onRewardedVideoAdAgainPlayClicked(string placementId, string callbackJson)
  211. {
  212. Debug.Log("Unity: ATRewardedVideoAdClient::onRewardedVideoAdAgainPlayClicked()");
  213. onPlayAgainClick?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  214. }
  215. public void onAgainReward(string placementId, string callbackJson)
  216. {
  217. Debug.Log("Unity: ATRewardedVideoAdClient::onAgainReward()");
  218. onPlayAgainReward?.Invoke(this, new ATAdEventArgs(placementId, callbackJson));
  219. }
  220. }
  221. }