| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- import { DataEventId } from "../../../../../game/data/GameData";
- import { zgSingleton } from "../../zgSingleton";
- import ATSDKMgr from "./ATSDKMgr";
- /**
- * inter插屏广告
- * @description
- * @author 冯聪
- */
- export default class ATInterstitial extends zgSingleton {
- /** */
- private ATInterstitialJS: any;
- /** 插屏广告类型 0 插屏 1全屏 */
- private interAdType: number = -1;
- /** 插屏广告状态 */
- private interAdState: InterAdState = 0;
- /** 是否加载完显示 */
- private ifLoadShow: boolean = false;
- private singleClick = false;
- private singleClickFull = false;
- /** 初始化 */
- init() {
- this.ATInterstitialJS = cc["ATInterstitialJS"];
- this.ATInterstitialJS.proxy = this;;
- this.ATInterstitialJS.init();
- if (this.interAdState == InterAdState.Unload) {
- this.loadInter(0);
- this.loadInter(1);
- }
- }
- /** 广告位id
- * @param 0 插屏 1 全屏
- */
- placementID() {
- if (this.interAdType == 0) {
- if (cc.sys.os === cc.sys.OS_IOS) {
- return ATSDKMgr.topon_inter_placementId;
- } else if (cc.sys.os === cc.sys.OS_ANDROID) {
- return ATSDKMgr.topon_inter_placementId;
- }
- }
- else {
- if (cc.sys.os === cc.sys.OS_IOS) {
- return ATSDKMgr.topon_fullinter_placementId;
- } else if (cc.sys.os === cc.sys.OS_ANDROID) {
- return ATSDKMgr.topon_fullinter_placementId;
- }
- }
- }
- /**
- * 检查当前广告类型
- * @param placementId 当前广告id
- * @returns 0 插屏 1 全屏
- */
- checkPlacementIDType(placementId) {
- if (cc.sys.os === cc.sys.OS_IOS) {
- if (placementId == ATSDKMgr.topon_inter_placementId) {
- return 0;
- }
- else if (placementId == ATSDKMgr.topon_fullinter_placementId) {
- return 1;
- }
- } else if (cc.sys.os === cc.sys.OS_ANDROID) {
- if (placementId == ATSDKMgr.topon_inter_placementId) {
- return 0;
- }
- else if (placementId == ATSDKMgr.topon_fullinter_placementId) {
- return 1;
- }
- }
- }
- //广告逻辑部分------------------------------------------------------------------------
- /** 检测是否插屏预备好了 */
- hasAdReady() {
- return this.ATInterstitialJS.hasAdReady();
- }
- /**
- * 加载插屏广告
- * @param type 0 插屏 1 全屏
- */
- loadInter(type: number, ifLoadShow: boolean = false) {
- this.ifLoadShow = ifLoadShow;
- this.interAdState = InterAdState.Loading;
- this.ATInterstitialJS.loadInter(type);
- }
- /**
- * 显示插屏广告
- * @param type 0 插屏 1 全屏
- */
- showInter(type: number) {
- if (this.interAdState == InterAdState.Show && type == this.interAdType) {
- //正在显示不重复弹出
- console.log('当前插屏类型正在展示');
- }
- else {
- this.interAdType = type;
- if (this.hasAdReady()) {
- this.interAdState = InterAdState.Show;
- this.ATInterstitialJS.showInter(type);
- }
- else {
- //如果正在加载中,则不处理
- if (this.interAdState == InterAdState.Loading) {
- //正在加载不重复加载
- this.ifLoadShow = true;
- }
- else {
- this.loadInter(type, true)
- }
- }
- }
- }
- //广告回调部分------------------------------------------------------------------------
- onInterstitialAdLoaded(placementId) {
- this.interAdState = InterAdState.LoadSuccess;
- if (this.ifLoadShow) {
- let type = this.checkPlacementIDType(placementId);
- this.showInter(type);
- }
- }
- onInterstitialAdLoadFail(placementId, errorInfo) {
- this.interAdState = InterAdState.LoadFail;
- let id = 11
- let type = this.checkPlacementIDType(placementId);
- if (type == 0) {
- id = 11
- }
- else if (type == 1) {
- // mk.tip.pop('拉取全屏视频失败,请稍后再试');
- id = 10
- }
- gData.adData.updateADLog(id, placementId);
- }
- //广告展示成功
- onInterstitialAdShow(placementId, callbackInfo) {
- this.interAdState = InterAdState.Show;
- // // console.log('99999999 onInterstitialAdShow')
- let data = JSON.parse(callbackInfo)
- let id = 2
- let type = this.checkPlacementIDType(placementId);
- if (type == 0) {
- id = 2
- this.singleClick = true;
- }
- else if (type == 1) {
- id = 9
- this.singleClickFull = true;
- }
- gData.adData.updateADLog(id, placementId, data);
- // if (GameM.commonData.ifUROI) {
- // let eventID = EncryptUtil.randomString(32);
- // let adAdn = this.getAdAdn(data.network_firm_id)
- // let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- // AdM.sendUROIEvent(eventID, data.id, placementId, "ad_show", "interstitial", adAdn, price)
- // }
- }
- onInterstitialAdClick(placementId, callbackInfo) {
- // let data = JSON.parse(callbackInfo)
- // if (GameM.commonData.ifUROI) {
- // let eventID = EncryptUtil.randomString(32);
- // let adAdn = this.getAdAdn(data.network_firm_id)
- // let price = GameM.commonData.getAdPrice(data.adsource_id, data.adsource_price)
- // AdM.sendUROIEvent(eventID, data.id, placementId, "ad_click", "interstitial", adAdn, price)
- // }
- let id = 52;
- let singleId = 72;
- let type = this.checkPlacementIDType(placementId);
- let data = JSON.parse(callbackInfo)
- if (type == 0) {
- id = 52;
- singleId = 72;
- mk.data.sendDataEvent(DataEventId.ad_click, '插屏点击');
- if (this.singleClick) {
- this.singleClick = false;
- gData.adData.updateADLog(singleId, placementId, data);
- }
- }
- else if (type == 1) {
- id = 56;
- singleId = 76;
- mk.data.sendDataEvent(DataEventId.ad_click, '全屏插屏点击');
- if (this.singleClickFull) {
- this.singleClickFull = false;
- gData.adData.updateADLog(singleId, placementId, data);
- }
- }
- gData.adData.updateADLog(id, placementId, data);
- }
- //插屏广告关闭
- onInterstitialAdClose(placementId, callbackInfo) {
- this.interAdState = InterAdState.Close;
- // //给奖励
- let type = this.checkPlacementIDType(placementId);
- if (type == 1) {
- let data = JSON.parse(callbackInfo);
- gData.adData.updateADLog(8, placementId, data);
- this.loadInter(1);
- }
- else {
- this.loadInter(0);
- }
- }
- onInterstitialAdFailedToPlayVideo(placementId, errorInfo) {
- mk.console.logSingle('onInterstitialAdFailedToPlayVideo placementId >> ', placementId);
- mk.console.logSingle('onInterstitialAdFailedToPlayVideo ', errorInfo);
- }
- }
- /** 插屏广告加载状态 */
- export enum InterAdState {
- /** 未加载 */
- Unload = 0,
- /** 加载中 */
- Loading = 1,
- /** 加载成功 */
- LoadSuccess = 2,
- /** 加载失败 */
- LoadFail = 3,
- /** 显示状态 */
- Show = 4,
- /** 关闭状态 */
- Close = 5
- }
|