GlobalMgr.ts 1.7 KB

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