90 lines
2.5 KiB
TypeScript
90 lines
2.5 KiB
TypeScript
import { AudioClip } from "cc";
|
|
import { tgxAudioMgr } from "../../core_tgx/tgx";
|
|
import { ModuleDef } from "../../scripts/ModuleDef";
|
|
|
|
const BundleName = ModuleDef.Arean;
|
|
export class AreanGameAudioMgr {
|
|
/**
|
|
* @en
|
|
* play short audio, such as strikes,explosions
|
|
* @zh
|
|
* 播放短音频,比如 打击音效,爆炸音效等
|
|
* @param sound clip or url for the audio
|
|
* @param volume
|
|
*/
|
|
public static playOneShot(sound: AudioClip | string, volume: number = 1.0) {
|
|
// console.log(sound);
|
|
tgxAudioMgr.inst.playOneShot(sound, volume, BundleName);
|
|
}
|
|
|
|
/**
|
|
* @en
|
|
* play long audio, such as the bg music
|
|
* @zh
|
|
* 播放长音频,比如 背景音乐
|
|
* @param sound clip or url for the sound
|
|
* @param volume
|
|
*/
|
|
public static play(sound: AudioClip | string, volume: number = 1.0,) {
|
|
|
|
tgxAudioMgr.inst.play(sound, volume, BundleName);
|
|
}
|
|
|
|
/**
|
|
* stop the audio play
|
|
*/
|
|
public static stop() {
|
|
tgxAudioMgr.inst.stop();
|
|
}
|
|
|
|
/**
|
|
* pause the audio play
|
|
*/
|
|
public static pause() {
|
|
tgxAudioMgr.inst.pause();
|
|
}
|
|
|
|
/**
|
|
* resume the audio play
|
|
*/
|
|
public static resume() {
|
|
tgxAudioMgr.inst.resume();
|
|
}
|
|
|
|
public static getVolumeByDist(soundPos: { x: number, y: number, z: number }, earPos: { x: number, y: number, z: number }, maxDist: number = 50.0) {
|
|
let dx = soundPos.x - earPos.x;
|
|
let dy = soundPos.y - earPos.y;
|
|
let dz = 0;
|
|
let dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
if (dist < 1.0) {
|
|
return 1.0;
|
|
}
|
|
let factor = 1.0 / (dist / maxDist);
|
|
if (factor > 1.0) {
|
|
factor = 1.0;
|
|
}
|
|
return factor
|
|
}
|
|
}
|
|
|
|
export enum AreanAudioName {
|
|
弓箭 = 'res/Audio/arrow',
|
|
背景音乐1 = 'res/Audio/bgm1',
|
|
爆炸 = 'res/Audio/boom',
|
|
弩 = 'res/Audio/crossbow',
|
|
电光 = 'res/Audio/electric',
|
|
马 = 'res/Audio/horse',
|
|
金属1 = 'res/Audio/metal1',
|
|
金属2 = 'res/Audio/metal2',
|
|
陨石 = 'res/Audio/meteorite',
|
|
号角 = 'res/Audio/trumpet',
|
|
关闭窗口 = 'res/Audio/closeWin',
|
|
打开窗口 = 'res/Audio/openWin',
|
|
点击 = 'res/Audio/camera',
|
|
警告 = 'res/Audio/warning',
|
|
奖励 = 'res/Audio/bub',
|
|
升级 = 'res/Audio/levelup',
|
|
拖拽放手 = 'res/Audio/dragIn',
|
|
死亡 = 'res/Audio/die',
|
|
技能释放 = 'res/Audio/bub',
|
|
} |