| 12345678910111213141516171819202122232425262728293031323334353637 |
- import { System } from "cc";
- import { Sound } from "./Sound";
- /**
- * 声音系统
- * @author 袁浩
- */
- export class SoundSystem extends System {
- public static readonly ID = "SOUND";
- private soundMap: Map<string, Sound> = new Map<string, Sound>();
- public effectVolumeScale: number = 1;
- public musicVolumeScale: number = 1;
- public regedit(sound: Sound) {
- this.soundMap.set(sound.soundName, sound);
- }
- public unregedit(soundOrName: Sound | string) {
- this.soundMap.delete(typeof soundOrName == "string" ? soundOrName : soundOrName.soundName);
- }
- /**
- * 根据声音名称获取声音组件
- * @param name 声音名称
- * @returns
- */
- public getSound(name: string) {
- return this.soundMap.get(name);
- }
- /**
- * 获取所有正在运行的声音组件
- * @returns
- */
- public getSounds() {
- let sounds: Sound[] = [];
- this.soundMap.forEach((value: Sound) => {
- sounds.push(value);
- });
- return sounds;
- }
- }
|