| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- require("./AnyThinkAds/ATRewardedVideoJSSDK");
- require("./AnyThinkAds/ATJSSDK");
- require("./AnyThinkAds/ATInterstitialJSSDK");
- require("./AnyThinkAds/ATNativeJSSDK");
- var ATNativeJS = cc.Class({
- name: "ATNativeJS",
- /** 代理脚本(TS) */
- proxy: null,
- // timeID: 0,
- ctor: function () {
- // console.log("ATNativeJS created! ");
- },
- init: function () {
- ATNativeJSSDK.setAdListener(this);
- },
- /** 广告位Id */
- placementID: function () {
- return this.proxy.placementID();
- },
- /** 检测是否插屏预备好*/
- hasAdReady() {
- return ATNativeJSSDK.hasAdReady(this.placementID()) ? true : false;
- },
- /**
- * 加载原生广告
- * @param {*} width 类型
- * @param {*} height 是否显示
- */
- loadNative: function (width, height) {
- ATNativeJSSDK.loadNative(this.placementID(), ATNativeJSSDK.createLoadAdSize(width, height));
- },
- /** 信息流位置
- * @param {*} posX x位置
- * @param {*} posY y位置
- * @param {*} width 宽度
- * @param {*} height 高度
- * @param {*} fontSize 字体大小
- */
- showNative: function (posX, posY, width, height, fontSize) {
- let nativeAdViewProperty = new ATNativeJSSDK.AdViewProperty();
- nativeAdViewProperty.parent = nativeAdViewProperty.createItemViewProperty(posX, posY, width, height, "#ffffff", "", 0);
- nativeAdViewProperty.mainImage = nativeAdViewProperty.createItemViewProperty(0, 0, width, height, "#ffffff", "#ffffff", fontSize);
- ATNativeJSSDK.showAd(this.placementID(), nativeAdViewProperty);
- },
- /**
- * 销毁原生广告
- */
- destroyNative: function () {
- ATNativeJSSDK.removeAd(this.placementID());
- },
- //广告回调部分------------------------------------------------------------------------
- /**
- * 原生广告加载成功
- * @param {*} placementId
- */
- onNativeAdLoaded: function (placementId) {
- if (this.proxy == null) return;
- this.proxy.onNativeAdLoaded(placementId);
- },
- /**
- * 原生广告加载失败
- * @param {*} placementId 广告位id
- * @param {*} errorInfo 错误信息
- */
- onNativeAdLoadFail: function (placementId, errorInfo) {
- ATJSSDK.printLog("===[AnyThinkNativeDemo::onNativeAdLoadFail(" + placementId + ", " + errorInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onNativeAdLoadFail(placementId, errorInfo);
- },
- /**
- * 原生广告显示成功
- * @param {*} placementId 广告位id
- * @param {*} callbackInfo 回调信息
- * @returns
- */
- onNativeAdShow: function (placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdShow(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onNativeAdShow(placementId, callbackInfo);
- },
- /**
- * 原生广告被点击
- * @param {*} placementId 广告位Id
- * @param {*} callbackInfo 回调信息
- */
- onNativeAdClick: function (placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdClick(" + placementId + ", " + callbackInfo + ")");
- if (this.proxy == null) return;
- this.proxy.onNativeAdClick(placementId, callbackInfo);
- },
- /**
- * 原生广告视频开始播放,部分广告平台有此回调
- * @param {*} placementId 广告位id
- */
- onNativeAdVideoStart: function (placementId) {
- // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdVideoStart(" + placementId + ")");
- },
- /**
- * 原生广告视频结束播放,部分广告平台有此回调
- * @param {*} placementId
- */
- onNativeAdVideoEnd: function (placementId) {
- // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdVideoEnd(" + placementId + ")");
- },
- /**
- * 广告关闭按钮被点击,部分广告平台有此回调
- * @param {*} placementId
- * @param {*} callbackInfo
- */
- onNativeAdCloseButtonTapped: function (placementId, callbackInfo) {
- // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");
- }
- });
- module.exports = ATNativeJS;
- if (!cc["ATNativeJS"]) {
- cc["ATNativeJS"] = new ATNativeJS();
- }
|