SoundSystem.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { System } from "cc";
  2. import { Sound } from "./Sound";
  3. /**
  4. * 声音系统
  5. * @author 袁浩
  6. */
  7. export class SoundSystem extends System {
  8. public static readonly ID = "SOUND";
  9. private soundMap: Map<string, Sound> = new Map<string, Sound>();
  10. public effectVolumeScale: number = 1;
  11. public musicVolumeScale: number = 1;
  12. public regedit(sound: Sound) {
  13. this.soundMap.set(sound.soundName, sound);
  14. }
  15. public unregedit(soundOrName: Sound | string) {
  16. this.soundMap.delete(typeof soundOrName == "string" ? soundOrName : soundOrName.soundName);
  17. }
  18. /**
  19. * 根据声音名称获取声音组件
  20. * @param name 声音名称
  21. * @returns
  22. */
  23. public getSound(name: string) {
  24. return this.soundMap.get(name);
  25. }
  26. /**
  27. * 获取所有正在运行的声音组件
  28. * @returns
  29. */
  30. public getSounds() {
  31. let sounds: Sound[] = [];
  32. this.soundMap.forEach((value: Sound) => {
  33. sounds.push(value);
  34. });
  35. return sounds;
  36. }
  37. }