123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- /*
- * @Author: your name
- * @Date: 2021-09-12 12:41:49
- * @LastEditTime: 2021-09-29 22:30:24
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: \zombiefood\assets\script\ui\uiview\Interface\UIMenu.ts
- */
- import auto_menu from "../../../ui/uidata/Interface/auto_menu";
- import UIBase from "../../../framework/ui/UIBase";
- import UIHelp from "../../../framework/ui/UIHelp";
- import bundleManager from "../../../manager/bundleManager";
- import levelManager from "../../../manager/levelManager";
- import AccountModel from "../../../data/Account/AccountModel";
- import zombieActionMgr from "../../../manager/zombieActionMgr";
- import Utils from "../../../framework/utils/utils";
- import UITopMenu from "./UITopMenu";
- import { EVENT_TYPE } from "../../../gameLogic/utrl/gameEnum";
- import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
- import JoyStick from "../../../gameLogic/utrl/joy_stick";
- import AudioManager from "../../../framework/music/AudioManager";
- import UIWelfareView from "./UIWelfareView";
- import SignUtil from "../../../framework/utils/signUtil";
- import UISignView from "./UISignView";
- import UIGameScene from "../scene/UIGameScene";
- import { SingletonFactory } from "../../../framework/utils/SingletonFactory";
- import EventManager from "../../../framework/event/EventManager";
- import dynamicAtlasManager = cc.dynamicAtlasManager;
- import UICrazyAwardView from "./UICrazyAwardView";
- import { GameEvent } from "../../../constant/constant-game";
- import { USER } from "../../../constant/constant-user";
- import { Log, LOG_TAG } from "../../../framework/log/Log";
- import array = cc.js.array;
- import UIMng from "../../../framework/ui/UIMng";
- import AESUtil from "../../../AESUtil"
- import ATSDK from "../../../AnyThinkAds/ATJSSDK";
- import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK";
- import ATInterstitialSDK from "../../../AnyThinkAds/ATInterstitialJSSDK";
- import ATBannerJSSDK from "../../../AnyThinkAds/ATBannerJSSDK";
- import { AdType } from '../../../ATAndroidJS2';
- import AAJS2 from "../../../ATAndroidJS2";
- import GlobalManager from '../../../GlobalManager';
- const { ccclass, menu, property } = cc._decorator;
- @ccclass
- @menu("UI/Interface/UIMenu")
- export default class UIMenu extends UIBase implements AdDeveloperCallback {
-
- onRewardedVideoAdLoaded(placementId: any): void {
- ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
- }
- onRewardedVideoAdFailed(placementId: any, errorInfo: any): void {
- ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
- }
- onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void {
- ATSDK.printLog("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("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
- //console.log('zh: ad over 开始发送事件11 start')
- //this.handleCustomEvent()
- //console.log('zh: ad over 开始发送事件11 OVER')
- }
- 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::onRewardedVideoAdClosed(" + 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("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;
-
- }
- /**
- * AD播放完毕的事件处理
- */
- handleCustomEvent() {
- console.log('zh:00收到发送的事件')
- let adKey = "zh_ad_type"
- let idx = cc.sys.localStorage.getItem(adKey);//0,1,2,3
- console.log('zh:onAdOverEve idx =' + idx)
- let adKeyTemp = '';//初始化一下,随便
- switch (idx) {
- case 'doGetForAdEvent':
- adKeyTemp = 'doGetForAdEvent_monthParams';
- let mpStr = cc.sys.localStorage.getItem(adKeyTemp);
- let mpJosn = JSON.parse(mpStr);
- console.log('zh:#############幸存者 奖励')
- GlobalManager.getInstance().callMethod('doGetForAdEvent', mpJosn.result, mpJosn.type);
- break;
- case 'doSearchForAdEvent':
- console.log('zh:#############商店搜集 奖励')
- GlobalManager.getInstance().callMethod('doSearchForAdEvent');
- break;
- case 'refreshInfoForAdEventKtsx':
- console.log('zh:#############呼叫空投-刷新物品 奖励')
- GlobalManager.getInstance().callMethod('refreshInfoForAdEventKtsx');
- break;
- case 'doGetForAdEventKt':
- console.log('zh:#############呼叫空投-获取物品 奖励')
- GlobalManager.getInstance().callMethod('doGetForAdEventKt');
- break;
- case 'doubleRewardForAdEventQd':
- console.log('zh:#############签到奖励 奖励')
- GlobalManager.getInstance().callMethod('doubleRewardForAdEventQd');
- break;
- case 'sendBtnEventForAdEventFuHuo'://复活
- adKeyTemp = 'sendBtnEventForAdEventFuHuo_monthParams';
- let mpStr2 = cc.sys.localStorage.getItem(adKeyTemp);
- console.log('zh:#############复活 奖励',mpStr2)
- GlobalManager.getInstance().callMethod('sendBtnEventForAdEventFuHuo',mpStr2);
- break;
- default:
- console.log('zh:未知的道具类型AD' + idx)
- }
- cc.sys.localStorage.setItem(adKey, '');
- cc.sys.localStorage.setItem(adKeyTemp, '');
- console.log('zh:清理adKey ')
- }
- adState:boolean = false;
- adKey: string = "zh_ad_type";
- ui: auto_menu = null;
- protected static prefabUrl = "Interface/menu";
- protected static className = "UIMenu";
- npcID: number;
- roleSpine: any;
- isLoadRes: boolean = false;
- bClick: boolean = true;
- progressBar: cc.ProgressBar;
- onUILoad() {
- this.ui = this.node.addComponent(auto_menu);
- this.isNewUser();
- this.progressBar = this.ui.progress.getComponent(cc.ProgressBar);
- zjSdk?.showMain({
- y: -50,
- });
- bundleManager.loadSimpleSubpk('level3', () => {
- bundleManager.loadSimpleSubpk('level4');
- });
- this.initAd();
- this.initAdInster();
- this.initAdForPageInter();
- GlobalManager.getInstance().registerMethod('initAdForPageInter', this.initAdForPageInter.bind(this));
- this.initAdPageForBanner();
- setTimeout(() => {
- this.showBannerAd();
- }, 100);
- }
- private showOrHidenBannerAd(boo:boolean) {
- var pid = AAJS2.getPlacementId2(AdType.Banner);
- if(boo){
- ATBannerJSSDK.reShowAd(pid);
- }else{
- ATBannerJSSDK.hideAd(pid);
- }
-
- }
- private showBannerAd() {
- var pid = AAJS2.getPlacementId2(AdType.Banner);
- let boo = ATBannerJSSDK.hasAdReady(pid);
- // ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop);
- ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.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 没有准备好')
- }
- }
- initAd() {
- let adKey = "zh_ad_type"
- cc.sys.localStorage.setItem(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("h67626c3be8ac7", "a4efc7bc00a02e895ce1b09c3f55a85b2");//正式的,发布提交go0gle play
- //ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
- //ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
- //ATSDK.initSDK("h67161678d3fcf", "aa0e53109399d0c3a213140e896bdac07");//这是 QuickScrews 的已经上架的
- 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);
- }
- }
- isNewUser() {
- let playerDt = AccountModel.getInstance().playerDtList;
- if (playerDt.length > 0) {
- AccountModel.getInstance().is_new = 0;
- }
- if (AccountModel.getInstance().is_new == 1) {
- zjSdk?.sendEvent('主界面曝光-新')
- } else {
- zjSdk?.sendEvent('主界面曝光-旧')
- }
- }
- start_btn() {
- this.showOrHidenBannerAd(false);
- if (!this.bClick) { return };
- if (!this.bloadRes()) {
- UIHelp.ShowTips('Loading resources...');//资源加载中......
- return;
- }
- this.bClick = false;
- zjSdk?.sendEvent('点击开始按钮');
- console.log('zh:1')
- zjSdk?.gameBegin(() => {
- console.log('zh:2')
- zjSdk?.hideMain();
- if (zjSdk?.hasOwnProperty('ZjGmData')) {
- if (zjSdk?.ZjGmData.instance.gameConfig.isShowInnerCrazyAward == '1') {
- GameEvent.isShowInnerCrazyAward = true;
- }
- if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('firstCrazyByZombieNum')) {
- GameEvent.firstCrazyByZombieNum = parseInt(zjSdk?.ZjGmData.instance.gameConfig.firstCrazyByZombieNum)
- }
- if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyByZombieNumTimes')) {
- GameEvent.crazyByZombieNumTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyByZombieNumTimes)
- } if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyAwardPopMaxTimes')) {
- GameEvent.crazyAwardPopMaxTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyAwardPopMaxTimes)
- }
- }
- console.log('zh:3')
- let curLevel = AccountModel.getInstance().curLevel;
- if (curLevel == 1 && AccountModel.getInstance().is_new == 1) {
- console.log('zh:4')
- this.onClose();
- gameEventManager.emit(EVENT_TYPE.playStoryAni, (node) => {
- console.log('zh:5')
- levelManager.open(curLevel, () => {
- cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0;
- UITopMenu.getInstance().node.active = true;
- this.tryShowUI();
- node.destroy();
- })
- });
- return;
- }
- console.log('zh:6')
- levelManager.open(curLevel, () => {
- console.log('zh:7')
- cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0;
- UITopMenu.getInstance().node.active = true;
- this.onClose();
- this.tryShowUI(false);
- console.log('zh:8')
- })
- })
- }
- tryShowUI(isNewBee = true) {
-
- //调用签到
- const callSign = () => {
- if (!SignUtil.canSign()) {
- return false;
- }
- const openSign = () => {
- if (SignUtil.canSign()) {
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
- UIHelp.ShowUI(UISignView, null, isNewBee);
- }
- }
- uiRoot.getComponent(UIGameScene).scheduleOnce(async () => {
- if (UIMng.getInstance().UILock) {
- EventManager.once(EVENT_TYPE.unLockUI, () => {
- this.scheduleOnce(() => {
- if (SignUtil.canSign()) {
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
- UIHelp.ShowUI(UISignView, null, isNewBee);
- }
- }, 1)
- })
- }
- openSign();
- }, isNewBee ? 30 : 0);
- return true;
- }
- //调用福利
- const callWelfare = (delay) => {
- const openWelfare = () => {
- if (isNewBee &&
- AccountModel.getInstance().curWelfare.length != 0) {
- return
- }
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
- UIHelp.ShowUI(UIWelfareView, null, isNewBee);
- }
- if (AccountModel.getInstance().curWelfare.length !== 4) {
- uiRoot.getComponent(UIGameScene).scheduleOnce(() => {
- if (UIMng.getInstance().UILock) {
- EventManager.once(EVENT_TYPE.unLockUI, () => {
- this.scheduleOnce(() => {
- openWelfare();
- }, 1)
- })
- return;
- }
- //新手点击过不要跳了
- openWelfare();
- }, delay);
- }
- };
- let uiRoot = cc.director.getScene().getChildByName('Canvas');
- const isShowSign = callSign();
- //新手
- if (isNewBee) {
- EventManager.once(EVENT_TYPE.closeSign, () => {
- callWelfare(30);
- })
- } else if (isShowSign) {
- EventManager.once(EVENT_TYPE.closeSign, () => {
- callWelfare(0);
- })
- } else {
- callWelfare(0);
- }
- }
- bloadRes() {
- if (bundleManager.localResIsload == true && bundleManager.getBunleTotal() == bundleManager.bundleTotal) {
- return true;
- }
- return false;
- }
- update(dt) {
- if (this.bloadRes() && !this.isLoadRes) {
- this.node.$loading_lb.getComponent(cc.Label).string = 'loading completed';
- this.progressBar.progress = 1;
- this.scheduleOnce(() => {
- this.ui.progress.active = false;
- this.node.$loading_lb.active = false;
- this.ui.start_btn.active = true;
- }, 0.2)
- this.isLoadRes = true;
- this.addSprite();
- setTimeout(() => {
- AudioManager.play('bg', 1, true, 'BGM');
- }, 50);
- levelManager.preLoadLevel(AccountModel.getInstance().curLevel);
- }
- if (!this.bloadRes()) {
- this.node.$loading_lb.getComponent(cc.Label).string = 'loading......';
- if (this.progressBar.progress < 1) {
- this.progressBar.progress += dt * 0.5;
- }
- }
- }
- addSprite() {
- this.initRedWarn();
- }
- initRedWarn() {
- let redWarn = new cc.Node;
- redWarn.name = "redWarn";
- redWarn.setContentSize(cc.size(1800, 2000));
- redWarn.addComponent(cc.Sprite);
- bundleManager.setBundleFrame('UI', 'main/hjianbianBG', redWarn);
- redWarn.active = false;
- redWarn.parent = cc.director.getScene().getChildByName('Canvas');
- cc.tween(redWarn)
- .repeatForever(cc.tween().to(0.5, { opacity: 0 }).to(0.5, { opacity: 255 }))
- .start();
- }
- onClose() {
- UIHelp.CloseUI(UIMenu);
- }
-
- initAdInster() {
- let adKey = "zh_ad_type"
- 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;
- //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 + ")");
-
- setTimeout(() => {
- that.initAdForPageInter();
- }, 500);
- },
- //广告加载失败
- onInterstitialAdLoadFail: function (placementId, errorInfo) {
- ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoadFail(" + placementId + ", " + errorInfo + ")");
- setTimeout(() => {
- that.initAdForPageInter();
- }, 500);
- },
- //广告展示成功
- onInterstitialAdShow: function (placementId, callbackInfo) {
-
- ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdShow(" + placementId + ", " + callbackInfo + ")");
- },
- //广告视频开始播放,部分平台有此回调
- 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);//插屏广告
- }
-
- //add判断插屏 开屏等,需要多次准备
- initAdForPageInter() {
- if (cc.sys.os === cc.sys.OS_ANDROID) {
- console.log('zh:initAdForPageInter 开始准备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;
- setting[ATBannerJSSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerJSSDK.createLoadAdSize(cc.view.getFrameSize().width, 200);
- //只针对Admob的自适应banner
- setting[ATBannerJSSDK.kATBannerAdAdaptiveWidth] = cc.view.getFrameSize().width;
- setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationCurrent;
- // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationPortrait;
- // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationLandscape;
- var pid = AAJS2.getPlacementId2(AdType.Banner);
- ATBannerJSSDK.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();
- }
- };
- ATBannerJSSDK.setAdListener(bannerListener);
- console.log("zh:initAdPageForBanner listener over ..... ");
- }
- /**
- * 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 'callBackForClickShop'://点击了超市
- console.log('zh:点击了超市')
- // 调用A页面的方法
- // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
- // GlobalManager.getInstance().callMethod('callBackForClickShop');
-
- 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)
- }
- }
- }
|