GlobalMgr.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { Node, Prefab, _decorator, assetManager, find, instantiate } from 'cc';
  2. import { AdvertMgr } from './AdvertMgr';
  3. import { AudioMgr } from './AudioMgr';
  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.pauseBgm();
  42. }
  43. // 恢复所有声音
  44. resumeAllSounds() {
  45. // console.log("恢复游戏所有声音 emo~~~~~~~~~~");
  46. AudioMgr.resumeBgm();
  47. }
  48. //开启广告
  49. openAd() {
  50. console.log("开启广告");
  51. AdvertMgr.instance.openAd = true;
  52. }
  53. //关闭广告
  54. closeAd() {
  55. console.log("关闭广告");
  56. AdvertMgr.instance.openAd = false;
  57. }
  58. //设置帧率
  59. setfps(value) {
  60. console.log("设置帧率:", value);
  61. }
  62. timeTest() {
  63. setTimeout(() => {
  64. window.__woso.SoundMr.pauseAll();
  65. }, 2000);
  66. }
  67. }