using Code.Game.Cleaning.Player; using Code.Game.Gameplay.Player; using Code.Game.Gameplay.Player.Factory; using Code.Infrastructure.App; using Code.Infrastructure.Camera; using Code.Infrastructure.Generators; using Code.Infrastructure.Input; using Code.Infrastructure.SceneLoader; using Code.Infrastructure.UI; using Code.Infrastructure.Utils; using Code.OfficeGame.BattleMode.Actions.Player; using Code.OfficeGame.BattleMode.UI; using Code.OfficeGame.Player; using Cysharp.Threading.Tasks; using KinematicCharacterController; using ObservableCollections; using R3; using Reflex.Core; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; namespace Code.Game.TestingLevel { [State(typeof(AppStates), typeof(AppStateMachineContext))] public partial class TestingState { public TestingState(AppStateMachineContext context) : base(context) { } public override AppStates MyState => AppStates.Testing; public override async UniTask EnterState() { Cursor.lockState = CursorLockMode.Locked; #if UNITY_EDITOR Context.InputService.EnableMap(ActionMappings.Debug); Context.InputService.BindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode); #endif Context.InputService.EnableMap(ActionMappings.OpenMovement); Context.InputService.EnableMap(ActionMappings.UI); // await Context.Camera.SwitchState(CameraMode.OpenMovement); if (Context.StateMachine.CurrentState == AppStates.BattleState) return; Context.AudioService.SetAudioListener(Context.Camera.Camera.GetComponent()); var waitForContainer = Context.SceneContainerManager.ScenesContainers .ObserveDictionaryAdd() .Where(x => x.Key == SceneId.Testing) .Take(1) .WaitAsync() .AsUniTask(); var factoryConfig = new SingleConfig(); await factoryConfig.LoadConfig(); var factory = new PlayerFactory(factoryConfig); var player = await factory.CreatePlayer(); var playerKinematicCharacterMotor = player.GetComponent(); var playerMovementController = player.GetComponent(); var playerControlsProvider = player.GetComponent(); var playerAnimatorProvider = player.GetComponent(); var playerTimelineActor = player.GetComponent(); playerMovementController.Freeze = true; BattleActionDecisionPanel battleActionDecisionPanel = (BattleActionDecisionPanel) await Context.UIFactory .LoadPanel(UIPanelType.BattleActionDecision,false); // ((OpenMovementCameraState)Context.Camera.CurrentBaseState).SetTarget(player.transform); void InstallExtra(Scene scene, ContainerBuilder builder) { builder.RegisterValue(factoryConfig); builder.RegisterValue(factory, new []{typeof(IPlayerFactory)}); builder.RegisterValue(playerKinematicCharacterMotor); builder.RegisterValue(playerMovementController); builder.RegisterValue(playerControlsProvider); builder.RegisterValue(playerAnimatorProvider); builder.RegisterValue(playerTimelineActor); builder.RegisterValue(battleActionDecisionPanel); } await UniTask.WhenAll( Context.SceneLoader .LoadSceneAsync( SceneId.Testing, LoadSceneMode.Single, true, InstallExtra), Context.SceneLoader .LoadSceneAsync( SceneId.FirstTestingSegment, LoadSceneMode.Additive, false), Context.SceneLoader .LoadSceneAsync( SceneId.SecondTestingSegment, LoadSceneMode.Additive, false), waitForContainer ); var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing]; container.Resolve() .SetPositionAndRotation( container.Resolve().playerSpawnPoint.position, container.Resolve().playerSpawnPoint.rotation); playerMovementController.Freeze = false; } private void ToggleBattleMode(InputAction.CallbackContext obj) { Context.StateMachine.SwitchState(AppStates.BattleState).Forget(); } public override async UniTask ExitState() { #if UNITY_EDITOR Context.InputService.DisableMap(ActionMappings.Debug); Context.InputService.UnbindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode); #endif Context.InputService.DisableMap(ActionMappings.OpenMovement); if (Context.StateMachine.NextState == AppStates.BattleState) return; await Context.SceneLoader.UnloadSceneAsync(SceneId.Testing); await Context.SceneLoader.UnloadSceneAsync(SceneId.FirstTestingSegment); await Context.SceneLoader.UnloadSceneAsync(SceneId.SecondTestingSegment); } } }