mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 00:26:04 +00:00
Audio player
This commit is contained in:
30
assets/Scripts/Services/AudioPlayer/AudioPlayer.ts
Normal file
30
assets/Scripts/Services/AudioPlayer/AudioPlayer.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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 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.clip = clip;
|
||||
this.musicSource.play();
|
||||
}
|
||||
}
|
9
assets/Scripts/Services/AudioPlayer/AudioPlayer.ts.meta
Normal file
9
assets/Scripts/Services/AudioPlayer/AudioPlayer.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "958e2e3e-8d16-4c76-be6e-7b61cd46e44c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user