123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785 |
- 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
- }
|