Музыка есть

This commit is contained in:
ThomasCharester committed 2025-11-13 23:13:41 +03:00
1 parent 557c4c3dee
commit 346dc97fef
67 files changed
+774 -66

No files matched your search

@@ -1,4 +1,5 @@
using Code.App.StateMachine;
using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Player;
using Code.Input;
@@ -14,7 +15,7 @@ namespace Code.App.AppStates
private PlayerHealth _playerHealth;
private PlayerMoney _playerMoney;
private bool _uiLoaded, _sceneLoaded;
private bool _uiLoaded, _sceneLoaded, _onGameplayMusicLoaded, _onActionMusicLoaded;
public GameplayState(AppStateMachineContext context) : base(context)
{
@@ -22,7 +23,7 @@ namespace Code.App.AppStates
public override void EnterState()
{
_uiLoaded = _sceneLoaded = false;
_uiLoaded = _sceneLoaded = _onActionMusicLoaded = _onGameplayMusicLoaded = false;
Context.UIService.LoadingScreen.Show();
@@ -35,12 +36,23 @@ namespace Code.App.AppStates
Context.UIService.SwitchPanelTo(UIPanel.Gameplay, callback: PostUILoaded);
Context.AudioFactory.WarmGameplayMusic(OnGameplayMusicLoaded);
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Peaceful);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveMoney);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.LooseHealth, LooseHealth);
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.LooseMoney, LooseMoney);
}
private void OnGameplayMusicLoaded()
{
_onGameplayMusicLoaded = true;
// Context.AudioService.();
CheckIfLoaded();
}
private void OnSceneLoaded()
{
_sceneLoaded = true;
@@ -1,4 +1,5 @@
using Code.App.StateMachine;
using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Camera.CameraStates;
using Code.Input;
@@ -14,14 +15,14 @@ namespace Code.App.AppStates
{
public class MainMenuState : BaseState<AppStateMachineContext>
{
private bool _uiLoaded, _sceneLoaded;
private bool _uiLoaded, _sceneLoaded, _menuMusicLoaded;
public MainMenuState(AppStateMachineContext context) : base(context)
{
}
public override void EnterState()
{
_uiLoaded = _sceneLoaded = false;
_uiLoaded = _sceneLoaded = _menuMusicLoaded = false;
Context.UIService.LoadingScreen.Show();
@@ -29,9 +30,20 @@ namespace Code.App.AppStates
Context.UIService.SwitchPanelTo(UIPanel.MainMenu, PostUILoaded);
Context.AudioFactory.WarmMenuMusic(MenuMusicLoaded);
Context.CameraStateMachine.SwitchState(CameraMode.Static);
}
private void MenuMusicLoaded()
{
_menuMusicLoaded = true;
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Peaceful);
Context.AudioService.PlayRandomMenuMusicUntilHumanityWillBeDestroyedForTheySins();
CheckIfLoaded();
}
private void PostUILoaded()
{
((MainMenuPanel)Context.UIService.CurrentPanel).startButton.onClick.AddListener(StartGame);
@@ -60,7 +72,7 @@ namespace Code.App.AppStates
private void CheckIfLoaded()
{
if(!_uiLoaded || !_sceneLoaded) return;
if(!_uiLoaded || !_sceneLoaded || !_menuMusicLoaded) return;
Context.UIService.LoadingScreen.Hide();
@@ -87,7 +99,8 @@ namespace Code.App.AppStates
public override void ExitState()
{
Context.InputService.DisableMap(ActionMappings.MainMenu);
Context.AudioService.GladlyAskToStopMenuMusic(Context.AudioFactory.ReleaseMenuMusic);
base.ExitState();
}
}
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Code.App.StateMachine;
using Code.Audio;
using Code.Configs;
using Code.Constants;
using Code.Gameplay.Camera;
@@ -32,6 +33,10 @@ namespace Code.App
InitializeCamera(containerBuilder, staticDataService);
containerBuilder.AddSingleton(typeof(UIFactory), typeof(IUIFactory));
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
containerBuilder.AddSingleton(typeof(AudioFactory), typeof(IAudioFactory));
containerBuilder.AddSingleton(typeof(AudioService), typeof(IAudioService));
containerBuilder.AddSingleton(typeof(SceneLoaderService), typeof(ISceneLoaderService));
containerBuilder.OnContainerBuilt += Bootstrap;
@@ -69,14 +74,23 @@ namespace Code.App
containerBuilder.AddSingleton(staticDataService.PlayerConfig, typeof(PlayerConfig));
containerBuilder.AddSingleton(staticDataService.CharacterConfig, typeof(CharacterConfig));
containerBuilder.AddSingleton(staticDataService.UIConfig, typeof(UIConfig));
containerBuilder.AddSingleton(staticDataService.AudioMixerConfig, typeof(AudioMixerConfig));
containerBuilder.AddSingleton(staticDataService.SoundtrackListConfig, typeof(SoundtrackListConfig));
containerBuilder.AddSingleton(staticDataService.SFXListConfig, typeof(SFXListConfig));
containerBuilder.AddSingleton(staticDataService.DispatcherSoundListConfig, typeof(DispatcherSoundListConfig));
containerBuilder.AddSingleton(staticDataService.EnemiesSoundListConfig, typeof(EnemiesSoundListConfig));
// containerBuilder.AddSingleton(staticDataService.UIConfig.canvasPrefab, typeof(Canvas));
// containerBuilder.AddSingleton(staticDataService.UIConfig.uiElementsPrefabs, typeof(UIElement[]));
}
private bool _onUiLoaded;
private bool _onAudioLoaded;
private AppStateMachine _appStateMachine;
private void Bootstrap(Container container)
{
container.Resolve<IAudioFactory>();
IAudioService audioService = container.Resolve<IAudioService>();
audioService.Initialize(OnAudioLoaded);
_appStateMachine = container.Resolve<AppStateMachine>();
_appStateMachine.Initialize();
AttributeInjector.Inject(_appStateMachine.StateMachineContext, container);
@@ -91,16 +105,21 @@ namespace Code.App
IUIService uiService = container.Resolve<IUIService>();
uiService.Initialize(loadingScreen.GetComponent<LoadingScreen>());
TryStartGame();
}
private void TryStartGame()
{
if (!_onAudioLoaded) return;
// TODO: поменяно для теста
_appStateMachine
.SwitchState(AppState.MainMenu)
.AllowStateTransition(AppState.Gameplay);
}
private void OnAudioLoaded()
{
_onAudioLoaded = true;
TryStartGame();
}
}
}
@@ -1,3 +1,4 @@
using Code.Audio;
using Code.Gameplay.Camera;
using Code.Gameplay.Player;
using Code.Input;
@@ -15,5 +16,7 @@ namespace Code.App.StateMachine
[Inject] public CameraStateMachine CameraStateMachine { get; private set; }
[Inject] public IUIService UIService { get; private set; }
[Inject] public IPlayerFactory PlayerFactory { get; private set; }
[Inject] public IAudioFactory AudioFactory { get; private set; }
[Inject] public IAudioService AudioService { get; private set; }
}
}