SoundSystem.ts 686 B

12345678910111213141516171819202122
  1. import { _decorator, Component, Node, game, find } from 'cc';
  2. import { Sound } from '../core/sound/Sound';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('SoundSystem')
  5. export class SoundSystem extends Component {
  6. private static thisObject: SoundSystem;
  7. start() {
  8. SoundSystem.thisObject = this;
  9. game.addPersistRootNode(this.node);
  10. }
  11. public static play(index: number) {
  12. this.thisObject.getComponent(Sound).play(index);
  13. }
  14. public static stop() {
  15. this.thisObject && this.thisObject.getComponent(Sound).stop();
  16. }
  17. public static setVolume(value: number) {
  18. this.thisObject.getComponent(Sound).volume = value;
  19. }
  20. }