123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- import { Component } from "cc";
- import {ATiOSNativeTS} from "./iOS/ATiOSNativeTS"
- import {ATAndroidNativeTS} from "./Android/ATAndroidNativeTS"
- var initPlatformBridge = function () {
- if (cc.sys.os === cc.sys.OS.IOS) {
- return ATiOSNativeTS;
- } else if (cc.sys.os === cc.sys.OS.ANDROID) {
- return ATAndroidNativeTS;
- }
- };
- var platformBridge = initPlatformBridge();
- export const ATNativeTSSDK = {
- ATNativeListener: {
- developerCallback: null,
- onNativeAdLoaded: function (placementId) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdLoaded != null && undefined != this.developerCallback.onNativeAdLoaded) {
- this.developerCallback.onNativeAdLoaded(placementId);
- }
- },
- onNativeAdLoadFail: function (placementId, errorInfo) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdLoadFail != null && undefined != this.developerCallback.onNativeAdLoadFail) {
- this.developerCallback.onNativeAdLoadFail(placementId, errorInfo);
- }
- },
- onNativeAdShow: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdShow != null && undefined != this.developerCallback.onNativeAdShow) {
- this.developerCallback.onNativeAdShow(placementId, callbackInfo);
- }
- },
- onNativeAdClick: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdClick != null && undefined != this.developerCallback.onNativeAdClick) {
- this.developerCallback.onNativeAdClick(placementId, callbackInfo);
- }
- },
- onNativeAdVideoStart: function (placementId) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdVideoStart != null && undefined != this.developerCallback.onNativeAdVideoStart) {
- this.developerCallback.onNativeAdVideoStart(placementId,);
- }
- },
- onNativeAdVideoEnd: function (placementId) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdVideoEnd != null && undefined != this.developerCallback.onNativeAdVideoEnd) {
- this.developerCallback.onNativeAdVideoEnd(placementId);
- }
- },
- onNativeAdCloseButtonTapped: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onNativeAdCloseButtonTapped != null && undefined != this.developerCallback.onNativeAdCloseButtonTapped) {
- this.developerCallback.onNativeAdCloseButtonTapped(placementId, callbackInfo);
- }
- },
- //added v5.8.10
- onAdSourceBiddingAttempt: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingAttempt != null && undefined != this.developerCallback.onAdSourceBiddingAttempt) {
- this.developerCallback.onAdSourceBiddingAttempt(placementId, callbackInfo);
- }
- },
- onAdSourceBiddingFilled: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingFilled != null && undefined != this.developerCallback.onAdSourceBiddingFilled) {
- this.developerCallback.onAdSourceBiddingFilled(placementId, callbackInfo);
- }
- },
- onAdSourceBiddingFail: function (placementId, errorInfo, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onAdSourceBiddingFail != null && undefined != this.developerCallback.onAdSourceBiddingFail) {
- this.developerCallback.onAdSourceBiddingFail(placementId, errorInfo, callbackInfo);
- }
- },
- onAdSourceAttemp: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onAdSourceAttemp != null && undefined != this.developerCallback.onAdSourceAttemp) {
- this.developerCallback.onAdSourceAttemp(placementId, callbackInfo);
- }
- },
- onAdSourceLoadFilled: function (placementId, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onAdSourceLoadFilled != null && undefined != this.developerCallback.onAdSourceLoadFilled) {
- this.developerCallback.onAdSourceLoadFilled(placementId, callbackInfo);
- }
- },
- onAdSourceLoadFail: function (placementId, errorInfo, callbackInfo) {
- if (this.developerCallback != null && this.developerCallback.onAdSourceLoadFail != null && undefined != this.developerCallback.onAdSourceLoadFail) {
- this.developerCallback.onAdSourceLoadFail(placementId, errorInfo, callbackInfo);
- }
- }
- },
- loadNative: function (placementId, settings = {}) {
- if (undefined != platformBridge && platformBridge != null) {
- platformBridge.loadNative(placementId, JSON.stringify(settings));
- } else {
- cc.log("You must run on Android or iOS.");
- }
- },
- setAdListener: function (listener) {
- var eventJSON = {};
- eventJSON[LoadedCallbackKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdLoaded",
- eventJSON[LoadFailCallbackKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdLoadFail",
- eventJSON[CloseCallbackKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdCloseButtonTapped",
- eventJSON[ClickCallbackKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdClick",
- eventJSON[ShowCallbackKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdShow",
- eventJSON[VideoStartKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdVideoStart",
- eventJSON[VideoEndKey] = "ATNativeTSSDK.ATNativeListener.onNativeAdVideoEnd",
- //added v5.8.10
- eventJSON[BiddingAttempt] = "ATNativeTSSDK.ATNativeListener.onAdSourceBiddingAttempt",
- eventJSON[BiddingFilled] = "ATNativeTSSDK.ATNativeListener.onAdSourceBiddingFilled",
- eventJSON[BiddingFail] = "ATNativeTSSDK.ATNativeListener.onAdSourceBiddingFail",
- eventJSON[Attemp] = "ATNativeTSSDK.ATNativeListener.onAdSourceAttemp",
- eventJSON[LoadFilled] = "ATNativeTSSDK.ATNativeListener.onAdSourceLoadFilled",
- eventJSON[LoadFail] = "ATNativeTSSDK.ATNativeListener.onAdSourceLoadFail"
- if (undefined != platformBridge && platformBridge != null) {
- platformBridge.setAdListener(JSON.stringify(eventJSON));
- } else {
- cc.log("You must run on Android or iOS.");
- }
- this.ATNativeListener.developerCallback = listener;
- },
- hasAdReady: function (placementId) {
- if (undefined != platformBridge && platformBridge != null) {
- return platformBridge.hasAdReady(placementId);
- } else {
- cc.log("You must run on Android or iOS.");
- }
- return false;
- },
- checkAdStatus: function (placementId) {
- if (undefined != platformBridge && platformBridge != null) {
- return platformBridge.checkAdStatus(placementId);
- } else {
- cc.log("You must run on Android or iOS.");
- }
- return "";
- },
- showAd: function (placementId, adViewProperty) {
- if (undefined != platformBridge && platformBridge != null) {
- platformBridge.showAd(placementId, JSON.stringify(adViewProperty.getAdViewProperty()));
- } else {
- cc.log("You must run on Android or iOS.");
- }
- },
- showAdInScenario: function (placementId, adViewProperty, scenario = "") {
- if (undefined != platformBridge && platformBridge != null) {
- platformBridge.showAdInScenario(placementId, JSON.stringify(adViewProperty.getAdViewProperty()), scenario);
- } else {
- cc.log("You must run on Android or iOS.");
- }
- },
- entryAdScenario: function (placementId, scenario = "") {
- if (undefined != platformBridge && platformBridge != null) {
- platformBridge.entryAdScenario(placementId, scenario);
- } else {
- cc.log("You must run on Android or iOS.");
- }
- },
- removeAd: function (placementId) {
- if (undefined != platformBridge && platformBridge != null) {
- platformBridge.removeAd(placementId);
- } else {
- cc.log("You must run on Android or iOS.");
- }
- },
- createLoadAdSize: function (width, height) {
- var loadAdSize = {};
- loadAdSize["width"] = width;
- loadAdSize["height"] = height;
- return loadAdSize;
- },
- };
- export class AdViewProperty extends Component {
- parent = null
- appIcon = null
- mainImage = null
- title = null
- desc = null
- adLogo = null
- cta = null
- rating = null
- dislike = null
- elements = null
- createItemViewProperty (x, y, width, height, backgroundColor, textColor, textSize, isCustomClick = false) {
- var itemProperty = {};
- itemProperty["x"] = x;
- itemProperty["y"] = y;
- itemProperty["width"] = width;
- itemProperty["height"] = height;
- itemProperty["backgroundColor"] = backgroundColor;
- itemProperty["textColor"] = textColor;
- itemProperty["textSize"] = textSize;
- itemProperty["isCustomClick"] = isCustomClick;
- return itemProperty;
- }
- getAdViewProperty() {
- var nativeViewProperty = {};
- if (this.parent != null) {
- nativeViewProperty["parent"] = this.parent;
- }
- if (this.appIcon != null) {
- nativeViewProperty["icon"] = this.appIcon;
- }
- if (this.mainImage != null) {
- nativeViewProperty["mainImage"] = this.mainImage;
- }
- if (this.title != null) {
- nativeViewProperty["title"] = this.title;
- }
- if (this.desc != null) {
- nativeViewProperty["desc"] = this.desc;
- }
- if (this.adLogo != null) {
- nativeViewProperty["adLogo"] = this.adLogo;
- }
- if (this.cta != null) {
- nativeViewProperty["cta"] = this.cta;
- }
- if (this.rating != null) {
- nativeViewProperty["rating"] = this.rating;
- }
- if (this.dislike != null) {
- nativeViewProperty["dislike"] = this.dislike;
- }
- if (this.elements != null) {
- nativeViewProperty["elements"] = this.elements
- }
- return nativeViewProperty;
- }
- }
- const LoadedCallbackKey = "NativeLoaded";
- const LoadFailCallbackKey = "NativeLoadFail";
- const CloseCallbackKey = "NativeCloseButtonTapped";
- const ClickCallbackKey = "NativeClick";
- const ShowCallbackKey = "NativeShow";
- const VideoStartKey = "NativeVideoStart";
- const VideoEndKey = "NativeVideoEnd";
- const BiddingAttempt = "NativeBiddingAttempt";
- const BiddingFilled = "NativeBiddingFilled";
- const BiddingFail = "NativeBiddingFail";
- const Attemp = "NativeAttemp";
- const LoadFilled = "NativeLoadFilled";
- const LoadFail = "NativeLoadFail";
- window["ATNativeTSSDK"] = ATNativeTSSDK;
|