mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-13 09:14:50 +08:00
音效管理优化
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-09-02 10:22:36
|
||||
*/
|
||||
import { AudioClip } from 'cc';
|
||||
import { AudioSource, _decorator } from 'cc';
|
||||
import { AudioClip, AudioSource, _decorator } from 'cc';
|
||||
import { IAudioParams } from './IAudio';
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
@@ -30,4 +29,11 @@ export class AudioEffect extends AudioSource {
|
||||
private onAudioEnded() {
|
||||
this.onComplete && this.onComplete(this);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.stop();
|
||||
this.clip = null;
|
||||
this.path = null!;
|
||||
this.params = null!;
|
||||
}
|
||||
}
|
||||
@@ -168,28 +168,27 @@ export class AudioEffectPool {
|
||||
key += "_" + aeid;
|
||||
|
||||
node = new Node("AudioEffect");
|
||||
|
||||
ae = node.addComponent(AudioEffect);
|
||||
ae.key = key;
|
||||
ae.aeid = aeid;
|
||||
ae.path = path;
|
||||
ae.params = params;
|
||||
ae.onComplete = this.onAudioEffectPlayComplete.bind(this);
|
||||
}
|
||||
else {
|
||||
node = this.pool.get()!;
|
||||
ae = node.getComponent(AudioEffect)!;
|
||||
key = ae.key;
|
||||
}
|
||||
|
||||
// 记录正在播放的音效播放器
|
||||
this.effects.set(key, ae);
|
||||
this.effects.set(ae.key, ae);
|
||||
|
||||
node.parent = oops.audio.node;
|
||||
ae.path = path;
|
||||
ae.params = params;
|
||||
ae.loop = params.loop!;
|
||||
ae.volume = params.volume!;
|
||||
ae.clip = clip;
|
||||
ae.play();
|
||||
|
||||
resolve(ae);
|
||||
});
|
||||
}
|
||||
@@ -208,8 +207,8 @@ export class AudioEffectPool {
|
||||
put(ae: AudioEffect) {
|
||||
let effect = this.effects.get(ae.key);
|
||||
if (effect && effect.clip) {
|
||||
effect.stop();
|
||||
effect.clip = null;
|
||||
effect.reset();
|
||||
|
||||
this.effects.delete(ae.key);
|
||||
this.pool.put(effect.node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user