platformBrowser.ts 2.2 KB

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