AudioSystemNoMixer
This commit is contained in:
1 parent
72af9520df
commit
0f46c63b5d
50 files changed
+975
-50
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
@@ -46,7 +47,7 @@ namespace Code.Infrastructure.App.States
|
||||
|
||||
public void OnReadyToPlay(AudioNames groupName)
|
||||
{
|
||||
Context.AudioService.PlayTest();
|
||||
// Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0,new CancellationTokenSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Audio
|
||||
@@ -8,6 +10,13 @@ namespace Code.Infrastructure.Audio
|
||||
{
|
||||
AudioClip GetClip(AudioNames groupName, int id);
|
||||
void PlayTest();
|
||||
|
||||
UniTaskVoid PlayOneShot(AudioNames groupName, int id, Vector3 position = new Vector3(),
|
||||
AudioSourceType sourceType = AudioSourceType.NoBlend,
|
||||
AudioSource audioSource = null);
|
||||
|
||||
UniTaskVoid PlayRepeatedly(AudioNames groupName, int id,
|
||||
CancellationTokenSource cancellationTokenSource, AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null);
|
||||
}
|
||||
|
||||
public class AudioService : IAudioClipsEventHandle, IAudioService
|
||||
@@ -33,12 +42,54 @@ namespace Code.Infrastructure.Audio
|
||||
{
|
||||
_pool.GetSource(AudioSourceType.NoBlend).PlayOneShot(GetClip(AudioNames.UISounds, 0));
|
||||
}
|
||||
|
||||
public async UniTaskVoid PlayOneShot(AudioNames groupName, int id, Vector3 position = new Vector3(),
|
||||
AudioSourceType sourceType = AudioSourceType.NoBlend,
|
||||
AudioSource audioSource = null)
|
||||
{
|
||||
if (!audioSource) audioSource = _pool.GetSource(sourceType);
|
||||
|
||||
audioSource.transform.position = position;
|
||||
audioSource.PlayOneShot(GetClip(groupName, id));
|
||||
|
||||
await UniTask.NextFrame();
|
||||
await UniTask.WaitUntilValueChanged(audioSource, _ => !audioSource.isPlaying);
|
||||
|
||||
_pool.ReleaseSource(audioSource);
|
||||
}
|
||||
|
||||
public async UniTaskVoid PlayRepeatedly(AudioNames groupName, int id,
|
||||
CancellationTokenSource cancellationTokenSource, AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null)
|
||||
{
|
||||
if (!audioSource) audioSource = _pool.GetSource(sourceType);
|
||||
if(!audioSource.resource) audioSource.resource = GetClip(groupName, id);
|
||||
|
||||
audioSource.Play();
|
||||
|
||||
await UniTask.NextFrame();
|
||||
var (isCanceled, _) = await UniTask.WaitUntilValueChanged(audioSource,
|
||||
_ => !audioSource.isPlaying,
|
||||
cancellationToken: cancellationTokenSource.Token).SuppressCancellationThrow();
|
||||
UnityEngine.Debug.LogError("Music skipping");
|
||||
|
||||
if (isCanceled)
|
||||
{
|
||||
cancellationTokenSource.Dispose();
|
||||
|
||||
_pool.ReleaseSource(audioSource);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PlayRepeatedly(groupName, id, cancellationTokenSource, sourceType, audioSource).Forget();
|
||||
}
|
||||
|
||||
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));
|
||||
_eventBus.RaiseEvent<IReadyToPlayHandle>(x => x.OnReadyToPlay(groupname));
|
||||
}
|
||||
|
||||
public void AudioClipsUnLoaded(AudioNames groupName)
|
||||
|
||||
@@ -93,6 +93,7 @@ namespace Code.Infrastructure.Audio
|
||||
private void OnRelease(AudioSource source)
|
||||
{
|
||||
source.Stop();
|
||||
source.resource = null;
|
||||
//source.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Code.Infrastructure.Audio;
|
||||
using Reflex.Attributes;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class MenuChoosePanel : UIPanel
|
||||
{
|
||||
[Inject] IAudioService _audioService;
|
||||
public void PlaySelectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 7);
|
||||
public void PlayDeselectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 8);
|
||||
public void PlayClickSound() => _audioService.PlayOneShot(AudioNames.UISounds, 1);
|
||||
public override void Open()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cb94154f9164cfba977f8496353191e
|
||||
timeCreated: 1769504122
|
||||
Reference in new issue
Block a user