import { BaseView } from "../lightMVC/core/base/BaseView"; import SDK from "./sdk/SDK"; import hallSceneMediator from "./hallSceneMediator"; import { App } from "./Manager/App"; import { SoundManager } from "./Manager/SoundManager"; import TimeControl from "./TimeControl"; import ChooseLevelPanel from "./view/chooseLevel/ChooseLevelPanel"; import ChooseLevelPanelMediator from "./view/chooseLevel/ChooseLevelPanelMediator"; import ChooseSkinPanel from "./view/chooseSkin/ChooseSkinPanel"; import ChooseSkinPanelMediator from "./view/chooseSkin/ChooseSkinPanelMediator"; import InsufficientPanel from "./view/insufficientPanel/InsufficientPanel"; import InsufficientPanelMediator from "./view/insufficientPanel/InsufficientPanelMediator"; import MissionPanel from "./view/missionPanel/MissionPanel"; import MissionPanelMediator from "./view/missionPanel/MissionPanelMediator"; import SetNormalPanel from "./view/setNormal/SetNormalPanel"; import SetNormalPanelMediator from "./view/setNormal/SetNormalPanelMediator"; import ShopPanel from "./view/shopView/ShopPanel"; import ShopPanelMediator from "./view/shopView/ShopPanelMediator"; import TipPanel from "./view/tipPanel/TipPanel"; import TipPanelMediator from "./view/tipPanel/TipPanelMediator"; import AESUtil from "./AESUtil" import ATSDK from "./AnyThinkAds/ATJSSDK"; import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoJSSDK"; import AAJS2 from "./ATAndroidJS2"; import GlobalManager from './GlobalManager'; import ATInterstitialSDK from "./AnyThinkAds/ATInterstitialJSSDK"; import ATBannerSDK from "./AnyThinkAds/ATBannerJSSDK"; import { AdType } from './ATAndroidJS2'; const Tag: string = 'zh:UIGame'; const { ccclass, property } = cc._decorator; @ccclass export default class hallScene extends BaseView { public static _instance; @property(cc.Button) public startGameBtn: cc.Button = null; @property(cc.Button) public setNormalBtn: cc.Button = null; // @property(cc.Button) // public chooseSkinBtn: cc.Button = null; @property(cc.Button) public missionBtn: cc.Button = null; // @property(cc.Button) // public btnVideo: cc.Button = null; // @property(cc.Button) // public btnShop: cc.Button = null; @property(cc.Button) public btnLeft: cc.Button = null; @property(cc.Button) public btnRight: cc.Button = null; @property(cc.PageView) public pageView: cc.PageView = null; @property(cc.Label) public labelTili: cc.Label = null; @property(cc.Label) public physicalTime: cc.Label = null; @property(cc.Label) public labelCoin: cc.Label = null; @property(cc.Label) public labelDiamond: cc.Label = null; private loadSceneName: string = "gameScene"; private currientView = 0; adState: boolean = false; adKey: string = "zh_ad_type"; public static get instance() { return hallScene._instance; } public static set instance(value) { hallScene._instance = value; } onLoad() { // cc.sys.localStorage.clear(); hallScene.instance = this; this.registerMediator(hallSceneMediator, this, "主界面"); SDK.Instance.showBanner(); this.initAd(); this.initAdForPage(); //GlobalManager.getInstance().registerMethod('initAdForPageInter', this.initAdForPageInter.bind(this)); this.initAdPageForBanner(); setTimeout(() => { this.showBannerAd(); }, 100); this.initAdInster(); } private showOrHidenBannerAd(boo: boolean) { var pid = AAJS2.getPlacementId2(AdType.Banner); if (boo) { ATBannerSDK.reShowAd(pid); } else { ATBannerSDK.hideAd(pid); } } private showBannerAd() { var pid = AAJS2.getPlacementId2(AdType.Banner); let boo = ATBannerSDK.hasAdReady(pid); // ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop); ATBannerSDK.showAdInPosition(pid, ATBannerSDK.kATBannerAdShowingPositionBottom); if (boo) { console.log('zh:showBannerAd AD OK SHOW....') //ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionBottom); //ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop); } else { console.log('zh:showBannerAd AD 没有准备好') } } /** * AD播放完毕的事件处理 */ handleCustomEvent() { console.log('zh:00收到发送的事件') //let adKey = "zh_ad_type" let yxAdMark = cc.sys.localStorage.getItem("yxAdMark"); console.log('zh:onAdOverEve yxAdMarkAAAA =' + yxAdMark) let adKeyTemp = '';//初始化一下,随便 switch (yxAdMark) { case 'callBack_btnReplay'://失败了重新尝试 console.log('zh:callBack_btnReplay ') GlobalManager.instance.callMethod('callBack_btnReplay'); break; case 'callBack_for_chouJiang'://抽奖callBack_for_chouJiang console.log('zh:callBack_for_chouJiang ') GlobalManager.instance.callMethod('callBack_for_chouJiang'); break; case 'callBackFor_successPanel'://成功的时候奖 console.log('zh:callBackFor_successPanel ') GlobalManager.instance.callMethod('callBackFor_successPanel'); break; case 'callBack_forGetJBei': console.log('zh:callBack_forGetJBei ');//点击了奖杯 GlobalManager.instance.callMethod('callBack_forGetJBei'); break; case 'callBack_gotoNextLevel': console.log('zh:callBack_gotoNextLevel ');// GlobalManager.instance.callMethod('callBack_gotoNextLevel'); break; case 'callBackFor_kaoJiao': console.log('zh:callBackFor_kaoJiao ');// var yxAdMark_index = cc.sys.localStorage.getItem("yxAdMark_index"); GlobalManager.instance.callMethod('callBackFor_kaoJiao', yxAdMark_index); cc.sys.localStorage.delete(yxAdMark_index); break; case 'callBack_for_tiLiAd': console.log('zh:callBack_for_tiLiAd ');//体力不足 GlobalManager.instance.callMethod('callBack_for_tiLiAd'); break; default: console.log('zh:未知的道具类型AD==' + yxAdMark) } cc.sys.localStorage.setItem(this.adKey, ''); cc.sys.localStorage.setItem(adKeyTemp, ''); console.log('zh:清理adKey ') } initAd() { if (cc.sys.os != cc.sys.OS_ANDROID) { return; } //let adKey = "zh_ad_type" cc.sys.localStorage.setItem(this.adKey, ""); let placementId = AAJS2.getPlacementId(); let deviceId = AAJS2.getDeviceUserId(); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; ATRewardedVideoSDK.loadRewardedVideo(placementId, setting); //console.log('zh:bbb222') var customPlacementId = ""; if (cc.sys.os === cc.sys.OS_IOS) { customPlacementId = placementId; } else if (cc.sys.os === cc.sys.OS_ANDROID) { customPlacementId = placementId; } // 初始化SDK // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//正式的,发布提交go0gle play // ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告 // ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的 ATSDK.initSDK("h67161678d3fcf", "aa0e53109399d0c3a213140e896bdac07");//正式的整理大师 // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//货柜1 正式的,发布提交go0gle play ATSDK.setLogDebug(true);//zh:diy var GDPRLevel = ATSDK.getGDPRLevel(); // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。 ATSDK.getUserLocation(function (userLocation) { //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗 if (userLocation === ATSDK.kATUserLocationInEU) { if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) { ATSDK.showGDPRAuth(); } } }); ATRewardedVideoSDK.setAdListener(this); if (cc.sys.os === cc.sys.OS_ANDROID) { setTimeout(() => { var allInfo = AAJS2.allInfo(); ATSDK.printLog("zh:allInfo=" + allInfo); let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@"; let iv = "Jn0.aWsOu$y-Dbqb"; let data = { data: AESUtil.AESencrypt(allInfo, key, iv) }; ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data)); console.log('zh:ad_allInfo', data); AAJS2.makePostRequestWithXhr(JSON.stringify(data)); }, 200); } } initAdForPage() { if (cc.sys.os === cc.sys.OS_ANDROID) { let deviceId = AAJS2.getDeviceUserId(); console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId())); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting); } } start() { this.startGameBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this); this.setNormalBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this); this.btnLeft.node.on(cc.Node.EventType.TOUCH_END, this.ClickLeft, this); this.btnRight.node.on(cc.Node.EventType.TOUCH_END, this.ClickRight, this); // this.btnVideo.node.on(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this); this.missionBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this); // this.chooseSkinBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this); // this.btnShop.node.on(cc.Node.EventType.TOUCH_END, this.ClickShop, this); // console.log('----------', TimeControl.instance.currentTili); // App.DataManager.TimeCountJudge();//全局倒计时判断 // if (App.DataManager.TimeFlag) { // let data = { "isShow": true, 'timeStr': App.DataManager.TimeChange(TimeControl.instance.currentTimeCount) }; // this.TiliCountShow(data); // } this.ShowPhysicalValue(); this.ShowUserCoinValue(); this.ShowUserDiamondValue(); App.SoundManager.playBGM(SoundManager.hallBgm[0]); } public ClickOpenMission() { // this.showInterAd("callBackFor_ClickOpenMission",false, () => this.callBackFor_ClickOpenMission()); App.Facade.popView(MissionPanelMediator, MissionPanel, "打开任务界面", false); } public callBackFor_ClickOpenMission() { App.Facade.popView(MissionPanelMediator, MissionPanel, "打开任务界面", false); } /** * 体力显示设置 */ public ShowPhysicalValue(): void { console.log('############', TimeControl.instance.currentTili) if (hallScene.instance.labelTili) { hallScene.instance.labelTili.string = TimeControl.instance.currentTili + "/" + TimeControl.instance.tiliMax; } } // 显示玩家金币 public ShowUserCoinValue(): void { if (hallScene.instance.labelCoin) { hallScene.instance.labelCoin.string = App.DataManager.UserCoin.toString(); } } // 钻石 public ShowUserDiamondValue(): void { if (hallScene.instance.labelDiamond) { hallScene.instance.labelDiamond.string = App.DataManager.UserDiamond.toString(); } } /** * 体力倒计时显示设置 */ public TiliCountShow(data: any): void { if (!this.physicalTime) return; this.physicalTime.node.active = data.isShow; if (data.timeStr) this.physicalTime.string = data.timeStr; } /** * 开始游戏 */ public StartGame_111(intoLevel: number) { console.log("aaa-大是大非-------intoLevel----------", intoLevel); App.DataManager.UpdateTili(TimeControl.instance.consumeTili, (success) => { App.DataManager.CurrentIntoLevel = intoLevel; App.DataManager.PlayLevel = App.DataManager.CurrentIntoLevel; App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_playLevel, App.DataManager.PlayLevel); if (success) App.Facade.runBundleScene("gameScene", this.loadSceneName); else App.Facade.popView(InsufficientPanelMediator, InsufficientPanel, "1体力不足", false); }); } /** * 开始游戏 */ public StartGame(intoLevel: number) { console.log("aaa-大是大非-------intoLevel----------", intoLevel); App.DataManager.UpdateTili(TimeControl.instance.consumeTili, (success) => { // 更新当前进入的关卡和播放关卡 App.DataManager.CurrentIntoLevel = intoLevel; App.DataManager.PlayLevel = App.DataManager.CurrentIntoLevel; // 保存当前播放关卡到本地存储 App.LocalStorageUtil.setNumber( App.LocalStorageUtil.lst_playLevel, App.DataManager.PlayLevel ); // 根据体力更新结果跳转场景或提示 if (success) { console.log("2"); App.Facade.runBundleScene("gameScene", this.loadSceneName); } else { console.log("1"); App.Facade.popView( InsufficientPanelMediator, InsufficientPanel, "体力不足", false ); } }); } /** * 点击开始游戏按钮直接开始 */ private ClickStartGame() { if (this.pageView.getCurrentPageIndex() == 1) { App.Facade.popView(TipPanelMediator, TipPanel, "coming soon!", false); } else { App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", false); } } /** * 点击观看视频加体力 */ private ClickAddTili() { console.log('点击观看视频加体力~'); SoundManager.getInstance().VideoStartStop(); SDK.Instance.showRewardVideo(() => { TimeControl.instance.currentTili = TimeControl.instance.tiliMax; this.ShowPhysicalValue(); App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Tili, TimeControl.instance.currentTili); SoundManager.getInstance().VideoEndOpen(); }, () => { SoundManager.getInstance().VideoEndOpen(); }, () => { SoundManager.getInstance().VideoEndOpen(); }); } // 商城 private ClickShop() { App.Facade.popView(ShopPanelMediator, ShopPanel, "商城", false); } /** * 打开关卡选择界面 */ private ClickChooseLevel() { App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", true); App.Facade.popView(TipPanelMediator, TipPanel, "aasdasdf", false); } /** * 打开选择皮肤界面 */ private ClickChooseSkin() { App.Facade.popView(ChooseSkinPanelMediator, ChooseSkinPanel, "皮肤选择", false); } /** * 打开设置界面 */ private ClickSetNormal() { App.Facade.popView(SetNormalPanelMediator, SetNormalPanel, "设置", false); } private ClickLeft() { this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0; this.pageView.scrollToPage(this.currientView, 0.5); } private ClickRight() { this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0; this.pageView.scrollToPage(this.currientView, 0.5); } onDisable() { this.startGameBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this); this.setNormalBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this); this.btnLeft.node.off(cc.Node.EventType.TOUCH_END, this.ClickLeft, this); this.btnRight.node.off(cc.Node.EventType.TOUCH_END, this.ClickRight, this); this.missionBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this); // this.btnVideo.node.off(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this); // this.btnShop.node.off(cc.Node.EventType.TOUCH_END, this.ClickShop, this); // this.chooseSkinBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this); } // update (dt) {} onRewardedVideoAdLoaded(placementId: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")"); } onRewardedVideoAdFailed(placementId: any, errorInfo: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")"); } onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")"); let deviceId = AAJS2.getDeviceUserId(); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting); } onRewardedVideoAdPlayEnd(placementId: any, callbackInfo: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")"); console.log('zh: ad PlayEnd') //this.node.emit("handleCustomEvent"); } onRewardedVideoAdPlayFailed(placementId: any, errorInfo: any, callbackInfo: any): void { ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")"); } onRewardedVideoAdClosed(placementId: any, callbackInfo: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::AdClosed(" + placementId + ", " + callbackInfo + ")"); if (this.adState == true) { this.adState = false; console.log('zh: ad奖励OK,开始处理奖励') this.handleCustomEvent() } else { console.log('zh: ad奖励标识 NO OK ') } } onRewardedVideoAdPlayClicked(placementId: any, callbackInfo: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")"); } onReward(placementId: any, callbackInfo: any): void { ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")"); console.log('zh:onReward AD奖励标志OK') this.adState = true; } //#region 插屏广告 /** * 显示插屏广告 * * @param adMarkForClose 插屏广告关闭后调用那个方法的具体指示标识 * @param checkClose 是否需要判断关闭事件,有的不需要,如果AD占用游戏时间则为true * @param callback 插屏广告关闭(加载失败\非ANDROID平台)的回调 */ private showInterAd(adMarkForClose: string, checkClose: boolean, callback: () => void) { if (cc.sys.os === cc.sys.OS_ANDROID) { cc.sys.localStorage.setItem("adMarkForClose", adMarkForClose);//关闭后,调用哪个方法的标识 //add判断插屏 开屏等 let pid_inter = AAJS2.getPlacementId2(AdType.Inter); let boo = ATInterstitialSDK.hasAdReady(pid_inter); if (boo) { // 暂停游戏 cc.director.pause(); console.log('zh:showInterAd AD OK'); ATInterstitialSDK.showAd(pid_inter); //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效 if (!checkClose) {//如果不占用游戏时间 callback(); } } else { console.log('zh:showInterAd AD 没有准备好'); //GlobalManager.getInstance().callMethod('initAdForPageInter'); this.initAdForPageInter(); callback(); } } else { callback(); } } //add判断插屏 开屏等,需要多次准备 //add判断插屏 开屏等,需要多次准备 initAdForPageInter() { if (cc.sys.os === cc.sys.OS_ANDROID) { console.log('zh:skillBox.ts 开始准备AD .....'); let deviceId = AAJS2.getDeviceUserId(); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; //add判断插屏 开屏等 let pid_inter = AAJS2.getPlacementId2(AdType.Inter); console.log("zh: pid_inter checkstatus:", ATInterstitialSDK.checkAdStatus(pid_inter)); ATInterstitialSDK.loadInterstitial(pid_inter, setting); } } initAdPageForBanner() { //v5.6.8新增 var setting = {}; let deviceId = AAJS2.getDeviceUserId(); setting[ATRewardedVideoSDK.userIdKey] = deviceId; // let fsw =screen.windowSize.width; // let fsw = cc.view.getFrameSize().width let fsw = cc.view.getFrameSize().width; setting[ATBannerSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerSDK.createLoadAdSize(fsw, 150); //只针对Admob的自适应banner setting[ATBannerSDK.kATBannerAdAdaptiveWidth] = fsw; setting[ATBannerSDK.kATBannerAdAdaptiveOrientation] = ATBannerSDK.kATBannerAdAdaptiveOrientationCurrent; // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationPortrait; // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationLandscape; var pid = AAJS2.getPlacementId2(AdType.Banner); ATBannerSDK.loadBanner(pid, setting); var bannerListener = { //广告加载成功 onBannerAdLoaded: function (placementId) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdLoaded(" + placementId + ")"); }, //广告加载失败 onBannerAdLoadFail: function (placementId, errorInfo) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdLoadFail(" + placementId + ", " + errorInfo + ")"); this.initAdPageForBanner(); }, //广告展示成功 onBannerAdShow: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdShow(" + placementId + ", " + callbackInfo + ")"); }, //广告被点击 onBannerAdClick: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdClick(" + placementId + ", " + callbackInfo + ")"); }, //广告自动刷新成功 onBannerAdAutoRefresh: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefresh(" + placementId + ", " + callbackInfo + ")"); }, //广告自动刷新失败 onBannerAdAutoRefreshFail: function (placementId, errorInfo) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefreshFail(" + placementId + ", " + errorInfo + ")"); }, //广告关闭按钮被点击 onBannerAdCloseButtonTapped: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkBannerDemo::onBannerAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")"); this.initAdPageForBanner(); } }; ATBannerSDK.setAdListener(bannerListener); console.log("zh:initAdPageForBanner listener over ..... "); } initAdInster() { let adKey = "adMarkForClose" cc.sys.localStorage.setItem(adKey, ""); let deviceId = AAJS2.getDeviceUserId(); var setting = {}; setting[ATRewardedVideoSDK.userIdKey] = deviceId; var pid = AAJS2.getPlacementId2(AdType.Inter); let placementId = pid; setting[ATInterstitialSDK.UseRewardedVideoAsInterstitial] = false;//UseRewardedVideoAsInterstitial //setting[ATInterstitialJSSDK.UseRewardedVideoAsInterstitial] = true; ATInterstitialSDK.loadInterstitial(pid, setting); //v5.6.8以下 //ATInterstitialSDK.loadInterstitial(pid); let that = this; var interstitialListener = { //广告加载成功 onInterstitialAdLoaded: function (placementId) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoaded(" + placementId + ")"); }, //广告加载失败 onInterstitialAdLoadFail: function (placementId, errorInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoadFail(" + placementId + ", " + errorInfo + ")"); }, //广告展示成功 onInterstitialAdShow: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdShow(" + placementId + ", " + callbackInfo + ")"); setTimeout(() => { that.initAdForPageInter(); }, 500); }, //广告视频开始播放,部分平台有此回调 onInterstitialAdStartPlayingVideo: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdStartPlayingVideo(" + placementId + ", " + callbackInfo + ")"); }, //广告视频播放结束,部分广告平台有此回调 onInterstitialAdEndPlayingVideo: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdEndPlayingVideo(" + placementId + ", " + callbackInfo + ")"); }, //广告视频播放失败,部分广告平台有此回调 onInterstitialAdFailedToPlayVideo: function (placementId, errorInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdFailedToPlayVideo(" + placementId + ", " + errorInfo + ")"); }, //广告展示失败 onInterstitialAdFailedToShow: function (placementId) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdFailedToShow(" + placementId + ")"); }, //广告被关闭 onInterstitialAdClose: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdClose(" + placementId + ", " + callbackInfo + ")"); //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效 that.handleCustomEventForInter(); }, //广告被点击 onInterstitialAdClick: function (placementId, callbackInfo) { ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdClick(" + placementId + ", " + callbackInfo + ")"); } }; ATInterstitialSDK.setAdListener(interstitialListener);//插屏广告 } /** * AD播放完毕的事件处理,插屏处理 */ handleCustomEventForInter() { let that = this; console.log('zh:00收到发送的事件handleCustomEventForInter') let mark = cc.sys.localStorage.getItem("adMarkForClose"); console.log('zh:handleCustomEventForInter mark =' + mark) switch (mark) { case 'callBack_gotoNextLevel':// console.log('zh:点击了点击了超市') // 调用A页面的方法 // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2'); GlobalManager.instance.callMethod('callBack_gotoNextLevel'); break; case 'xxxxxx2222'://开始游戏 //发送事件。。。。todo: 重新开始游戏 //this.node.emit('env_playAdEnd', 'Hello,你好'); // 调用A页面的方法 // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2'); // GlobalManager.instance.callMethod('startGameForFailAD'); break; default: console.log('zh:未知的inster类型AD' + mark) } } //#endregion }