AdAgentBroser.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import AdAgent from "./AdAgent";
  2. import YZ_NativeBanner from "./YZ_NativeBanner";
  3. import YZ_NativeInsert from "./YZ_NativeInsert";
  4. import { BeForGameOverAdId, LevelStatus, BannerLocation } from "./YZ_Constant";
  5. import { NativeBannerInfo } from "./CommonConfig";
  6. import { utils } from "./Utils";
  7. import YZ_NativeItem from "./YZ_NativeItem";
  8. import YZ_NativeAdObject from "./YZ_NativeAdObject";
  9. export default class AdAgentBroser extends AdAgent {
  10. _nativeBannerNode: cc.Node;
  11. _nativeInsertNode: cc.Node;
  12. _nativeBannerInfo: NativeBannerInfo = null;
  13. //当前显示Banner的位置
  14. _curLocation: BannerLocation = BannerLocation.None;
  15. /**
  16. * 获取当前banner配置
  17. */
  18. getNativeBannerInfo() {
  19. return new NativeBannerInfo();
  20. }
  21. public ShowBanner(location: BannerLocation = null) {
  22. if (this._curLocation != location) {
  23. this.HideBanner(location);
  24. }
  25. this._curLocation = location;
  26. if (this.getNativeBannerInfo().is_show_banner == -1) {
  27. utils.showLog("当前位置配置为不展示banner!");
  28. this.HideBanner(location);
  29. return;
  30. }
  31. if (!this._nativeBannerNode) {
  32. this._nativeBannerNode = cc.instantiate(utils.config.otherconfig.nativeBanner);
  33. cc.director.getScene().addChild(this._nativeBannerNode, 1000);
  34. }
  35. this._nativeBannerNode.active = true;
  36. let nativeBanner = this._nativeBannerNode.getComponent(YZ_NativeBanner);
  37. if (nativeBanner) {
  38. let addate = { title: "今日头条", desc: "看新闻用今日头条", imgUrlList: [utils.cur_tool.img_url], icon: utils.cur_tool.img_url };
  39. nativeBanner.init(null, addate, this.getNativeBannerInfo());
  40. }
  41. // utils.showRecommendGamesBanner();
  42. }
  43. public ShowInterstitial() {
  44. if (!this._nativeInsertNode) {
  45. this._nativeInsertNode = cc.instantiate(utils.config.otherconfig.nativeInsert);
  46. cc.director.getScene().addChild(this._nativeInsertNode, 9999);
  47. }
  48. this._nativeInsertNode.active = true;
  49. let nativeBanner = this._nativeInsertNode.getComponent(YZ_NativeInsert);
  50. if (nativeBanner) {
  51. let addate = { title: "今日头条", desc: "看新闻用今日头条", imgUrlList: [utils.cur_tool.img_url], icon: utils.cur_tool.img_url };
  52. nativeBanner.init(null, addate);
  53. }
  54. // utils.showRecommendGamesBanner();
  55. }
  56. showStatementAds(data) {
  57. utils.adManager.ShowInterstitial();
  58. // utils.showCrossWidget6();
  59. }
  60. public HideBanner(location: BannerLocation = null) {
  61. if (this._nativeBannerNode) {
  62. this._nativeBannerNode.active = false;
  63. }
  64. utils.hideRecommendGamesBanner();
  65. }
  66. public ShowVideo(callback: Function) {
  67. callback(true, "视频播放成功!");
  68. }
  69. showBeforGameOverAd(level: number, levelStatus: LevelStatus, rewardValue: number, closeCallFunc: Function, rewardFunc: Function): void {
  70. cc.log("显示结算前广告: #Level= ", level, " #LevelStatys=", levelStatus, " #rewardValue = ", rewardValue);
  71. utils.currentLevel = level;
  72. utils.isSuccess = levelStatus == LevelStatus.GameWin;
  73. utils.rewardCallFunc = rewardFunc;
  74. utils.rewardCloseFunc = closeCallFunc;
  75. utils.rewardValue = rewardValue;
  76. let adType = utils.adManager.checkShowBeforGameOverAd(level, levelStatus == LevelStatus.GameWin);
  77. switch (adType) {
  78. case BeForGameOverAdId.SharePanel:
  79. utils.recordEnd();
  80. utils.showShareRecordPanel();
  81. break;
  82. case BeForGameOverAdId.GoldBox:
  83. utils.adManager.showRewardBoxPanel();
  84. break;
  85. case BeForGameOverAdId.Turntable:
  86. utils.adManager.showrewardTurnTablePanel();
  87. break;
  88. default:
  89. closeCallFunc && closeCallFunc();
  90. break;
  91. }
  92. }
  93. signleNativeAd: cc.Node = null;
  94. _curNativeItem: YZ_NativeItem = null;
  95. /**
  96. * 创建结算页面推广组件
  97. */
  98. public ShowSingleNativeAd(params?: any) {
  99. if (utils.config.otherconfig.singleNativeAd) {
  100. if (this.signleNativeAd && cc.isValid(this.signleNativeAd)) {
  101. this.signleNativeAd.destroy();
  102. }
  103. this.signleNativeAd = cc.instantiate(utils.config.otherconfig.singleNativeAd);
  104. let nativeItem: YZ_NativeItem = this.signleNativeAd.getComponent("YZ_NativeItem");
  105. nativeItem.showType = 2;
  106. nativeItem.params = params;
  107. this._curNativeItem = nativeItem;
  108. if (params && params.parent) {
  109. params.parent.addChild(this.signleNativeAd, cc.macro.MAX_ZINDEX);
  110. }
  111. let nativeObj = new YZ_NativeAdObject();
  112. let data = {
  113. imgUrlList: [utils.cur_tool.img_url],
  114. icon: utils.cur_tool.img_url,
  115. title: "爱奇艺视频",
  116. desc: "下载爱奇艺,即送VIP!"
  117. }
  118. nativeObj.data = data;
  119. nativeItem._nativeAd = nativeObj;
  120. this._curNativeItem.init(nativeObj);
  121. utils.showLog("单个原生广告创建成功!");
  122. return this.signleNativeAd;
  123. } else {
  124. utils.showLog("未找到预制体 singleNativeAd, 请查看CommonUtils组件上是否赋值!");
  125. return null;
  126. }
  127. }
  128. }