import { _decorator, Node, Prefab, instantiate, Component, Camera, UITransform, v3, game, view, screen, tween, Vec3 } from 'cc'; const { ccclass, property } = _decorator; /** 广告管理*/ @ccclass('AdvertMgr') export class AdvertMgr { private static _instance: AdvertMgr | null = null; public static get instance(): AdvertMgr { if (!this._instance) this._instance = new AdvertMgr(); return this._instance; } adInstance: any = null; gtag: any = null; openAd: boolean = true; initilize(): void { this.adInstance = (window as any)['adInstance']; console.log('ad sdk初始化'); console.log(this.adInstance); } /** 显示插屏广告*/ showInterstitial(cb?: () => void): void { if (!this.adInstance || !this.openAd) { cb && cb(); return; } this.adInstance.interstitialAd({ beforeAd() { console.log('The ad starts playing'); }, afterAd() { console.log('The ad ends playing'); }, error(err) { // console.log('The ad failed to load'); // tgxUITips.show(err); // AudioMgr.inst.resume(); } }); } /** 显示激励广告*/ showReawardVideo(cb?: () => void): void { if (!this.adInstance || !this.openAd) { cb && cb(); return; } this.adInstance.rewardAd({ beforeAd() { console.log('The ad starts playing, and the game should pause.'); // AudioMgr.inst.pause(); }, adDismissed() { console.log('Player dismissed the ad before completion.'); // AudioMgr.inst.resume(); }, adViewed() { console.log('Ad was viewed and closed.'); if (cb) cb(); // AudioMgr.inst.resume(); }, error(err: any) { // console.log(`激励广告错误:${err}`); // tgxUITips.show(err); // EventDispatcher.instance.emit(ADEvent.REWARD_VIDEO_ERROR); // AudioMgr.inst.resume(); } }); } }