mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
Audio player
This commit is contained in:
32
assets/Scripts/Game/Audio/GameAudioAdapter.ts
Normal file
32
assets/Scripts/Game/Audio/GameAudioAdapter.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { _decorator, Component, Node, AudioClip } from "cc";
|
||||
import { AppRoot } from "../../AppRoot/AppRoot";
|
||||
import { AudioPlayer } from "../../Services/AudioPlayer/AudioPlayer";
|
||||
import { Enemy } from "../Unit/Enemy/Enemy";
|
||||
import { EnemyManager } from "../Unit/Enemy/EnemyManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("GameAudioAdapter")
|
||||
export class GameAudioAdapter extends Component {
|
||||
@property(AudioClip) private enemyHit: AudioClip;
|
||||
|
||||
private audioPlayer: AudioPlayer;
|
||||
|
||||
public init(enemyManager: EnemyManager): void {
|
||||
this.audioPlayer = AppRoot.Instance.AudioPlayer;
|
||||
|
||||
enemyManager.EnemyAddedEvent.on(this.addEnemyListeners, this);
|
||||
enemyManager.EnemyRemovedEvent.on(this.removeEnemyListeners, this);
|
||||
}
|
||||
|
||||
private addEnemyListeners(enemy: Enemy): void {
|
||||
enemy.Health.HealthPointsChangeEvent.on(this.playEnemyHitSound, this);
|
||||
}
|
||||
|
||||
private removeEnemyListeners(enemy: Enemy): void {
|
||||
enemy.Health.HealthPointsChangeEvent.off(this.playEnemyHitSound);
|
||||
}
|
||||
|
||||
private playEnemyHitSound(): void {
|
||||
this.audioPlayer.playSound(this.enemyHit);
|
||||
}
|
||||
}
|
9
assets/Scripts/Game/Audio/GameAudioAdapter.ts.meta
Normal file
9
assets/Scripts/Game/Audio/GameAudioAdapter.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "eb84241d-4cc1-4e50-911d-c0c880ec024d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user