123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- import {RDAdsEntity} from "./RDAdsEntity";
- import {RDPlatformManager} from "./RDPlatformManager";
- import {Log, LOG_TAG} from "../log/Log";
- import {RDCommand} from "./RDCommand";
- import {RDPlatformParam} from "./RDPlatformParam";
- export class AdsManager extends cc.Component {
- private static readonly ADS_LEVEL_COUNT: number = 2;
- private static _instance: AdsManager = new AdsManager();
- private _playCount: number = 0;
- //private _mainPush: UIADMainPush[] = [];
- private bannerList = null;
- private drawList = null;
- private showBanner = false;
- public static getInstance(): AdsManager {
- return this._instance;
- }
- public init(): void {
- Log.log(LOG_TAG, "[AdsManager] Init");
- }
- /**
- * 是否开启矩阵广告
- */
- isMatrixAdOpen(): boolean {
- var matrixAdOpen = RDPlatformParam.ADPARAM[RDPlatformParam.platFromId]["matrixAdOpen"];
- return matrixAdOpen;
- }
- /**
- * 调用奖励广告
- * @param cmd
- * @param data
- */
- public showRewardAd(cmd: number, data: RDAdsEntity): void {
- Log.log(LOG_TAG, "showRewardAd");
- RDPlatformManager.getInstance().sendData(cmd, data);
- }
- /**
- * 调用BannerAd
- * @param cmd
- * @param data
- */
- public showBannerAd() {
- if (!this.showBanner) {
- this.showBanner = true;
- RDPlatformManager.getInstance().sendData(RDCommand.CMD_SHOW_BANNER_AD, null);
- }
- }
- public hideBannerAd() {
- this.showBanner = false;
- RDPlatformManager.getInstance().sendData(RDCommand.CMD_HIDE_BANNER_AD, null);
- }
- /**
- * 调用插屏广告
- */
- public showInterstitialAd(): void {
- this._playCount++;
- if (this._playCount < AdsManager.ADS_LEVEL_COUNT) {
- return;
- }
- this._playCount = 0;
- RDPlatformManager.getInstance().sendData(RDCommand.CMD_SHOW_INTERSTITIAL_VIDEO_AD, null);
- }
- /**
- * 显示主推广告 可以同时开启多个
- * @param name 主推标识
- * @param position 位置
- * @param time 时间
- */
- // public showMainPush(position, time?: number) {
- // if (!this.isMatrixAdOpen()) return;
- // // //主推UI
- // if (this._mainPush.length == 0) {
- // cc.director.getScheduler().schedule(this.updateMainPush, this, 1, cc.macro.REPEAT_FOREVER, 0.1, false);
- // }
- // let admianpush = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADMAINPUSH);
- // let mainPush = cc.instantiate(admianpush);
- // let mpScript = mainPush.getComponent(UIADMainPush);
- // cc.director.getScene().addChild(mainPush, 100);
- // mpScript.setPosition(position);
- // this._mainPush.push(mpScript);
- // }
- // updateMainPush() {
- // let gameConfig = GameListManger.getInstance().gameList;
- // var id = Utils.random(0, gameConfig.length);
- // this._mainPush.forEach(element => {
- // if (id >= gameConfig.length) {
- // id = 0;
- // }
- // element.freash(gameConfig[id]);
- // id += 1;
- // });
- // }
- // public hideMainPush() {
- // if (!this.isMatrixAdOpen()) return;
- // this._mainPush.forEach(element => {
- // element.node.destroy();
- // });
- // this._mainPush = [];
- // cc.director.getScheduler().unschedule(this.updateMainPush, this);
- // }
- /**
- * 动态显示 banner列表
- * @param position
- */
- // public showADBannerList(position) {
- // if (!this.isMatrixAdOpen()) return;
- // if (!this.bannerList) {
- // let bannerListPrefab = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADBANNERLIST);
- // let bannerList = cc.instantiate(bannerListPrefab);
- // cc.director.getScene().addChild(bannerList, 10000);
- // this.bannerList = bannerList;
- // }
- // this.bannerList.setPosition(position);
- // }
- public hideADBannerList() {
- if (!this.isMatrixAdOpen()) return;
- if (this.bannerList) {
- this.bannerList.destroy();
- this.bannerList = null;
- }
- }
- /**
- * 动态显示 draw抽屉矩阵
- * @param positionY
- */
- // public showADDraw(positionY) {
- // if (!this.isMatrixAdOpen()) return;
- // if (!this.drawList) {
- // let drawListPrefab = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADADRAW);
- // let drawList = cc.instantiate(drawListPrefab);
- // cc.director.getScene().addChild(drawList, 100);
- // this.drawList = drawList;
- // }
- // this.drawList.y = positionY;
- // }
- public hideADDraw() {
- if (!this.isMatrixAdOpen()) return;
- if (this.drawList) {
- this.drawList.destroy();
- this.drawList = null;
- }
- }
- /**
- * 打开全屏效果图
- */
- // public showADScreen() {
- // //Todo 添加全屏推广界面 看给的效果图
- // console.log("全屏===============广告");
- // let prefab = <cc.Prefab>BenzAssetManager.getInstance().getAsset(AssetsHelper.COMMON_PREFABS_ADSCREEN);
- // let adScreen = cc.instantiate(prefab);
- // cc.director.getScene().addChild(adScreen, 10000);
- // }
- }
|