platformBrowser.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { _decorator} from 'cc';
  2. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  3. import { GameConst } from '../core/common/GameConst';
  4. import { audioMgr } from '../core/manager/AudioManager';
  5. import { settingData } from '../user/SettingData';
  6. import { Singleton } from '../core/manager/Singleton';
  7. const { ccclass, property } = _decorator;
  8. class PlatformBrowser extends Singleton{
  9. adInstance: any = null;
  10. gtag: any = null;
  11. openAd: boolean = true;
  12. public initialize(): void {
  13. this.initilizeWindow();
  14. this.adInstance = (window as any)['adInstance'];
  15. try {
  16. window["__woso"]?.["TopCallback"]?.();
  17. } catch (error) {
  18. }
  19. console.log('web ads sdk初始化');
  20. }
  21. private initilizeWindow() {
  22. window["youxi"] = {
  23. SoundManager: {
  24. pauseAll: () => {
  25. settingData.data.soundFx = false;
  26. settingData.data.bgMusic = false;
  27. settingData.saveToCache();
  28. audioMgr.stop(GameConst.audios.bg_music);
  29. },
  30. resumeAll: () => {
  31. settingData.data.soundFx = true;
  32. settingData.data.bgMusic = true;
  33. audioMgr.play(GameConst.audios.bg_music,true);
  34. settingData.saveToCache();
  35. }
  36. },
  37. GameManager: {
  38. pauseAll: () => {
  39. // console.log(`暂停游戏`);
  40. },
  41. resumeAll: () => {
  42. // console.log(`开始游戏`);
  43. }
  44. },
  45. TargetedAds: {
  46. open: () => {
  47. console.log("开启广告");
  48. },
  49. clos: () => {
  50. console.log("关闭广告");
  51. }
  52. },
  53. Fps: {
  54. setfps: (value) => {
  55. // GlobalMgr.instance.setfps(value);
  56. }
  57. }
  58. };
  59. }
  60. /**显示插屏广告*/
  61. public showInterstitialAd(cb?:Function): void {
  62. if(GameConst.isDebug){
  63. console.log('模拟显示插屏广告回调');
  64. cb?.();
  65. return
  66. }
  67. try {
  68. window['showAd']('interstitial').then(() => {
  69. //MsgHints.show(i18n('main.插屏广告加载成功'))
  70. }).catch(() => {
  71. //MsgHints.show(i18n('main.插屏广告加载失败'))
  72. // GtagMgr.inst.doGameDot(GtagType.ad_error);
  73. });
  74. } catch (error) {
  75. // tgxUITips.show('The ad failed to load')
  76. }
  77. }
  78. /** 显示激励广告*/
  79. public showRewardVideo(cb:Function): void {
  80. //1 成功 0 失败分享
  81. if(GameConst.isDebug){
  82. console.log('模拟激励广告回调');
  83. cb?.(1);
  84. return
  85. }
  86. try {
  87. window["showAd"]('rewarded')
  88. .then(() => {
  89. //MsgHints.show(i18n('main.激励广告加载成功'))
  90. if (cb) cb(1);
  91. })
  92. .catch(() => {
  93. //MsgHints.show(i18n('main.激励广告加载失败'))
  94. //上报信息
  95. // GtagMgr.inst.doGameDot(GtagType.ad_error);
  96. // cb && cb();
  97. })
  98. return
  99. } catch (error) {
  100. }
  101. //tgxUITips.show('The ads failed to load');
  102. }
  103. /** 显示激励广告*/
  104. public hideBannerAd(): void {
  105. }
  106. public showBannerAd(): void {
  107. }
  108. public vibrateShort(): void {
  109. }
  110. }
  111. export const platformBrowser = PlatformBrowser.ins();