audio fixes
This commit is contained in:
@@ -16,8 +16,17 @@ namespace Darkmatter.Services.Audio
|
||||
{
|
||||
if (sfxCatalog != null)
|
||||
builder.RegisterComponent(sfxCatalog);
|
||||
if (audioService != null)
|
||||
builder.RegisterComponent<IAudioService>(audioService);
|
||||
|
||||
var resolved = audioService;
|
||||
if (resolved == null) resolved = GetComponent<AudioService>();
|
||||
if (resolved == null) resolved = GetComponentInChildren<AudioService>(includeInactive: true);
|
||||
if (resolved == null) resolved = FindFirstObjectByType<AudioService>(FindObjectsInactive.Include);
|
||||
|
||||
if (resolved != null)
|
||||
builder.RegisterComponent<IAudioService>(resolved);
|
||||
else
|
||||
Debug.LogError("[AudioServiceModule] No AudioService component found. SFX/music won't play. Assign 'audioService' field or add AudioService MonoBehaviour to scene.");
|
||||
|
||||
builder.Register<ISfxPlayer, SfxPlayer>(Lifetime.Singleton);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,18 @@ namespace Darkmatter.Services.Audio
|
||||
private Dictionary<AudioChannel, AudioMixerGroup> _mixerGroups;
|
||||
private float[] _currentWeights;
|
||||
|
||||
private bool _initialized;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitializeAsync(default).Forget();
|
||||
}
|
||||
|
||||
public UniTask InitializeAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_initialized) return UniTask.CompletedTask;
|
||||
_initialized = true;
|
||||
|
||||
if (sourceRoot == null) sourceRoot = transform;
|
||||
_lifetimeCts = new CancellationTokenSource();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user