重构音频模块 1. 高频、大量音频反复调用时,单帧 CPU 开销与 GC 最优 2. AudioClip / AudioSource 的加载、缓存淘汰、卸载形成完整闭环,避免线性遍历 3. AudioSource 对象池 + 播放请求 struct 全部池化覆盖所有分配点 4. 支持3D环境音并具备距离衰减、遮挡等空间属性 5. 新增音频类型(BGM/SFX/Voice/Ambient) 6. 可调式监控Debug信息 及时跟踪音频缓存 处理 句柄状态
98 lines
5.8 KiB
C#
98 lines
5.8 KiB
C#
using AlicizaX.Audio.Runtime;
|
|
using AlicizaX.Editor;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace AlicizaX.Audio.Editor
|
|
{
|
|
[CustomEditor(typeof(AudioGroupConfigCollection))]
|
|
internal sealed class AudioGroupConfigCollectionInspector : UnityEditor.Editor
|
|
{
|
|
private SerializedProperty _groupConfigs;
|
|
|
|
private static readonly GUIContent GroupConfigsLabel = new GUIContent("音频分组配置");
|
|
private static readonly GUIContent AudioTypeLabel = new GUIContent("音频类型");
|
|
private static readonly GUIContent NameLabel = new GUIContent("名称");
|
|
private static readonly GUIContent MuteLabel = new GUIContent("静音");
|
|
private static readonly GUIContent VolumeLabel = new GUIContent("音量");
|
|
private static readonly GUIContent AgentCountLabel = new GUIContent("通道数");
|
|
private static readonly GUIContent ExposedVolumeLabel = new GUIContent("Mixer音量参数");
|
|
private static readonly GUIContent SpatialBlendLabel = new GUIContent("空间混合");
|
|
private static readonly GUIContent DopplerLabel = new GUIContent("多普勒");
|
|
private static readonly GUIContent SpreadLabel = new GUIContent("扩散");
|
|
private static readonly GUIContent SourcePriorityLabel = new GUIContent("AudioSource优先级");
|
|
private static readonly GUIContent ReverbZoneMixLabel = new GUIContent("混响区混合");
|
|
private static readonly GUIContent OcclusionEnabledLabel = new GUIContent("开启遮挡");
|
|
private static readonly GUIContent OcclusionMaskLabel = new GUIContent("遮挡检测层");
|
|
private static readonly GUIContent OcclusionIntervalLabel = new GUIContent("遮挡检测间隔");
|
|
private static readonly GUIContent OcclusionCutoffLabel = new GUIContent("遮挡低通截止频率");
|
|
private static readonly GUIContent OcclusionVolumeLabel = new GUIContent("遮挡音量系数");
|
|
private static readonly GUIContent RolloffModeLabel = new GUIContent("衰减模式");
|
|
private static readonly GUIContent MinDistanceLabel = new GUIContent("最小距离");
|
|
private static readonly GUIContent MaxDistanceLabel = new GUIContent("最大距离");
|
|
|
|
private void OnEnable()
|
|
{
|
|
_groupConfigs = serializedObject.FindProperty("m_GroupConfigs");
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
EditorGUILayout.PropertyField(_groupConfigs, GroupConfigsLabel, false);
|
|
if (_groupConfigs.isExpanded)
|
|
{
|
|
EditorGUI.indentLevel++;
|
|
for (int i = 0; i < _groupConfigs.arraySize; i++)
|
|
{
|
|
SerializedProperty element = _groupConfigs.GetArrayElementAtIndex(i);
|
|
DrawConfig(element, i);
|
|
}
|
|
EditorGUI.indentLevel--;
|
|
}
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
|
|
private static void DrawConfig(SerializedProperty configProperty, int index)
|
|
{
|
|
if (configProperty == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
SerializedProperty typeProperty = configProperty.FindPropertyRelative("AudioType");
|
|
string title = typeProperty != null ? typeProperty.enumDisplayNames[typeProperty.enumValueIndex] : ("配置 " + index);
|
|
EditorGUILayout.BeginVertical(GUI.skin.box);
|
|
EditorGUILayout.LabelField(title, EditorStyles.boldLabel);
|
|
|
|
EditorGUILayout.PropertyField(typeProperty, AudioTypeLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_Name"), NameLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_Mute"), MuteLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_Volume"), VolumeLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_AgentHelperCount"), AgentCountLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_ExposedVolumeParameter"), ExposedVolumeLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_SpatialBlend"), SpatialBlendLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_DopplerLevel"), DopplerLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_Spread"), SpreadLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_SourcePriority"), SourcePriorityLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_ReverbZoneMix"), ReverbZoneMixLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("audioRolloffMode"), RolloffModeLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("minDistance"), MinDistanceLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("maxDistance"), MaxDistanceLabel);
|
|
|
|
SerializedProperty occlusionEnabled = configProperty.FindPropertyRelative("m_OcclusionEnabled");
|
|
EditorGUILayout.PropertyField(occlusionEnabled, OcclusionEnabledLabel);
|
|
if (occlusionEnabled.boolValue)
|
|
{
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_OcclusionMask"), OcclusionMaskLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_OcclusionCheckInterval"), OcclusionIntervalLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_OcclusionLowPassCutoff"), OcclusionCutoffLabel);
|
|
EditorGUILayout.PropertyField(configProperty.FindPropertyRelative("m_OcclusionVolumeMultiplier"), OcclusionVolumeLabel);
|
|
}
|
|
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
}
|
|
}
|