Пытаюсь добавить AudioMixer

This commit is contained in:
ThomasCharester committed 2026-01-28 18:07:47 +03:00
1 parent 1f8e14d078
commit ec60c47652
20 files changed
+197 -80

No files matched your search

@@ -0,0 +1,11 @@
using Code.Infrastructure.Generators;
namespace Code.Infrastructure.Audio
{
[AudioMixerEnum]
public enum AudioGroupType
{
Master,
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 754a72a6b2c140a49a23bf6d39654c94
timeCreated: 1769609499
@@ -11,9 +11,10 @@ namespace Code.Infrastructure.Audio
[ToConfig] public int id;
[ToConfig] public AssetReference fileReference;
}
[Config("Configs/Audio/AudioSource")]
public class AudioSourcePrefab
[Config("Configs/Audio/AudioServiceSettings")]
public class AudioServiceSettings
{
[ToConfig] public AssetReference prefabReference;
[ToConfig] public AssetReference sourcePrefab;
[ToConfig] public AssetReference mixerPrefab;
}
}
@@ -3,6 +3,7 @@ using System.Threading;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Audio;
namespace Code.Infrastructure.Audio
{
@@ -19,13 +20,15 @@ namespace Code.Infrastructure.Audio
CancellationTokenSource cancellationTokenSource, AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null);
}
public class AudioService : IAudioClipsEventHandle, IAudioService
public partial class AudioService : IAudioClipsEventHandle, IAudioService
{
private EventBus.EventBus _eventBus;
private IAudioFactory _audioFactory;
private IAudioSourcePool _pool;
private Dictionary<AudioNames, Dictionary<int, AudioClip>> _audioClips = new();
private AudioMixer _mixer;
private Dictionary<AudioGroupType, AudioMixerGroup> _audioMixerGroups = new();
public AudioService(EventBus.EventBus eventBus, IAudioFactory audioFactory, IAudioSourcePool pool)
{
_eventBus = eventBus;
@@ -36,8 +39,11 @@ namespace Code.Infrastructure.Audio
for (int i = 0; i < typeof(AudioNames).GetEnumValues().Length; i++)
_audioClips.Add((AudioNames)i, new Dictionary<int, AudioClip>());
InitializeMixer();
}
private partial void InitializeMixer();
public void PlayTest()
{
_pool.GetSource(AudioSourceType.NoBlend).PlayOneShot(GetClip(AudioNames.UISounds, 0));
@@ -33,7 +33,7 @@ namespace Code.Infrastructure.Audio
private string _configsLabel;
private AsyncOperationHandle<IList<AudioSourceSettingsConfig>> _handles;
private AssetReference _sourcePrefabConfigReference;
private AsyncOperationHandle<AudioSourcePrefabConfig> _prefabConfigHandle;
private AsyncOperationHandle<AudioServiceSettingsConfig> _prefabConfigHandle;
private AsyncOperationHandle<GameObject> _prefabHandle;
private EventBus.EventBus _eventBus;
@@ -42,21 +42,21 @@ namespace Code.Infrastructure.Audio
_eventBus = eventBus;
_configsLabel = configLocator.TryGetManyConfigAssetReferences<AudioSourceSettingsConfig>();
_sourcePrefabConfigReference = configLocator.TryGetConfigAssetReference<AudioSourcePrefabConfig>();
_sourcePrefabConfigReference = configLocator.TryGetConfigAssetReference<AudioServiceSettingsConfig>();
LoadConfigs().Forget();
}
private async UniTaskVoid LoadConfigs()
{
_prefabConfigHandle = Addressables.LoadAssetAsync<AudioSourcePrefabConfig>(_sourcePrefabConfigReference);
_prefabConfigHandle = Addressables.LoadAssetAsync<AudioServiceSettingsConfig>(_sourcePrefabConfigReference);
_handles = Addressables.LoadAssetsAsync<AudioSourceSettingsConfig>(_configsLabel);
await UniTask.WhenAll(
_prefabConfigHandle.ToUniTask(),
_handles.ToUniTask());
_prefabHandle = Addressables.LoadAssetAsync<GameObject>(_prefabConfigHandle.Result.prefabReference);
_prefabHandle = Addressables.LoadAssetAsync<GameObject>(_prefabConfigHandle.Result.sourcePrefab);
_settings = _handles.Result.ToDictionary(x => x.sourceType);
@@ -9,5 +9,6 @@ namespace Code.Infrastructure.Audio
[ToConfig] public float spatialBlend;
[ToConfig] public AudioSourceType sourceType;
}
}