ATNativeJS.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. require("./AnyThinkAds/ATRewardedVideoJSSDK");
  2. require("./AnyThinkAds/ATJSSDK");
  3. require("./AnyThinkAds/ATInterstitialJSSDK");
  4. require("./AnyThinkAds/ATNativeJSSDK");
  5. var ATNativeJS = cc.Class({
  6. name: "ATNativeJS",
  7. /** 代理脚本(TS) */
  8. proxy: null,
  9. // timeID: 0,
  10. ctor: function () {
  11. // console.log("ATNativeJS created! ");
  12. },
  13. init: function () {
  14. ATNativeJSSDK.setAdListener(this);
  15. },
  16. /** 广告位Id */
  17. placementID: function () {
  18. return this.proxy.placementID();
  19. },
  20. /** 检测是否插屏预备好*/
  21. hasAdReady() {
  22. return ATNativeJSSDK.hasAdReady(this.placementID()) ? true : false;
  23. },
  24. /**
  25. * 加载原生广告
  26. * @param {*} width 类型
  27. * @param {*} height 是否显示
  28. */
  29. loadNative: function (width, height) {
  30. ATNativeJSSDK.loadNative(this.placementID(), ATNativeJSSDK.createLoadAdSize(width, height));
  31. },
  32. /** 信息流位置
  33. * @param {*} posX x位置
  34. * @param {*} posY y位置
  35. * @param {*} width 宽度
  36. * @param {*} height 高度
  37. * @param {*} fontSize 字体大小
  38. */
  39. showNative: function (posX, posY, width, height, fontSize) {
  40. let nativeAdViewProperty = new ATNativeJSSDK.AdViewProperty();
  41. nativeAdViewProperty.parent = nativeAdViewProperty.createItemViewProperty(posX, posY, width, height, "#ffffff", "", 0);
  42. nativeAdViewProperty.mainImage = nativeAdViewProperty.createItemViewProperty(0, 0, width, height, "#ffffff", "#ffffff", fontSize);
  43. ATNativeJSSDK.showAd(this.placementID(), nativeAdViewProperty);
  44. },
  45. /**
  46. * 销毁原生广告
  47. */
  48. destroyNative: function () {
  49. ATNativeJSSDK.removeAd(this.placementID());
  50. },
  51. //广告回调部分------------------------------------------------------------------------
  52. /**
  53. * 原生广告加载成功
  54. * @param {*} placementId
  55. */
  56. onNativeAdLoaded: function (placementId) {
  57. if (this.proxy == null) return;
  58. this.proxy.onNativeAdLoaded(placementId);
  59. },
  60. /**
  61. * 原生广告加载失败
  62. * @param {*} placementId 广告位id
  63. * @param {*} errorInfo 错误信息
  64. */
  65. onNativeAdLoadFail: function (placementId, errorInfo) {
  66. ATJSSDK.printLog("===[AnyThinkNativeDemo::onNativeAdLoadFail(" + placementId + ", " + errorInfo + ")");
  67. if (this.proxy == null) return;
  68. this.proxy.onNativeAdLoadFail(placementId, errorInfo);
  69. },
  70. /**
  71. * 原生广告显示成功
  72. * @param {*} placementId 广告位id
  73. * @param {*} callbackInfo 回调信息
  74. * @returns
  75. */
  76. onNativeAdShow: function (placementId, callbackInfo) {
  77. // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdShow(" + placementId + ", " + callbackInfo + ")");
  78. if (this.proxy == null) return;
  79. this.proxy.onNativeAdShow(placementId, callbackInfo);
  80. },
  81. /**
  82. * 原生广告被点击
  83. * @param {*} placementId 广告位Id
  84. * @param {*} callbackInfo 回调信息
  85. */
  86. onNativeAdClick: function (placementId, callbackInfo) {
  87. // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdClick(" + placementId + ", " + callbackInfo + ")");
  88. if (this.proxy == null) return;
  89. this.proxy.onNativeAdClick(placementId, callbackInfo);
  90. },
  91. /**
  92. * 原生广告视频开始播放,部分广告平台有此回调
  93. * @param {*} placementId 广告位id
  94. */
  95. onNativeAdVideoStart: function (placementId) {
  96. // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdVideoStart(" + placementId + ")");
  97. },
  98. /**
  99. * 原生广告视频结束播放,部分广告平台有此回调
  100. * @param {*} placementId
  101. */
  102. onNativeAdVideoEnd: function (placementId) {
  103. // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdVideoEnd(" + placementId + ")");
  104. },
  105. /**
  106. * 广告关闭按钮被点击,部分广告平台有此回调
  107. * @param {*} placementId
  108. * @param {*} callbackInfo
  109. */
  110. onNativeAdCloseButtonTapped: function (placementId, callbackInfo) {
  111. // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");
  112. }
  113. });
  114. module.exports = ATNativeJS;
  115. if (!cc["ATNativeJS"]) {
  116. cc["ATNativeJS"] = new ATNativeJS();
  117. }