mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-01-14 06:51:30 +00:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
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);
|
|
}
|
|
}
|