PlatformBrowser.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { _decorator} from 'cc';
  2. import { Constants } from '../data/Constants';
  3. const { ccclass, property } = _decorator;
  4. class PlatformBrowser {
  5. adInstance: any = null;
  6. gtag: any = null;
  7. openAd: boolean = true;
  8. public initialize(): void {
  9. this.adInstance = (window as any)['adInstance'];
  10. try {
  11. window["__woso"]?.["TopCallback"]?.();
  12. } catch (error) {
  13. }
  14. console.log('web ads sdk初始化');
  15. }
  16. /**显示插屏广告*/
  17. public showInterstitialAd(cb?:Function): void {
  18. if(Constants.isDebug){
  19. console.log('模拟显示插屏广告回调');
  20. cb?.();
  21. return
  22. }
  23. try {
  24. window['showAd']('interstitial').then(() => {
  25. console.log("rewarded11111")
  26. }).catch(() => {
  27. // GtagMgr.inst.doGameDot(GtagType.ad_error);
  28. });
  29. } catch (error) {
  30. // tgxUITips.show('The ad failed to load')
  31. }
  32. }
  33. /** 显示激励广告*/
  34. public showRewardVideo(cb:Function): void {
  35. if(Constants.isDebug){
  36. console.log('模拟激励广告回调');
  37. cb?.(1);
  38. return
  39. }
  40. try {
  41. window["showAd"]('rewarded')
  42. .then(() => {
  43. if (cb) cb(1);
  44. })
  45. .catch(() => {
  46. //上报信息
  47. // GtagMgr.inst.doGameDot(GtagType.ad_error);
  48. // cb && cb();
  49. })
  50. return
  51. } catch (error) {
  52. }
  53. //tgxUITips.show('The ads failed to load');
  54. }
  55. /** 显示激励广告*/
  56. public hideBannerAd(): void {
  57. }
  58. public showBannerAd(): void {
  59. }
  60. public vibrateShort(): void {
  61. }
  62. }
  63. export default new PlatformBrowser();