platformBrowser.ts 2.1 KB

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