2024-04-24 01:52:31 -07:00
|
|
|
import { _decorator, AudioClip, CCFloat, Component, Node } from 'cc';
|
2024-05-27 02:19:31 -07:00
|
|
|
import AudioManager from '../Manager/AudioManager';
|
2024-04-24 01:52:31 -07:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass('SequenceSound')
|
|
|
|
export class SequenceSound extends Component {
|
|
|
|
@property({ type: CCFloat, visible: true })
|
|
|
|
private _duration: number = 0.5;
|
|
|
|
@property({ type: AudioClip, visible: true })
|
|
|
|
private _audioClips: AudioClip[] = [];
|
|
|
|
|
|
|
|
private _currentIndex = 0;
|
|
|
|
private _timer = 0;
|
|
|
|
|
|
|
|
protected update(dt: number): void {
|
|
|
|
if (this._timer > 0) {
|
|
|
|
this._timer -= dt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public playSound(volume: number = 1) {
|
|
|
|
if (this._timer > 0) {
|
2024-05-27 02:19:31 -07:00
|
|
|
AudioManager.playSfx(this._audioClips[this._currentIndex], { volume });
|
2024-04-24 01:52:31 -07:00
|
|
|
this._currentIndex++;
|
|
|
|
if (this._currentIndex >= this._audioClips.length) this._currentIndex = 0;
|
|
|
|
} else {
|
|
|
|
this._currentIndex = 0;
|
2024-05-27 02:19:31 -07:00
|
|
|
AudioManager.playSfx(this._audioClips[this._currentIndex], { volume });
|
2024-04-24 01:52:31 -07:00
|
|
|
}
|
|
|
|
this._timer = this._duration;
|
|
|
|
}
|
|
|
|
}
|