GlobalMgr.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Node, Prefab, _decorator, assetManager, find, instantiate } from 'cc';
  2. import { AudioMgr } from '../core_tgx/base/AudioMgr';
  3. import { AdvertMgr } from '../core_tgx/base/ad/AdvertMgr';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('GlobalMgr')
  6. export class GlobalMgr {
  7. private static _instance: GlobalMgr | null = null;
  8. public static get instance(): GlobalMgr {
  9. if (!this._instance) this._instance = new GlobalMgr();
  10. return this._instance;
  11. }
  12. //初始化__woso 挂载到window对象上
  13. public initilize() {
  14. window.__woso = {
  15. SoundMr: {
  16. pauseAll: () => {
  17. GlobalMgr.instance.pauseAllSounds();
  18. },
  19. resumeAll: () => {
  20. GlobalMgr.instance.resumeAllSounds();
  21. }
  22. },
  23. TargetedAds: {
  24. open: () => {
  25. GlobalMgr.instance.openAd();
  26. },
  27. clos: () => {
  28. GlobalMgr.instance.closeAd();
  29. }
  30. },
  31. Fps: {
  32. setfps: (value) => {
  33. GlobalMgr.instance.setfps(value);
  34. }
  35. }
  36. };
  37. }
  38. // 暂停所有声音
  39. pauseAllSounds() {
  40. // console.log("暂停游戏所有声音 oh~~~~~~~~~~~");
  41. AudioMgr.inst.toggleBgMusic(false);
  42. AudioMgr.inst.toggleSoundEffects(false);
  43. }
  44. // 恢复所有声音
  45. resumeAllSounds() {
  46. // console.log("恢复游戏所有声音 emo~~~~~~~~~~");
  47. AudioMgr.inst.toggleBgMusic(true);
  48. AudioMgr.inst.toggleSoundEffects(true);
  49. }
  50. //开启广告
  51. openAd() {
  52. console.log("开启广告");
  53. AdvertMgr.instance.openAd = true;
  54. }
  55. //关闭广告
  56. closeAd() {
  57. console.log("关闭广告");
  58. AdvertMgr.instance.openAd = false;
  59. }
  60. //设置帧率
  61. setfps(value) {
  62. console.log("设置帧率:", value);
  63. }
  64. timeTest() {
  65. setTimeout(() => {
  66. window.__woso.SoundMr.pauseAll();
  67. }, 2000);
  68. }
  69. }