hallScene.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. import { BaseView } from "../lightMVC/core/base/BaseView";
  2. import SDK from "./sdk/SDK";
  3. import hallSceneMediator from "./hallSceneMediator";
  4. import { App } from "./Manager/App";
  5. import { SoundManager } from "./Manager/SoundManager";
  6. import TimeControl from "./TimeControl";
  7. import ChooseLevelPanel from "./view/chooseLevel/ChooseLevelPanel";
  8. import ChooseLevelPanelMediator from "./view/chooseLevel/ChooseLevelPanelMediator";
  9. import ChooseSkinPanel from "./view/chooseSkin/ChooseSkinPanel";
  10. import ChooseSkinPanelMediator from "./view/chooseSkin/ChooseSkinPanelMediator";
  11. import InsufficientPanel from "./view/insufficientPanel/InsufficientPanel";
  12. import InsufficientPanelMediator from "./view/insufficientPanel/InsufficientPanelMediator";
  13. import MissionPanel from "./view/missionPanel/MissionPanel";
  14. import MissionPanelMediator from "./view/missionPanel/MissionPanelMediator";
  15. import SetNormalPanel from "./view/setNormal/SetNormalPanel";
  16. import SetNormalPanelMediator from "./view/setNormal/SetNormalPanelMediator";
  17. import ShopPanel from "./view/shopView/ShopPanel";
  18. import ShopPanelMediator from "./view/shopView/ShopPanelMediator";
  19. import TipPanel from "./view/tipPanel/TipPanel";
  20. import TipPanelMediator from "./view/tipPanel/TipPanelMediator";
  21. import AESUtil from "./AESUtil"
  22. import ATSDK from "./AnyThinkAds/ATJSSDK";
  23. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoJSSDK";
  24. import AAJS2 from "./ATAndroidJS2";
  25. import GlobalManager from './GlobalManager';
  26. import ATInterstitialSDK from "./AnyThinkAds/ATInterstitialJSSDK";
  27. import ATBannerSDK from "./AnyThinkAds/ATBannerJSSDK";
  28. import { AdType } from './ATAndroidJS2';
  29. const Tag: string = 'zh:UIGame';
  30. const { ccclass, property } = cc._decorator;
  31. @ccclass
  32. export default class hallScene extends BaseView {
  33. public static _instance;
  34. @property(cc.Button)
  35. public startGameBtn: cc.Button = null;
  36. @property(cc.Button)
  37. public setNormalBtn: cc.Button = null;
  38. // @property(cc.Button)
  39. // public chooseSkinBtn: cc.Button = null;
  40. @property(cc.Button)
  41. public missionBtn: cc.Button = null;
  42. // @property(cc.Button)
  43. // public btnVideo: cc.Button = null;
  44. // @property(cc.Button)
  45. // public btnShop: cc.Button = null;
  46. @property(cc.Button)
  47. public btnLeft: cc.Button = null;
  48. @property(cc.Button)
  49. public btnRight: cc.Button = null;
  50. @property(cc.PageView)
  51. public pageView: cc.PageView = null;
  52. @property(cc.Label)
  53. public labelTili: cc.Label = null;
  54. @property(cc.Label)
  55. public physicalTime: cc.Label = null;
  56. @property(cc.Label)
  57. public labelCoin: cc.Label = null;
  58. @property(cc.Label)
  59. public labelDiamond: cc.Label = null;
  60. private loadSceneName: string = "gameScene";
  61. private currientView = 0;
  62. adState: boolean = false;
  63. adKey: string = "zh_ad_type";
  64. public static get instance() {
  65. return hallScene._instance;
  66. }
  67. public static set instance(value) {
  68. hallScene._instance = value;
  69. }
  70. onLoad() {
  71. // cc.sys.localStorage.clear();
  72. hallScene.instance = this;
  73. this.registerMediator(hallSceneMediator, this, "主界面");
  74. SDK.Instance.showBanner();
  75. this.initAd();
  76. this.initAdForPage();
  77. //GlobalManager.getInstance().registerMethod('initAdForPageInter', this.initAdForPageInter.bind(this));
  78. this.initAdPageForBanner();
  79. setTimeout(() => {
  80. this.showBannerAd();
  81. }, 100);
  82. this.initAdInster();
  83. }
  84. private showOrHidenBannerAd(boo: boolean) {
  85. var pid = AAJS2.getPlacementId2(AdType.Banner);
  86. if (boo) {
  87. ATBannerSDK.reShowAd(pid);
  88. } else {
  89. ATBannerSDK.hideAd(pid);
  90. }
  91. }
  92. private showBannerAd() {
  93. var pid = AAJS2.getPlacementId2(AdType.Banner);
  94. let boo = ATBannerSDK.hasAdReady(pid);
  95. // ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop);
  96. ATBannerSDK.showAdInPosition(pid, ATBannerSDK.kATBannerAdShowingPositionBottom);
  97. if (boo) {
  98. console.log('zh:showBannerAd AD OK SHOW....')
  99. //ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionBottom);
  100. //ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop);
  101. } else {
  102. console.log('zh:showBannerAd AD 没有准备好')
  103. }
  104. }
  105. /**
  106. * AD播放完毕的事件处理
  107. */
  108. handleCustomEvent() {
  109. console.log('zh:00收到发送的事件')
  110. //let adKey = "zh_ad_type"
  111. let yxAdMark = cc.sys.localStorage.getItem("yxAdMark");
  112. console.log('zh:onAdOverEve yxAdMarkAAAA =' + yxAdMark)
  113. let adKeyTemp = '';//初始化一下,随便
  114. switch (yxAdMark) {
  115. case 'callBack_btnReplay'://失败了重新尝试
  116. console.log('zh:callBack_btnReplay ')
  117. GlobalManager.instance.callMethod('callBack_btnReplay');
  118. break;
  119. case 'callBack_for_chouJiang'://抽奖callBack_for_chouJiang
  120. console.log('zh:callBack_for_chouJiang ')
  121. GlobalManager.instance.callMethod('callBack_for_chouJiang');
  122. break;
  123. case 'callBackFor_successPanel'://成功的时候奖
  124. console.log('zh:callBackFor_successPanel ')
  125. GlobalManager.instance.callMethod('callBackFor_successPanel');
  126. break;
  127. case 'callBack_forGetJBei':
  128. console.log('zh:callBack_forGetJBei ');//点击了奖杯
  129. GlobalManager.instance.callMethod('callBack_forGetJBei');
  130. break;
  131. case 'callBack_gotoNextLevel':
  132. console.log('zh:callBack_gotoNextLevel ');//
  133. GlobalManager.instance.callMethod('callBack_gotoNextLevel');
  134. break;
  135. case 'callBackFor_kaoJiao':
  136. console.log('zh:callBackFor_kaoJiao ');//
  137. var yxAdMark_index = cc.sys.localStorage.getItem("yxAdMark_index");
  138. GlobalManager.instance.callMethod('callBackFor_kaoJiao', yxAdMark_index);
  139. cc.sys.localStorage.delete(yxAdMark_index);
  140. break;
  141. case 'callBack_for_tiLiAd':
  142. console.log('zh:callBack_for_tiLiAd ');//体力不足
  143. GlobalManager.instance.callMethod('callBack_for_tiLiAd');
  144. break;
  145. default:
  146. console.log('zh:未知的道具类型AD==' + yxAdMark)
  147. }
  148. cc.sys.localStorage.setItem(this.adKey, '');
  149. cc.sys.localStorage.setItem(adKeyTemp, '');
  150. console.log('zh:清理adKey ')
  151. }
  152. initAd() {
  153. if (cc.sys.os != cc.sys.OS_ANDROID) {
  154. return;
  155. }
  156. //let adKey = "zh_ad_type"
  157. cc.sys.localStorage.setItem(this.adKey, "");
  158. let placementId = AAJS2.getPlacementId();
  159. let deviceId = AAJS2.getDeviceUserId();
  160. var setting = {};
  161. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  162. ATRewardedVideoSDK.loadRewardedVideo(placementId, setting);
  163. //console.log('zh:bbb222')
  164. var customPlacementId = "";
  165. if (cc.sys.os === cc.sys.OS_IOS) {
  166. customPlacementId = placementId;
  167. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  168. customPlacementId = placementId;
  169. }
  170. // 初始化SDK
  171. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//正式的,发布提交go0gle play
  172. // ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
  173. // ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  174. ATSDK.initSDK("h67161678d3fcf", "aa0e53109399d0c3a213140e896bdac07");//正式的整理大师
  175. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//货柜1 正式的,发布提交go0gle play
  176. ATSDK.setLogDebug(true);//zh:diy
  177. var GDPRLevel = ATSDK.getGDPRLevel();
  178. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  179. ATSDK.getUserLocation(function (userLocation) {
  180. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  181. if (userLocation === ATSDK.kATUserLocationInEU) {
  182. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  183. ATSDK.showGDPRAuth();
  184. }
  185. }
  186. });
  187. ATRewardedVideoSDK.setAdListener(this);
  188. if (cc.sys.os === cc.sys.OS_ANDROID) {
  189. setTimeout(() => {
  190. var allInfo = AAJS2.allInfo();
  191. ATSDK.printLog("zh:allInfo=" + allInfo);
  192. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  193. let iv = "Jn0.aWsOu$y-Dbqb";
  194. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  195. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  196. console.log('zh:ad_allInfo', data);
  197. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  198. }, 200);
  199. }
  200. }
  201. initAdForPage() {
  202. if (cc.sys.os === cc.sys.OS_ANDROID) {
  203. let deviceId = AAJS2.getDeviceUserId();
  204. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  205. var setting = {};
  206. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  207. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  208. }
  209. }
  210. start() {
  211. this.startGameBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this);
  212. this.setNormalBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this);
  213. this.btnLeft.node.on(cc.Node.EventType.TOUCH_END, this.ClickLeft, this);
  214. this.btnRight.node.on(cc.Node.EventType.TOUCH_END, this.ClickRight, this);
  215. // this.btnVideo.node.on(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this);
  216. this.missionBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this);
  217. // this.chooseSkinBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this);
  218. // this.btnShop.node.on(cc.Node.EventType.TOUCH_END, this.ClickShop, this);
  219. // console.log('----------', TimeControl.instance.currentTili);
  220. // App.DataManager.TimeCountJudge();//全局倒计时判断
  221. // if (App.DataManager.TimeFlag) {
  222. // let data = { "isShow": true, 'timeStr': App.DataManager.TimeChange(TimeControl.instance.currentTimeCount) };
  223. // this.TiliCountShow(data);
  224. // }
  225. this.ShowPhysicalValue();
  226. this.ShowUserCoinValue();
  227. this.ShowUserDiamondValue();
  228. App.SoundManager.playBGM(SoundManager.hallBgm[0]);
  229. }
  230. public ClickOpenMission() {
  231. // this.showInterAd("callBackFor_ClickOpenMission",false, () => this.callBackFor_ClickOpenMission());
  232. App.Facade.popView(MissionPanelMediator, MissionPanel, "打开任务界面", false);
  233. }
  234. public callBackFor_ClickOpenMission() {
  235. App.Facade.popView(MissionPanelMediator, MissionPanel, "打开任务界面", false);
  236. }
  237. /**
  238. * 体力显示设置
  239. */
  240. public ShowPhysicalValue(): void {
  241. console.log('############', TimeControl.instance.currentTili)
  242. if (hallScene.instance.labelTili) {
  243. hallScene.instance.labelTili.string = TimeControl.instance.currentTili + "/" + TimeControl.instance.tiliMax;
  244. }
  245. }
  246. // 显示玩家金币
  247. public ShowUserCoinValue(): void {
  248. if (hallScene.instance.labelCoin) {
  249. hallScene.instance.labelCoin.string = App.DataManager.UserCoin.toString();
  250. }
  251. }
  252. // 钻石
  253. public ShowUserDiamondValue(): void {
  254. if (hallScene.instance.labelDiamond) {
  255. hallScene.instance.labelDiamond.string = App.DataManager.UserDiamond.toString();
  256. }
  257. }
  258. /**
  259. * 体力倒计时显示设置
  260. */
  261. public TiliCountShow(data: any): void {
  262. if (!this.physicalTime) return;
  263. this.physicalTime.node.active = data.isShow;
  264. if (data.timeStr) this.physicalTime.string = data.timeStr;
  265. }
  266. /**
  267. * 开始游戏
  268. */
  269. public StartGame_111(intoLevel: number) {
  270. console.log("aaa-大是大非-------intoLevel----------", intoLevel);
  271. App.DataManager.UpdateTili(TimeControl.instance.consumeTili, (success) => {
  272. App.DataManager.CurrentIntoLevel = intoLevel;
  273. App.DataManager.PlayLevel = App.DataManager.CurrentIntoLevel;
  274. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_playLevel, App.DataManager.PlayLevel);
  275. if (success) App.Facade.runBundleScene("gameScene", this.loadSceneName);
  276. else App.Facade.popView(InsufficientPanelMediator, InsufficientPanel, "1体力不足", false);
  277. });
  278. }
  279. /**
  280. * 开始游戏
  281. */
  282. public StartGame(intoLevel: number) {
  283. console.log("aaa-大是大非-------intoLevel----------", intoLevel);
  284. App.DataManager.UpdateTili(TimeControl.instance.consumeTili, (success) => {
  285. // 更新当前进入的关卡和播放关卡
  286. App.DataManager.CurrentIntoLevel = intoLevel;
  287. App.DataManager.PlayLevel = App.DataManager.CurrentIntoLevel;
  288. // 保存当前播放关卡到本地存储
  289. App.LocalStorageUtil.setNumber(
  290. App.LocalStorageUtil.lst_playLevel,
  291. App.DataManager.PlayLevel
  292. );
  293. // 根据体力更新结果跳转场景或提示
  294. if (success) {
  295. console.log("2");
  296. App.Facade.runBundleScene("gameScene", this.loadSceneName);
  297. } else {
  298. console.log("1");
  299. App.Facade.popView(
  300. InsufficientPanelMediator,
  301. InsufficientPanel,
  302. "体力不足",
  303. false
  304. );
  305. }
  306. });
  307. }
  308. /**
  309. * 点击开始游戏按钮直接开始
  310. */
  311. private ClickStartGame() {
  312. if (this.pageView.getCurrentPageIndex() == 1) {
  313. App.Facade.popView(TipPanelMediator, TipPanel, "coming soon!", false);
  314. }
  315. else {
  316. App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", false);
  317. }
  318. }
  319. /**
  320. * 点击观看视频加体力
  321. */
  322. private ClickAddTili() {
  323. console.log('点击观看视频加体力~');
  324. SoundManager.getInstance().VideoStartStop();
  325. SDK.Instance.showRewardVideo(() => {
  326. TimeControl.instance.currentTili = TimeControl.instance.tiliMax;
  327. this.ShowPhysicalValue();
  328. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Tili, TimeControl.instance.currentTili);
  329. SoundManager.getInstance().VideoEndOpen();
  330. }, () => {
  331. SoundManager.getInstance().VideoEndOpen();
  332. }, () => {
  333. SoundManager.getInstance().VideoEndOpen();
  334. });
  335. }
  336. // 商城
  337. private ClickShop() {
  338. App.Facade.popView(ShopPanelMediator, ShopPanel, "商城", false);
  339. }
  340. /**
  341. * 打开关卡选择界面
  342. */
  343. private ClickChooseLevel() {
  344. App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", true);
  345. App.Facade.popView(TipPanelMediator, TipPanel, "aasdasdf", false);
  346. }
  347. /**
  348. * 打开选择皮肤界面
  349. */
  350. private ClickChooseSkin() {
  351. App.Facade.popView(ChooseSkinPanelMediator, ChooseSkinPanel, "皮肤选择", false);
  352. }
  353. /**
  354. * 打开设置界面
  355. */
  356. private ClickSetNormal() {
  357. App.Facade.popView(SetNormalPanelMediator, SetNormalPanel, "设置", false);
  358. }
  359. private ClickLeft() {
  360. this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0;
  361. this.pageView.scrollToPage(this.currientView, 0.5);
  362. }
  363. private ClickRight() {
  364. this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0;
  365. this.pageView.scrollToPage(this.currientView, 0.5);
  366. }
  367. onDisable() {
  368. this.startGameBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this);
  369. this.setNormalBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this);
  370. this.btnLeft.node.off(cc.Node.EventType.TOUCH_END, this.ClickLeft, this);
  371. this.btnRight.node.off(cc.Node.EventType.TOUCH_END, this.ClickRight, this);
  372. this.missionBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this);
  373. // this.btnVideo.node.off(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this);
  374. // this.btnShop.node.off(cc.Node.EventType.TOUCH_END, this.ClickShop, this);
  375. // this.chooseSkinBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this);
  376. }
  377. // update (dt) {}
  378. onRewardedVideoAdLoaded(placementId: any): void {
  379. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  380. }
  381. onRewardedVideoAdFailed(placementId: any, errorInfo: any): void {
  382. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  383. }
  384. onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void {
  385. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  386. let deviceId = AAJS2.getDeviceUserId();
  387. var setting = {};
  388. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  389. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  390. }
  391. onRewardedVideoAdPlayEnd(placementId: any, callbackInfo: any): void {
  392. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  393. console.log('zh: ad PlayEnd')
  394. //this.node.emit("handleCustomEvent");
  395. }
  396. onRewardedVideoAdPlayFailed(placementId: any, errorInfo: any, callbackInfo: any): void {
  397. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  398. }
  399. onRewardedVideoAdClosed(placementId: any, callbackInfo: any): void {
  400. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::AdClosed(" + placementId + ", " + callbackInfo + ")");
  401. if (this.adState == true) {
  402. this.adState = false;
  403. console.log('zh: ad奖励OK,开始处理奖励')
  404. this.handleCustomEvent()
  405. } else {
  406. console.log('zh: ad奖励标识 NO OK ')
  407. }
  408. }
  409. onRewardedVideoAdPlayClicked(placementId: any, callbackInfo: any): void {
  410. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  411. }
  412. onReward(placementId: any, callbackInfo: any): void {
  413. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  414. console.log('zh:onReward AD奖励标志OK')
  415. this.adState = true;
  416. }
  417. //#region 插屏广告
  418. /**
  419. * 显示插屏广告
  420. *
  421. * @param adMarkForClose 插屏广告关闭后调用那个方法的具体指示标识
  422. * @param checkClose 是否需要判断关闭事件,有的不需要,如果AD占用游戏时间则为true
  423. * @param callback 插屏广告关闭(加载失败\非ANDROID平台)的回调
  424. */
  425. private showInterAd(adMarkForClose: string, checkClose: boolean, callback: () => void) {
  426. if (cc.sys.os === cc.sys.OS_ANDROID) {
  427. cc.sys.localStorage.setItem("adMarkForClose", adMarkForClose);//关闭后,调用哪个方法的标识
  428. //add判断插屏 开屏等
  429. let pid_inter = AAJS2.getPlacementId2(AdType.Inter);
  430. let boo = ATInterstitialSDK.hasAdReady(pid_inter);
  431. if (boo) {
  432. // 暂停游戏
  433. cc.director.pause();
  434. console.log('zh:showInterAd AD OK');
  435. ATInterstitialSDK.showAd(pid_inter);
  436. //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效
  437. if (!checkClose) {//如果不占用游戏时间
  438. callback();
  439. }
  440. } else {
  441. console.log('zh:showInterAd AD 没有准备好');
  442. //GlobalManager.getInstance().callMethod('initAdForPageInter');
  443. this.initAdForPageInter();
  444. callback();
  445. }
  446. } else {
  447. callback();
  448. }
  449. }
  450. //add判断插屏 开屏等,需要多次准备
  451. //add判断插屏 开屏等,需要多次准备
  452. initAdForPageInter() {
  453. if (cc.sys.os === cc.sys.OS_ANDROID) {
  454. console.log('zh:skillBox.ts 开始准备AD .....');
  455. let deviceId = AAJS2.getDeviceUserId();
  456. var setting = {};
  457. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  458. //add判断插屏 开屏等
  459. let pid_inter = AAJS2.getPlacementId2(AdType.Inter);
  460. console.log("zh: pid_inter checkstatus:", ATInterstitialSDK.checkAdStatus(pid_inter));
  461. ATInterstitialSDK.loadInterstitial(pid_inter, setting);
  462. }
  463. }
  464. initAdPageForBanner() {
  465. //v5.6.8新增
  466. var setting = {};
  467. let deviceId = AAJS2.getDeviceUserId();
  468. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  469. // let fsw =screen.windowSize.width;
  470. // let fsw = cc.view.getFrameSize().width
  471. let fsw = cc.view.getFrameSize().width;
  472. setting[ATBannerSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerSDK.createLoadAdSize(fsw, 150);
  473. //只针对Admob的自适应banner
  474. setting[ATBannerSDK.kATBannerAdAdaptiveWidth] = fsw;
  475. setting[ATBannerSDK.kATBannerAdAdaptiveOrientation] = ATBannerSDK.kATBannerAdAdaptiveOrientationCurrent;
  476. // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationPortrait;
  477. // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationLandscape;
  478. var pid = AAJS2.getPlacementId2(AdType.Banner);
  479. ATBannerSDK.loadBanner(pid, setting);
  480. var bannerListener = {
  481. //广告加载成功
  482. onBannerAdLoaded: function (placementId) {
  483. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdLoaded(" + placementId + ")");
  484. },
  485. //广告加载失败
  486. onBannerAdLoadFail: function (placementId, errorInfo) {
  487. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdLoadFail(" + placementId + ", " + errorInfo + ")");
  488. this.initAdPageForBanner();
  489. },
  490. //广告展示成功
  491. onBannerAdShow: function (placementId, callbackInfo) {
  492. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdShow(" + placementId + ", " + callbackInfo + ")");
  493. },
  494. //广告被点击
  495. onBannerAdClick: function (placementId, callbackInfo) {
  496. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdClick(" + placementId + ", " + callbackInfo + ")");
  497. },
  498. //广告自动刷新成功
  499. onBannerAdAutoRefresh: function (placementId, callbackInfo) {
  500. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefresh(" + placementId + ", " + callbackInfo + ")");
  501. },
  502. //广告自动刷新失败
  503. onBannerAdAutoRefreshFail: function (placementId, errorInfo) {
  504. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefreshFail(" + placementId + ", " + errorInfo + ")");
  505. },
  506. //广告关闭按钮被点击
  507. onBannerAdCloseButtonTapped: function (placementId, callbackInfo) {
  508. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");
  509. this.initAdPageForBanner();
  510. }
  511. };
  512. ATBannerSDK.setAdListener(bannerListener);
  513. console.log("zh:initAdPageForBanner listener over ..... ");
  514. }
  515. initAdInster() {
  516. let adKey = "adMarkForClose"
  517. cc.sys.localStorage.setItem(adKey, "");
  518. let deviceId = AAJS2.getDeviceUserId();
  519. var setting = {};
  520. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  521. var pid = AAJS2.getPlacementId2(AdType.Inter);
  522. let placementId = pid;
  523. setting[ATInterstitialSDK.UseRewardedVideoAsInterstitial] = false;//UseRewardedVideoAsInterstitial
  524. //setting[ATInterstitialJSSDK.UseRewardedVideoAsInterstitial] = true;
  525. ATInterstitialSDK.loadInterstitial(pid, setting);
  526. //v5.6.8以下
  527. //ATInterstitialSDK.loadInterstitial(pid);
  528. let that = this;
  529. var interstitialListener = {
  530. //广告加载成功
  531. onInterstitialAdLoaded: function (placementId) {
  532. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoaded(" + placementId + ")");
  533. },
  534. //广告加载失败
  535. onInterstitialAdLoadFail: function (placementId, errorInfo) {
  536. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoadFail(" + placementId + ", " + errorInfo + ")");
  537. },
  538. //广告展示成功
  539. onInterstitialAdShow: function (placementId, callbackInfo) {
  540. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdShow(" + placementId + ", " + callbackInfo + ")");
  541. setTimeout(() => {
  542. that.initAdForPageInter();
  543. }, 500);
  544. },
  545. //广告视频开始播放,部分平台有此回调
  546. onInterstitialAdStartPlayingVideo: function (placementId, callbackInfo) {
  547. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdStartPlayingVideo(" + placementId + ", " + callbackInfo + ")");
  548. },
  549. //广告视频播放结束,部分广告平台有此回调
  550. onInterstitialAdEndPlayingVideo: function (placementId, callbackInfo) {
  551. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdEndPlayingVideo(" + placementId + ", " + callbackInfo + ")");
  552. },
  553. //广告视频播放失败,部分广告平台有此回调
  554. onInterstitialAdFailedToPlayVideo: function (placementId, errorInfo) {
  555. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdFailedToPlayVideo(" + placementId + ", " + errorInfo + ")");
  556. },
  557. //广告展示失败
  558. onInterstitialAdFailedToShow: function (placementId) {
  559. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdFailedToShow(" + placementId + ")");
  560. },
  561. //广告被关闭
  562. onInterstitialAdClose: function (placementId, callbackInfo) {
  563. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdClose(" + placementId + ", " + callbackInfo + ")");
  564. //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效
  565. that.handleCustomEventForInter();
  566. },
  567. //广告被点击
  568. onInterstitialAdClick: function (placementId, callbackInfo) {
  569. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdClick(" + placementId + ", " + callbackInfo + ")");
  570. }
  571. };
  572. ATInterstitialSDK.setAdListener(interstitialListener);//插屏广告
  573. }
  574. /**
  575. * AD播放完毕的事件处理,插屏处理
  576. */
  577. handleCustomEventForInter() {
  578. let that = this;
  579. console.log('zh:00收到发送的事件handleCustomEventForInter')
  580. let mark = cc.sys.localStorage.getItem("adMarkForClose");
  581. console.log('zh:handleCustomEventForInter mark =' + mark)
  582. switch (mark) {
  583. case 'callBack_gotoNextLevel'://
  584. console.log('zh:点击了点击了超市')
  585. // 调用A页面的方法
  586. // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
  587. GlobalManager.instance.callMethod('callBack_gotoNextLevel');
  588. break;
  589. case 'xxxxxx2222'://开始游戏
  590. //发送事件。。。。todo: 重新开始游戏
  591. //this.node.emit('env_playAdEnd', 'Hello,你好');
  592. // 调用A页面的方法
  593. // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
  594. // GlobalManager.instance.callMethod('startGameForFailAD');
  595. break;
  596. default:
  597. console.log('zh:未知的inster类型AD' + mark)
  598. }
  599. }
  600. //#endregion
  601. }