using Code.Game.Cleaning.Player; using Code.Infrastructure.App; using Code.Infrastructure.Camera; using Code.Infrastructure.Generators; using Code.Infrastructure.Input; using Code.Infrastructure.SceneLoader; using Code.OfficeGame.Player; using Cysharp.Threading.Tasks; using KinematicCharacterController; using Reflex.Core; using UnityEngine; using UnityEngine.InputSystem; namespace Code.Game.OfficeGame.GameStates { [State(typeof(AppStates), typeof(AppStateMachineContext))] public partial class BattleState { public BattleState(AppStateMachineContext context) : base(context) { } public override AppStates MyState => AppStates.BattleState; public override async UniTask EnterState() { #if UNITY_EDITOR Context.InputService.EnableMap(ActionMappings.Debug); Context.InputService.BindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode); #endif Context.InputService.EnableMap(ActionMappings.BattleMode); var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing]; if (Context.StateMachine.CurrentState == AppStates.Testing) { Physics.simulationMode = SimulationMode.Script; KinematicCharacterSystem.EnsureCreation(); KinematicCharacterSystem.Settings.AutoSimulation = false; KinematicCharacterSystem.Settings.Interpolate = false; TogglePlayerBattleMode(container, false); await Context.Camera.SwitchState(CameraMode.BattleMode); } } private void TogglePlayerBattleMode(Container container, bool enabled) { container.Resolve().Animator.enabled = enabled; container.Resolve().enabled = enabled; } private void ToggleBattleMode(InputAction.CallbackContext obj) { Context.StateMachine.SwitchState(AppStates.Testing).Forget(); } public override async UniTask ExitState() { if (Context.StateMachine.NextState == AppStates.Testing) { Physics.simulationMode = SimulationMode.FixedUpdate; KinematicCharacterSystem.Settings.AutoSimulation = true; KinematicCharacterSystem.Settings.Interpolate = true; var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing]; TogglePlayerBattleMode(container, true); } #if UNITY_EDITOR Context.InputService.DisableMap(ActionMappings.Debug); Context.InputService.UnbindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode); #endif Context.InputService.DisableMap(ActionMappings.BattleMode); } } }