重构音频模块 1. 高频、大量音频反复调用时,单帧 CPU 开销与 GC 最优 2. AudioClip / AudioSource 的加载、缓存淘汰、卸载形成完整闭环,避免线性遍历 3. AudioSource 对象池 + 播放请求 struct 全部池化覆盖所有分配点 4. 支持3D环境音并具备距离衰减、遮挡等空间属性 5. 新增音频类型(BGM/SFX/Voice/Ambient) 6. 可调式监控Debug信息 及时跟踪音频缓存 处理 句柄状态
44 lines
2.9 KiB
C#
44 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Audio;
|
|
|
|
namespace AlicizaX.Audio.Runtime
|
|
{
|
|
public interface IAudioService : IService
|
|
{
|
|
float Volume { get; set; }
|
|
bool Enable { get; set; }
|
|
AudioMixer AudioMixer { get; }
|
|
Transform InstanceRoot { get; }
|
|
Transform ListenerTransform { get; }
|
|
|
|
void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null, AudioMixer audioMixer = null);
|
|
void Restart();
|
|
float GetCategoryVolume(AudioType type);
|
|
void SetCategoryVolume(AudioType type, float value);
|
|
bool GetCategoryEnable(AudioType type);
|
|
void SetCategoryEnable(AudioType type, bool value);
|
|
void RegisterListener(AudioListener listener);
|
|
void UnregisterListener(AudioListener listener);
|
|
ulong Play(AudioType type, string path, bool loop = false, float volume = 1f, bool async = false, bool cacheClip = true);
|
|
ulong Play(AudioType type, AudioClip clip, bool loop = false, float volume = 1f);
|
|
ulong Play3D(AudioType type, string path, in Vector3 position, bool loop = false, float volume = 1f, bool async = false, bool cacheClip = true);
|
|
ulong Play3D(AudioType type, string path, in Vector3 position, float minDistance, float maxDistance, AudioRolloffMode rolloffMode, float spatialBlend = 1f, bool loop = false, float volume = 1f, bool async = false, bool cacheClip = true);
|
|
ulong Play3D(AudioType type, AudioClip clip, in Vector3 position, bool loop = false, float volume = 1f);
|
|
ulong Play3D(AudioType type, AudioClip clip, in Vector3 position, float minDistance, float maxDistance, AudioRolloffMode rolloffMode, float spatialBlend = 1f, bool loop = false, float volume = 1f);
|
|
ulong PlayFollow(AudioType type, string path, Transform target, in Vector3 localOffset, bool loop = false, float volume = 1f, bool async = false, bool cacheClip = true);
|
|
ulong PlayFollow(AudioType type, string path, Transform target, in Vector3 localOffset, float minDistance, float maxDistance, AudioRolloffMode rolloffMode, float spatialBlend = 1f, bool loop = false, float volume = 1f, bool async = false, bool cacheClip = true);
|
|
ulong PlayFollow(AudioType type, AudioClip clip, Transform target, in Vector3 localOffset, bool loop = false, float volume = 1f);
|
|
ulong PlayFollow(AudioType type, AudioClip clip, Transform target, in Vector3 localOffset, float minDistance, float maxDistance, AudioRolloffMode rolloffMode, float spatialBlend = 1f, bool loop = false, float volume = 1f);
|
|
bool Stop(ulong handle, bool fadeout = false);
|
|
bool IsPlaying(ulong handle);
|
|
void Stop(AudioType type, bool fadeout);
|
|
void StopAll(bool fadeout);
|
|
void Pause(ulong handle);
|
|
void Resume(ulong handle);
|
|
void Preload(IList<string> paths, bool pin = true);
|
|
void Unload(IList<string> paths);
|
|
void ClearCache();
|
|
}
|
|
}
|