Now Audio Playing
This commit is contained in:
1 parent
b7527d8d68
commit
513d6d0bc5
62 files changed
+1168
-119
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Audio
|
||||
{
|
||||
public interface IAudioService
|
||||
{
|
||||
AudioClip GetClip(AudioNames groupName, int id);
|
||||
void PlayTest();
|
||||
}
|
||||
|
||||
public class AudioService : IAudioClipsEventHandle, IAudioService
|
||||
{
|
||||
private EventBus.EventBus _eventBus;
|
||||
private IAudioFactory _audioFactory;
|
||||
private IAudioSourcePool _pool;
|
||||
private Dictionary<AudioNames, Dictionary<int, AudioClip>> _audioClips = new();
|
||||
|
||||
public AudioService(EventBus.EventBus eventBus, IAudioFactory audioFactory, IAudioSourcePool pool)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_audioFactory = audioFactory;
|
||||
_pool = pool;
|
||||
|
||||
_eventBus.Subscribe(this);
|
||||
|
||||
for (int i = 0; i < typeof(AudioNames).GetEnumValues().Length; i++)
|
||||
_audioClips.Add((AudioNames)i, new Dictionary<int, AudioClip>());
|
||||
}
|
||||
|
||||
public void PlayTest()
|
||||
{
|
||||
_pool.GetSource(AudioSourceType.NoBlend).PlayOneShot(GetClip(AudioNames.UISounds, 0));
|
||||
}
|
||||
public AudioClip GetClip(AudioNames groupName, int id) => _audioClips[groupName][id];
|
||||
|
||||
public void AudioClipsLoaded(AudioNames groupname, Dictionary<int, AudioClip> clips)
|
||||
{
|
||||
_audioClips[groupname] = clips;
|
||||
_eventBus.RaiseEvent<IReadyToPlayHandle>(x=> x.OnReadyToPlay(groupname));
|
||||
}
|
||||
|
||||
public void AudioClipsUnLoaded(AudioNames groupName)
|
||||
{
|
||||
_audioClips[groupName] = null;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IReadyToPlayHandle : IGlobalSubscriber
|
||||
{
|
||||
void OnReadyToPlay(AudioNames groupName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user