mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-25 19:28:53 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { AudioClip, AudioSource, Component, _decorator } from "cc";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("AudioPlayer")
|
|
export class AudioPlayer extends Component {
|
|
@property(AudioSource) private soundSource: AudioSource;
|
|
@property(AudioSource) private musicSource: AudioSource;
|
|
|
|
public init(soundVolume: number, musicVolume: number): void {
|
|
this.setSoundVolume(soundVolume);
|
|
this.setMusicVolume(musicVolume);
|
|
}
|
|
|
|
public get SoundVolume(): number {
|
|
return this.soundSource.volume;
|
|
}
|
|
|
|
public get MusicVolume(): number {
|
|
return this.musicSource.volume;
|
|
}
|
|
|
|
public setSoundVolume(volume: number): void {
|
|
this.soundSource.volume = volume;
|
|
}
|
|
|
|
public setMusicVolume(volume: number): void {
|
|
this.musicSource.volume = volume;
|
|
}
|
|
|
|
public playSound(clip: AudioClip): void {
|
|
this.soundSource.playOneShot(clip);
|
|
}
|
|
|
|
public playMusic(clip: AudioClip): void {
|
|
this.musicSource.stop();
|
|
this.musicSource.clip = clip;
|
|
this.musicSource.play();
|
|
}
|
|
}
|