В инфраструктуре начался сущий кошмар
This commit is contained in:
1 parent
346dc97fef
commit
e67fea2051
51 files changed
+659
-140
No files matched your search
@@ -4,26 +4,35 @@ using Code.Gameplay.Camera;
|
||||
using Code.Gameplay.Player;
|
||||
using Code.Input;
|
||||
using Code.Scenes;
|
||||
using Code.Scenes.SceneEnvironments;
|
||||
using Code.StateMachine;
|
||||
using Code.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.App.AppStates
|
||||
{
|
||||
public class GameplayState : BaseState<AppStateMachineContext>
|
||||
{
|
||||
// DEBUG
|
||||
private Transform _testSFXTransform;
|
||||
// DEBUG
|
||||
|
||||
private PlayerHealth _playerHealth;
|
||||
private PlayerMoney _playerMoney;
|
||||
|
||||
private bool _uiLoaded, _sceneLoaded, _onGameplayMusicLoaded, _onActionMusicLoaded;
|
||||
|
||||
private bool _uiLoaded, _sceneLoaded, _onGameplayMusicLoaded, _onSFXLoaded;
|
||||
|
||||
public GameplayState(AppStateMachineContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
_uiLoaded = _sceneLoaded = _onActionMusicLoaded = _onGameplayMusicLoaded = false;
|
||||
_uiLoaded = _sceneLoaded = _onGameplayMusicLoaded = _onSFXLoaded = false;
|
||||
|
||||
Context.UIService.LoadingScreen.Show();
|
||||
|
||||
@@ -32,52 +41,101 @@ namespace Code.App.AppStates
|
||||
|
||||
_playerHealth.OnDeath += EndGame;
|
||||
|
||||
Context.SceneLoaderService.LoadSceneAsync((int)SceneIds.MovementDev, callBack: OnSceneLoaded); // TODO Фабрика игрока Nada
|
||||
// TODO
|
||||
// Context.SceneLoaderService.LoadSceneAsync((int)SceneIds.MovementDev, callBack: OnSceneLoaded); // TODO Фабрика игрока Nada
|
||||
|
||||
Context.UIService.SwitchPanelTo(UIPanel.Gameplay, callback: PostUILoaded);
|
||||
// Context.UIService.SwitchPanelTo(UIPanel.Gameplay, callback: PostUILoaded);
|
||||
|
||||
Context.AudioFactory.WarmGameplayMusic(OnGameplayMusicLoaded);
|
||||
// Context.AudioFactory.WarmGameplayMusic(OnGameplayMusicLoaded);
|
||||
// Context.AudioFactory.WarmSFX(OnSFXLoaded);
|
||||
// TODO
|
||||
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;
|
||||
CheckIfLoaded();
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveHealth);
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, GiveMoney);
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, LooseHealth);
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, LooseMoney);
|
||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, PlayDebugSFX);
|
||||
|
||||
WaitForSceneToLoad();
|
||||
}
|
||||
|
||||
private void PostUILoaded()
|
||||
private async UniTaskVoid WaitForSceneToLoad()
|
||||
{
|
||||
await UniTask.WhenAll(
|
||||
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.MovementDev),
|
||||
Context.UIService.AsyncSwitchPanelTo(UIPanel.Gameplay),
|
||||
Context.AudioFactory.WarmGameplayMusic(),
|
||||
Context.AudioFactory.WarmSFX()
|
||||
);
|
||||
|
||||
Context.AudioService.PlayRandomPeacefulMusicUntilHumanityWillBeDestroyedForTheySins();
|
||||
Context.AudioService.PlayRandomActionMusicUntilHumanityWillBeDestroyedForTheySins();
|
||||
|
||||
var sceneEnvironment = ((GameplaySceneEnvironment)SceneManager.GetActiveScene()
|
||||
.GetSceneContainer().Resolve<CurrentSceneEnvironment>());
|
||||
|
||||
_testSFXTransform = sceneEnvironment.debugSfxTarget;
|
||||
|
||||
((GameplayPanel)Context.UIService.CurrentPanel).Initialize(_playerMoney, _playerHealth);
|
||||
_uiLoaded = true;
|
||||
CheckIfLoaded();
|
||||
}
|
||||
|
||||
private void CheckIfLoaded()
|
||||
{
|
||||
if(!_uiLoaded || !_sceneLoaded) return;
|
||||
|
||||
Context.UIService.LoadingScreen.Hide();
|
||||
|
||||
Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
|
||||
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||
|
||||
Context.UIService.LoadingScreen.Hide();
|
||||
}
|
||||
|
||||
// private void OnGameplayMusicLoaded()
|
||||
// {
|
||||
// _onGameplayMusicLoaded = true;
|
||||
//
|
||||
// Context.AudioService.PlayRandomPeacefulMusicUntilHumanityWillBeDestroyedForTheySins();
|
||||
// Context.AudioService.PlayRandomActionMusicUntilHumanityWillBeDestroyedForTheySins();
|
||||
//
|
||||
// CheckIfLoaded();
|
||||
// }
|
||||
// private void OnSFXLoaded()
|
||||
// {
|
||||
// _onSFXLoaded = true;
|
||||
//
|
||||
// CheckIfLoaded();
|
||||
// }
|
||||
// private void OnSceneLoaded()
|
||||
// {
|
||||
// _sceneLoaded = true;
|
||||
//
|
||||
// var sceneEnvironment = ((GameplaySceneEnvironment)SceneManager.GetActiveScene()
|
||||
// .GetSceneContainer().Resolve<CurrentSceneEnvironment>());
|
||||
//
|
||||
// _testSFXTransform = sceneEnvironment.debugSfxTarget;
|
||||
//
|
||||
// CheckIfLoaded();
|
||||
// }
|
||||
//
|
||||
// private void PostUILoaded()
|
||||
// {
|
||||
// ((GameplayPanel)Context.UIService.CurrentPanel).Initialize(_playerMoney, _playerHealth);
|
||||
// _uiLoaded = true;
|
||||
// CheckIfLoaded();
|
||||
// }
|
||||
//
|
||||
// private void CheckIfLoaded()
|
||||
// {
|
||||
// if(!_uiLoaded || !_sceneLoaded || !_onGameplayMusicLoaded || !_onSFXLoaded) return;
|
||||
//
|
||||
// Context.UIService.LoadingScreen.Hide();
|
||||
//
|
||||
// Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
|
||||
// Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||
// }
|
||||
|
||||
|
||||
// Debug
|
||||
// DEBUG
|
||||
|
||||
private void PlayDebugSFX(InputAction.CallbackContext context)
|
||||
{
|
||||
Context.AudioService.PlaySFX(SFXSounds.Crowbar, _testSFXTransform.position);
|
||||
}
|
||||
private void GiveHealth(InputAction.CallbackContext context)
|
||||
{
|
||||
_playerHealth.GetDamage(-1);
|
||||
@@ -99,7 +157,7 @@ namespace Code.App.AppStates
|
||||
_playerMoney.LooseMoney(100);
|
||||
((GameplayPanel)(Context.UIService.CurrentPanel)).CloseDispatcher();
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
public override void Tick()
|
||||
{
|
||||
}
|
||||
@@ -116,11 +174,13 @@ namespace Code.App.AppStates
|
||||
_playerMoney = null;
|
||||
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
Context.AudioService.GladlyAskToStopGameplayMusic(Context.AudioFactory.ReleaseGameplayMusic);
|
||||
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.GiveHealth, GiveHealth);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.GiveMoney, GiveHealth);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.LooseHealth, LooseHealth);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.LooseMoney, LooseMoney);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveHealth);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, GiveHealth);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, LooseHealth);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, LooseMoney);
|
||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, PlayDebugSFX);
|
||||
|
||||
base.ExitState();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Code.Scenes;
|
||||
using Code.Scenes.SceneEnvironments;
|
||||
using Code.StateMachine;
|
||||
using Code.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -15,47 +16,42 @@ namespace Code.App.AppStates
|
||||
{
|
||||
public class MainMenuState : BaseState<AppStateMachineContext>
|
||||
{
|
||||
private bool _uiLoaded, _sceneLoaded, _menuMusicLoaded;
|
||||
// private bool _uiLoaded, _sceneLoaded, _menuMusicLoaded;
|
||||
public MainMenuState(AppStateMachineContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override void EnterState()
|
||||
{
|
||||
_uiLoaded = _sceneLoaded = _menuMusicLoaded = false;
|
||||
// _uiLoaded = _sceneLoaded = _menuMusicLoaded = false;
|
||||
|
||||
Context.UIService.LoadingScreen.Show();
|
||||
|
||||
Context.SceneLoaderService.LoadSceneAsync((int)SceneIds.MainMenu, callBack: SceneLoaded);
|
||||
|
||||
Context.UIService.SwitchPanelTo(UIPanel.MainMenu, PostUILoaded);
|
||||
|
||||
Context.AudioFactory.WarmMenuMusic(MenuMusicLoaded);
|
||||
// Context.SceneLoaderService.LoadSceneAsync((int)SceneIds.MainMenu);
|
||||
//
|
||||
// Context.UIService.SwitchPanelTo(UIPanel.MainMenu, PostUILoaded);
|
||||
//
|
||||
// Context.AudioFactory.WarmMenuMusic(MenuMusicLoaded);
|
||||
|
||||
Context.CameraStateMachine.SwitchState(CameraMode.Static);
|
||||
|
||||
WaitForSceneToLoad();
|
||||
}
|
||||
|
||||
private void MenuMusicLoaded()
|
||||
private async UniTaskVoid WaitForSceneToLoad()
|
||||
{
|
||||
_menuMusicLoaded = true;
|
||||
await UniTask.WhenAll(
|
||||
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.MainMenu),
|
||||
Context.UIService.AsyncSwitchPanelTo(UIPanel.MainMenu),
|
||||
Context.AudioFactory.WarmMenuMusic()
|
||||
);
|
||||
|
||||
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Peaceful);
|
||||
Context.AudioService.PlayRandomMenuMusicUntilHumanityWillBeDestroyedForTheySins();
|
||||
|
||||
CheckIfLoaded();
|
||||
}
|
||||
private void PostUILoaded()
|
||||
{
|
||||
|
||||
((MainMenuPanel)Context.UIService.CurrentPanel).startButton.onClick.AddListener(StartGame);
|
||||
((MainMenuPanel)Context.UIService.CurrentPanel).exitButton.onClick.AddListener(ExitGame);
|
||||
|
||||
_uiLoaded = true;
|
||||
|
||||
CheckIfLoaded();
|
||||
}
|
||||
|
||||
private void SceneLoaded()
|
||||
{
|
||||
var hui = ((MainMenuEnvironment)SceneManager.GetActiveScene()
|
||||
.GetSceneContainer().Resolve<CurrentSceneEnvironment>());
|
||||
|
||||
@@ -64,22 +60,56 @@ namespace Code.App.AppStates
|
||||
|
||||
((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(hui.cameraPosition);
|
||||
|
||||
|
||||
_sceneLoaded = true;
|
||||
|
||||
CheckIfLoaded();
|
||||
}
|
||||
|
||||
private void CheckIfLoaded()
|
||||
{
|
||||
if(!_uiLoaded || !_sceneLoaded || !_menuMusicLoaded) return;
|
||||
|
||||
Context.UIService.LoadingScreen.Hide();
|
||||
|
||||
Context.InputService.EnableMap(ActionMappings.MainMenu);
|
||||
|
||||
base.EnterState();
|
||||
}
|
||||
|
||||
// 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);
|
||||
// ((MainMenuPanel)Context.UIService.CurrentPanel).exitButton.onClick.AddListener(ExitGame);
|
||||
//
|
||||
// _uiLoaded = true;
|
||||
//
|
||||
// CheckIfLoaded();
|
||||
// }
|
||||
//
|
||||
// private void SceneLoaded()
|
||||
// {
|
||||
// var hui = ((MainMenuEnvironment)SceneManager.GetActiveScene()
|
||||
// .GetSceneContainer().Resolve<CurrentSceneEnvironment>());
|
||||
//
|
||||
// ((StaticState)Context.CameraStateMachine.CurrentBaseState).LookTarget =
|
||||
// hui.cameraTarget;
|
||||
//
|
||||
// ((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(hui.cameraPosition);
|
||||
//
|
||||
//
|
||||
// _sceneLoaded = true;
|
||||
//
|
||||
// CheckIfLoaded();
|
||||
// }
|
||||
//
|
||||
// private void CheckIfLoaded()
|
||||
// {
|
||||
// if(!_uiLoaded || !_sceneLoaded || !_menuMusicLoaded) return;
|
||||
//
|
||||
// Context.UIService.LoadingScreen.Hide();
|
||||
//
|
||||
// Context.InputService.EnableMap(ActionMappings.MainMenu);
|
||||
//
|
||||
// base.EnterState();
|
||||
// }
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
|
||||
@@ -79,18 +79,13 @@ namespace Code.App
|
||||
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 _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);
|
||||
@@ -98,28 +93,24 @@ namespace Code.App
|
||||
CameraStateMachine cameraStateMachine = container.Resolve<CameraStateMachine>();
|
||||
AttributeInjector.Inject(cameraStateMachine.StateMachineContext, container);
|
||||
cameraStateMachine.Initialize();
|
||||
|
||||
BootstrapFinish(container);
|
||||
}
|
||||
private async UniTaskVoid BootstrapFinish(Container container)
|
||||
{
|
||||
// container.Resolve<IAudioFactory>();
|
||||
|
||||
var loadingScreen = GameObject.FindWithTag(Tags.LoadingScreen);
|
||||
DontDestroyOnLoad(loadingScreen);
|
||||
|
||||
IUIService uiService = container.Resolve<IUIService>();
|
||||
uiService.Initialize(loadingScreen.GetComponent<LoadingScreen>());
|
||||
await UniTask.WhenAll(
|
||||
container.Resolve<IUIService>().Initialize(loadingScreen.GetComponent<LoadingScreen>()),
|
||||
container.Resolve<IAudioService>().Initialize()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private void TryStartGame()
|
||||
{
|
||||
if (!_onAudioLoaded) return;
|
||||
// TODO: поменяно для теста
|
||||
_appStateMachine
|
||||
.SwitchState(AppState.MainMenu)
|
||||
.AllowStateTransition(AppState.Gameplay);
|
||||
}
|
||||
|
||||
private void OnAudioLoaded()
|
||||
{
|
||||
_onAudioLoaded = true;
|
||||
TryStartGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Code.Scenes;
|
||||
using Code.Scenes.SceneEnvironments;
|
||||
using Reflex.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.App.SceneInstallers
|
||||
{
|
||||
public class GameplaySceneInstaller : MonoBehaviour, IInstaller
|
||||
{
|
||||
[SerializeField] private GameplaySceneEnvironment _gameplaySceneEnvironment;
|
||||
|
||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||
{
|
||||
containerBuilder.AddScoped(typeof(GameplaySceneEnvironment), typeof(CurrentSceneEnvironment));
|
||||
|
||||
containerBuilder.OnContainerBuilt += Initialize;
|
||||
}
|
||||
|
||||
private void Initialize(Container container)
|
||||
{
|
||||
GameplaySceneEnvironment env = (GameplaySceneEnvironment)container.Resolve<CurrentSceneEnvironment>();
|
||||
|
||||
env.TransitVariables(_gameplaySceneEnvironment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88584fd4361b46f6a7326440cd95ce69
|
||||
timeCreated: 1763144580
|
||||
@@ -2,6 +2,7 @@ using Code.Scenes;
|
||||
using Code.Scenes.SceneEnvironments;
|
||||
using Reflex.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Code.App.SceneInstallers
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user