Миксер

Почини интерфейс
This commit is contained in:
ThomasCharester committed 2026-03-23 23:59:32 +03:00
1 parent 1aceea1b79
commit 60c28f54f2
74 files changed
+8060 -1059

No files matched your search

@@ -31,7 +31,8 @@ namespace Code.Infrastructure.App
IAudioSourcePoolInitializedHandle,
IAudioConfigsLoadedHandle,
ICinematicMachineHandle,
ILayerMasksInitializedHandle
ILayerMasksInitializedHandle,
IAudioServiceHandle
{
public void InstallBindings(ContainerBuilder containerBuilder)
{
@@ -86,7 +87,8 @@ namespace Code.Infrastructure.App
// Audio Pool
// Cinemachine Camera
// Layer masks
_initialLoading = new Loading(11, () => EssentialLoadEnded(_thatRightContainer));
// Audio Service
_initialLoading = new Loading(12, () => EssentialLoadEnded(_thatRightContainer));
_ui2CamLoading = new Loading(2,
() =>
@@ -208,5 +210,10 @@ namespace Code.Infrastructure.App
{
}
public void AudioServiceLoaded()
{
_initialLoading.DoProgress();
}
}
}
@@ -30,13 +30,20 @@ namespace Code.Infrastructure.App.States
{
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
Context.AudioService.CancelMusic(AudioNames.UISounds,0);
Context.AudioService.ChangeGroupVolume(
AudioGroupType.Music,
0,
0.5f,
() => Context.AudioService.CancelMusic(AudioNames.UISounds,0));
_eventBus.Unsubscribe(this);
}
public void OnReadyToPlay(AudioNames groupName)
{
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
}
public void MenuChoosePanelCreated(UIPanel panel)
@@ -29,7 +29,7 @@ namespace Code.Infrastructure.App.States
Context.UIService.TryLoadCreatePanel(UIPanelType.DebugSceneChooser);
// Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
Context.SceneLoader.LoadSceneAsync(SceneId.MainMenu, LoadSceneMode.Single).Forget();
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
}
protected override void OnExitState()
@@ -49,7 +49,7 @@ namespace Code.Infrastructure.App.States
public void OnReadyToPlay(AudioNames groupName)
{
_loading.DoProgress();
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0, AudioGroupType.Music);
}
public void OnMainMenuSceneLoaded()
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
@@ -102,5 +101,6 @@ namespace Code.Infrastructure.Audio
{
void AudioClipsLoaded(AudioNames groupName, Dictionary<int, AudioClip> toDictionary);
void AudioClipsUnLoaded(AudioNames groupName);
public void ApplyParameter(string effectName, float value, float time, Action callback = null);
}
}
@@ -6,6 +6,8 @@ namespace Code.Infrastructure.Audio
public enum AudioGroupType
{
Master,
SFX,
Music,
UIFX
}
}
@@ -1,6 +1,6 @@
using Code.Infrastructure.Generators;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Audio;
namespace Code.Infrastructure.Audio
{
@@ -11,9 +11,14 @@ namespace Code.Infrastructure.Audio
[ToConfig] public int id;
[ToConfig] public AssetReference fileReference;
}
[Config("Configs/Audio/AudioSourceSettings")]
[Config("Configs/Audio/AudioSource")]
public class AudioSourcePrefab
{
[ToConfig] public AssetReference sourcePrefab;
}
[Config("Configs/Audio/AudioMixer")]
public class AudioMixerConfig
{
[ToConfig] public AudioMixer mixerAsset;
}
}
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using PrimeTween;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Audio;
namespace Code.Infrastructure.Audio
@@ -12,16 +16,18 @@ namespace Code.Infrastructure.Audio
AudioClip GetClip(AudioNames groupName, int id);
void PlayTest();
UniTaskVoid PlayOneShot(AudioNames groupName, int id, Vector3 position = new Vector3(),
UniTaskVoid PlayOneShot(AudioNames groupName, int id, AudioGroupType audioGroupType, Vector3 position = new Vector3(),
AudioSourceType sourceType = AudioSourceType.NoBlend,
AudioSource audioSource = null);
UniTaskVoid PlayRepeatedly(AudioNames groupName, int id,
UniTaskVoid PlayRepeatedly(AudioNames groupName, int id, AudioGroupType audioGroupType,
AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null, CancellationTokenSource cancellationTokenSource = null);
bool CheckClip(AudioNames groupName, int id);
void CancelMusic(AudioNames groupName, int id);
void ReleaseCancellationSource(AudioNames groupName, int id);
void ApplyParameter(string effectName, float value, float time, Action callback = null);
void ChangeGroupVolume(AudioGroupType groupType, float value, float time, Action callback = null);
}
public partial class AudioService : IAudioClipsEventHandle, IAudioService
@@ -33,7 +39,7 @@ namespace Code.Infrastructure.Audio
private AudioMixer _mixer;
private Dictionary<AudioGroupType, AudioMixerGroup> _audioMixerGroups = new();
public AudioService(EventBus.EventBus eventBus, IAudioFactory audioFactory, IAudioSourcePool pool)
public AudioService(EventBus.EventBus eventBus, IAudioFactory audioFactory, IAudioSourcePool pool, IConfigLocator configLocator)
{
_eventBus = eventBus;
_audioFactory = audioFactory;
@@ -44,16 +50,27 @@ namespace Code.Infrastructure.Audio
for (int i = 0; i < typeof(AudioNames).GetEnumValues().Length; i++)
_audioClips.Add((AudioNames)i, new Dictionary<int, AudioClip>());
//InitializeMixer();
LoadMixerAsset(configLocator.TryGetConfigAssetReference<AudioMixerConfigConfig>()).Forget();
}
private partial void InitializeMixer();
private async UniTaskVoid LoadMixerAsset(AssetReference audioMixerConfig)
{
var audioMixer = await Addressables.LoadAssetAsync<AudioMixerConfigConfig>(audioMixerConfig);
_mixer = audioMixer.mixerAsset;
InitializeMixer();
_eventBus.RaiseEvent<IAudioServiceHandle>(x=> x.AudioServiceLoaded());
}
public void PlayTest()
{
_pool.GetSource(AudioSourceType.NoBlend).PlayOneShot(GetClip(AudioNames.UISounds, 0));
}
public async UniTaskVoid PlayOneShot(AudioNames groupName, int id, Vector3 position = new Vector3(),
public async UniTaskVoid PlayOneShot(AudioNames groupName, int id, AudioGroupType audioGroupType, Vector3 position = new Vector3(),
AudioSourceType sourceType = AudioSourceType.NoBlend,
AudioSource audioSource = null)
{
@@ -62,6 +79,7 @@ namespace Code.Infrastructure.Audio
if (!audioSource) audioSource = _pool.GetSource(sourceType);
audioSource.transform.position = position;
audioSource.outputAudioMixerGroup = _audioMixerGroups[audioGroupType];
audioSource.PlayOneShot(GetClip(groupName, id));
await UniTask.NextFrame();
@@ -74,7 +92,7 @@ namespace Code.Infrastructure.Audio
public void CancelMusic(AudioNames groupName, int id) => _cancellationTokenSources[new KeyValuePair<AudioNames, int>(groupName, id)].Cancel();
public void ReleaseCancellationSource(AudioNames groupName, int id) => _cancellationTokenSources[new KeyValuePair<AudioNames, int>(groupName, id)] = null;
public async UniTaskVoid PlayRepeatedly(AudioNames groupName, int id,
public async UniTaskVoid PlayRepeatedly(AudioNames groupName, int id, AudioGroupType audioGroupType,
AudioSourceType sourceType = AudioSourceType.NoBlend, AudioSource audioSource = null, CancellationTokenSource cancellationTokenSource = null)
{
if (!CheckClip(groupName, id)) return;
@@ -87,7 +105,7 @@ namespace Code.Infrastructure.Audio
if (!audioSource) audioSource = _pool.GetSource(sourceType);
if(!audioSource.resource) audioSource.resource = GetClip(groupName, id);
audioSource.outputAudioMixerGroup = _audioMixerGroups[audioGroupType];
audioSource.Play();
await UniTask.NextFrame();
@@ -107,7 +125,7 @@ namespace Code.Infrastructure.Audio
return;
}
PlayRepeatedly(groupName, id, sourceType, audioSource, cancellationTokenSource).Forget();
PlayRepeatedly(groupName, id, AudioGroupType.Music, sourceType, audioSource, cancellationTokenSource).Forget();
}
public AudioClip GetClip(AudioNames groupName, int id) => _audioClips[groupName][id];
@@ -124,10 +142,26 @@ namespace Code.Infrastructure.Audio
_audioClips[groupName].Clear();
_audioClips[groupName] = null;
}
public void ApplyParameter(string effectName, float value, float time, Action callback = null)
{
_mixer.GetFloat(effectName, out float startValue);
Tween.Custom(startValue, value, time, newValue => {
_mixer.SetFloat(effectName, newValue);
}).OnComplete(callback);
}
public void ChangeGroupVolume(AudioGroupType groupType, float value, float time, Action callback = null)
{
ApplyParameter(_audioMixerGroups[groupType].name, Mathf.Log10(value == 0f ? 0.001f : value) * 20, time, callback);
}
}
public interface IReadyToPlayHandle : IGlobalSubscriber
{
void OnReadyToPlay(AudioNames groupName);
}
public interface IAudioServiceHandle : IGlobalSubscriber
{
void AudioServiceLoaded();
}
}
@@ -51,4 +51,5 @@ namespace Code.Infrastructure.Generators
public class AudioMixerEnum : Attribute
{
}
public class UIEventOpenClose : Attribute{}
}
@@ -1,5 +1,6 @@
#if UNITY_EDITOR
using Code.Infrastructure.UI;
using Code.Infrastructure.UI;
using Unity.VisualScripting;
using UnityCodeGen;
using UnityEditor;
@@ -43,6 +44,33 @@ namespace Code.Infrastructure.Generators
}}
";
if(st.HasAttribute(typeof(UIEventOpenClose)))
{
fireStatesCode += $@"
protected override void FireOpenedEvent()
{{
_eventBus.RaiseEvent<I{st.Name}OpenedHandle>(h => h.{st.Name}Opened(this));
}}
protected override void FireClosedEvent()
{{
_eventBus.RaiseEvent<I{st.Name}ClosedHandle>(h => h.{st.Name}Closed());
base.FireClosedEvent();
}}
";
fireStatesInterfacesCode += $@"
public interface I{st.Name}OpenedHandle : IGlobalSubscriber
{{
void {st.Name}Opened(UIPanel panel);
}}
public interface I{st.Name}ClosedHandle : IGlobalSubscriber
{{
void {st.Name}Closed();
}}
";
}
var statesCode = $@"
// retard-generated
@@ -1,5 +1,4 @@
using System;
using UnityEngine;
namespace Code.Infrastructure.Loadings
{
@@ -26,7 +25,7 @@ namespace Code.Infrastructure.Loadings
_progress--;
_loadProgress?.Invoke(this);
if(_progress <= 0) // Зачем инвертировать, если так читается лучше, райдер соси
if(_progress == 0) // Зачем инвертировать, если так читается лучше, райдер соси
{
Completed = true;
_completed();
@@ -1,23 +1,25 @@
using System;
using System;
using Code.Infrastructure.Generators;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace Code.Infrastructure.UI.Panels
{
[UIEventOpenClose]
public partial class LoadingPanel : UIPanel
{
[SerializeField] private RawImage image;
[SerializeField] private Color shownColor;
[SerializeField] private Color hiddenColor;
public override void Open(Action callback = null)
public override void Open()
{
Tween.Color(image,shownColor, 1f).OnComplete( () => callback?.Invoke());
Tween.Color(image,shownColor, 1f).OnComplete(FireOpenedEvent);
}
public override void Close(Action callback = null)
public override void Close()
{
Tween.Color(image,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
Tween.Color(image,hiddenColor, 1f).OnComplete(FireClosedEvent);
}
}
}
@@ -1,23 +1,24 @@
using System;
using Code.Infrastructure.Generators;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace Code.Infrastructure.UI.Panels
{
[UIEventOpenClose]
public partial class LogoPanel : UIPanel
{
[SerializeField] private Image image;
[SerializeField] private Color shownColor;
[SerializeField] private Color hiddenColor;
public override void Open(Action callback = null)
public override void Open()
{
Tween.Color(image,shownColor, 1f).OnComplete( () => callback?.Invoke());
Tween.Color(image,shownColor, 1f).OnComplete(FireOpenedEvent);
}
public override void Close(Action callback = null)
public override void Close()
{
Tween.Color(image,hiddenColor, 1f).OnComplete( () => callback?.Invoke());
Tween.Color(image,hiddenColor, 1f).OnComplete(FireClosedEvent);
}
}
}
@@ -1,28 +1,28 @@
using System;
using Code.Debug;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Generators;
using Reflex.Attributes;
using UnityEngine;
namespace Code.Infrastructure.UI.Panels
{
[UIEventOpenClose]
public partial class MenuChoosePanel : UIPanel
{
[Inject] IAudioService _audioService;
[SerializeField] private SceneChooser sceneChooser;
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(Action callback = null)
public void PlaySelectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 7, AudioGroupType.UIFX);
public void PlayDeselectSound() => _audioService.PlayOneShot(AudioNames.UISounds, 8, AudioGroupType.UIFX);
public void PlayClickSound() => _audioService.PlayOneShot(AudioNames.UISounds, 1, AudioGroupType.UIFX);
public override void Open()
{
sceneChooser.EnableButtons();
callback?.Invoke();
FireOpenedEvent();
}
public override void Close(Action callback = null)
public override void Close()
{
callback?.Invoke();
FireClosedEvent();
}
}
}
+8 -3
View File
@@ -1,4 +1,3 @@
using System;
using Reflex.Attributes;
using UnityEngine;
@@ -11,11 +10,17 @@ namespace Code.Infrastructure.UI
[SerializeField] protected bool injectMeSenpai;
public bool InjectMeSenpai => injectMeSenpai;
[Inject] protected EventBus.EventBus _eventBus;
public abstract void Open(Action callback = null);
public abstract void Close(Action callback = null);
public abstract void Open();
public abstract void Close();
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
public virtual void FireCreatedEvent(){}
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
public virtual void FireRemovedEvent(){}
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
protected virtual void FireOpenedEvent(){}
// Вызвать вручную \ добавить в коллбек для вызова ивента в EventBus
protected virtual void FireClosedEvent(){gameObject.SetActive(false);}
}
}
+3 -15
View File
@@ -52,10 +52,7 @@ namespace Code.Infrastructure.UI
// TODO Close event
public void ClosePanel(UIPanelType uiPanelType)
{
_loadedSinglePanels[uiPanelType].Close(() =>
{
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
});
_loadedSinglePanels[uiPanelType].Close();
}
public void TryLoadCreatePanel(UIPanelType uiPanelType, Transform parent = null) => _factory.LoadPanel(uiPanelType, parent);
@@ -89,20 +86,11 @@ namespace Code.Infrastructure.UI
UnityEngine.Debug.LogError("Это для единичных панелей олух");
return;
}
_loadedSinglePanels[uiPanelType].Close(() =>
{
_loadedSinglePanels[uiPanelType].gameObject.SetActive(false);
RemovePanel(uiPanelType);
});
_loadedSinglePanels[uiPanelType].Close();
}
public void TryRemovePanel(UIPanel panel)
{
panel.Close(() =>
{
panel.gameObject.SetActive(false);
RemovePanel(panel);
// _eventBus.RaiseEvent<IUIMultiplePanelHandle>(x=> x.UIMultiplePanelRemoved(panel));
});
panel.Close();
}
private void RemovePanel(UIPanelType panelType)