YzCustomAdPanel.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { utils } from "./Utils";
  2. import { BannerLocation } from "./YZ_Constant";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class YzCustomAdPanel extends cc.Component {
  6. @property({ type: cc.Node })
  7. exitBtn: cc.Node = null;
  8. closeCallFunc: Function = null;
  9. //关闭按钮点击次数
  10. closeCount: number = 1;
  11. closeBtnClickCount: number = 0;
  12. onLoad() {
  13. if (utils.otherConfig && utils.otherConfig.group) {
  14. this.node.group = utils.otherConfig.group;
  15. }
  16. utils.adManager.showCustomAd({ location: 100 })
  17. let ratio = 0;
  18. if (cc.winSize.height < cc.winSize.width) {
  19. // 横屏游戏
  20. ratio = cc.winSize.width / 1920 * 0.75;
  21. } else {
  22. ratio = cc.winSize.width / 1080;
  23. }
  24. if (utils.getConfigByKey("custom_panel_close_count")) {
  25. this.closeCount = utils.getConfigByKey("custom_panel_close_count");
  26. }
  27. cc.find("Panel", this.node).scale = ratio;
  28. this.exitBtn.runAction(cc.fadeIn(3));
  29. }
  30. onExitBtnClickListener() {
  31. utils.showLog("退出游戏模版弹窗!");
  32. this.closeBtnClickCount++;
  33. if (this.closeCount == this.closeBtnClickCount) {
  34. cc.director.emit("CloseCustomADPanel");
  35. this.node.destroy();
  36. utils.adManager.hideCustomAd({ location: 100 });
  37. this.closeCallFunc && this.closeCallFunc();
  38. }
  39. }
  40. }