AdsManager.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import {RDAdsEntity} from "./RDAdsEntity";
  2. import {RDPlatformManager} from "./RDPlatformManager";
  3. import {Log, LOG_TAG} from "../log/Log";
  4. import {RDCommand} from "./RDCommand";
  5. import {RDPlatformParam} from "./RDPlatformParam";
  6. export class AdsManager extends cc.Component {
  7. private static readonly ADS_LEVEL_COUNT: number = 2;
  8. private static _instance: AdsManager = new AdsManager();
  9. private _playCount: number = 0;
  10. //private _mainPush: UIADMainPush[] = [];
  11. private bannerList = null;
  12. private drawList = null;
  13. private showBanner = false;
  14. public static getInstance(): AdsManager {
  15. return this._instance;
  16. }
  17. public init(): void {
  18. Log.log(LOG_TAG, "[AdsManager] Init");
  19. }
  20. /**
  21. * 是否开启矩阵广告
  22. */
  23. isMatrixAdOpen(): boolean {
  24. var matrixAdOpen = RDPlatformParam.ADPARAM[RDPlatformParam.platFromId]["matrixAdOpen"];
  25. return matrixAdOpen;
  26. }
  27. /**
  28. * 调用奖励广告
  29. * @param cmd
  30. * @param data
  31. */
  32. public showRewardAd(cmd: number, data: RDAdsEntity): void {
  33. Log.log(LOG_TAG, "showRewardAd");
  34. RDPlatformManager.getInstance().sendData(cmd, data);
  35. }
  36. /**
  37. * 调用BannerAd
  38. * @param cmd
  39. * @param data
  40. */
  41. public showBannerAd() {
  42. if (!this.showBanner) {
  43. this.showBanner = true;
  44. RDPlatformManager.getInstance().sendData(RDCommand.CMD_SHOW_BANNER_AD, null);
  45. }
  46. }
  47. public hideBannerAd() {
  48. this.showBanner = false;
  49. RDPlatformManager.getInstance().sendData(RDCommand.CMD_HIDE_BANNER_AD, null);
  50. }
  51. /**
  52. * 调用插屏广告
  53. */
  54. public showInterstitialAd(): void {
  55. this._playCount++;
  56. if (this._playCount < AdsManager.ADS_LEVEL_COUNT) {
  57. return;
  58. }
  59. this._playCount = 0;
  60. RDPlatformManager.getInstance().sendData(RDCommand.CMD_SHOW_INTERSTITIAL_VIDEO_AD, null);
  61. }
  62. /**
  63. * 显示主推广告 可以同时开启多个
  64. * @param name 主推标识
  65. * @param position 位置
  66. * @param time 时间
  67. */
  68. // public showMainPush(position, time?: number) {
  69. // if (!this.isMatrixAdOpen()) return;
  70. // // //主推UI
  71. // if (this._mainPush.length == 0) {
  72. // cc.director.getScheduler().schedule(this.updateMainPush, this, 1, cc.macro.REPEAT_FOREVER, 0.1, false);
  73. // }
  74. // let admianpush = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADMAINPUSH);
  75. // let mainPush = cc.instantiate(admianpush);
  76. // let mpScript = mainPush.getComponent(UIADMainPush);
  77. // cc.director.getScene().addChild(mainPush, 100);
  78. // mpScript.setPosition(position);
  79. // this._mainPush.push(mpScript);
  80. // }
  81. // updateMainPush() {
  82. // let gameConfig = GameListManger.getInstance().gameList;
  83. // var id = Utils.random(0, gameConfig.length);
  84. // this._mainPush.forEach(element => {
  85. // if (id >= gameConfig.length) {
  86. // id = 0;
  87. // }
  88. // element.freash(gameConfig[id]);
  89. // id += 1;
  90. // });
  91. // }
  92. // public hideMainPush() {
  93. // if (!this.isMatrixAdOpen()) return;
  94. // this._mainPush.forEach(element => {
  95. // element.node.destroy();
  96. // });
  97. // this._mainPush = [];
  98. // cc.director.getScheduler().unschedule(this.updateMainPush, this);
  99. // }
  100. /**
  101. * 动态显示 banner列表
  102. * @param position
  103. */
  104. // public showADBannerList(position) {
  105. // if (!this.isMatrixAdOpen()) return;
  106. // if (!this.bannerList) {
  107. // let bannerListPrefab = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADBANNERLIST);
  108. // let bannerList = cc.instantiate(bannerListPrefab);
  109. // cc.director.getScene().addChild(bannerList, 10000);
  110. // this.bannerList = bannerList;
  111. // }
  112. // this.bannerList.setPosition(position);
  113. // }
  114. public hideADBannerList() {
  115. if (!this.isMatrixAdOpen()) return;
  116. if (this.bannerList) {
  117. this.bannerList.destroy();
  118. this.bannerList = null;
  119. }
  120. }
  121. /**
  122. * 动态显示 draw抽屉矩阵
  123. * @param positionY
  124. */
  125. // public showADDraw(positionY) {
  126. // if (!this.isMatrixAdOpen()) return;
  127. // if (!this.drawList) {
  128. // let drawListPrefab = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADADRAW);
  129. // let drawList = cc.instantiate(drawListPrefab);
  130. // cc.director.getScene().addChild(drawList, 100);
  131. // this.drawList = drawList;
  132. // }
  133. // this.drawList.y = positionY;
  134. // }
  135. public hideADDraw() {
  136. if (!this.isMatrixAdOpen()) return;
  137. if (this.drawList) {
  138. this.drawList.destroy();
  139. this.drawList = null;
  140. }
  141. }
  142. /**
  143. * 打开全屏效果图
  144. */
  145. // public showADScreen() {
  146. // //Todo 添加全屏推广界面 看给的效果图
  147. // console.log("全屏===============广告");
  148. // let prefab = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADSCREEN);
  149. // let adScreen = cc.instantiate(prefab);
  150. // cc.director.getScene().addChild(adScreen, 10000);
  151. // }
  152. }