From cbc49d438466750b48f3256d64440efa7a18d720 Mon Sep 17 00:00:00 2001 From: Danil Iarosh Date: Tue, 23 Jun 2026 10:56:44 +0300 Subject: [PATCH] Decouple gameplay sessions and camera follow from concrete JumpPlayerController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Создан интерфейс IPlayerController, абстрагирующий состояние и действия игрока. - JumpPlayerController изменен для реализации интерфейса IPlayerController. - GameplaySession и VerticalCameraFollow переведены на использование IPlayerController для ослабления связей. - В GameplayInstaller добавлена регистрация зависимости IPlayerController в Zenject. --- .../Runtime/Gameplay/GameplayInstaller.cs | 1 + .../Runtime/Gameplay/GameplaySession.cs | 10 ++++---- .../Runtime/Gameplay/IPlayerController.cs | 23 +++++++++++++++++++ .../Gameplay/IPlayerController.cs.meta | 2 ++ .../Runtime/Gameplay/JumpPlayerController.cs | 8 ++++--- .../Runtime/Gameplay/VerticalCameraFollow.cs | 4 ++-- ProjectSettings/EditorSettings.asset | 2 +- 7 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 Assets/Scripts/Runtime/Gameplay/IPlayerController.cs create mode 100644 Assets/Scripts/Runtime/Gameplay/IPlayerController.cs.meta diff --git a/Assets/Scripts/Runtime/Gameplay/GameplayInstaller.cs b/Assets/Scripts/Runtime/Gameplay/GameplayInstaller.cs index 53e1d25..09922ef 100644 --- a/Assets/Scripts/Runtime/Gameplay/GameplayInstaller.cs +++ b/Assets/Scripts/Runtime/Gameplay/GameplayInstaller.cs @@ -28,6 +28,7 @@ namespace DanroJump.Gameplay } Container.BindInstance(player).AsSingle(); + Container.Bind().FromInstance(player).AsSingle(); Container.BindInstance(gameplayCamera).AsSingle(); Container.BindInstance(platformSpawner).AsSingle(); Container.BindInstance(difficultyProgression).AsSingle(); diff --git a/Assets/Scripts/Runtime/Gameplay/GameplaySession.cs b/Assets/Scripts/Runtime/Gameplay/GameplaySession.cs index 2f34828..f1c0abd 100644 --- a/Assets/Scripts/Runtime/Gameplay/GameplaySession.cs +++ b/Assets/Scripts/Runtime/Gameplay/GameplaySession.cs @@ -19,7 +19,7 @@ namespace DanroJump.Gameplay private const float HeightMetersPerScorePoint = 10f; private static readonly TimeSpan GameOverOverlayReturnDelay = TimeSpan.FromSeconds(8f); - private readonly JumpPlayerController player; + private readonly IPlayerController player; private readonly IReadOnlyServiceSettings serviceSettings; private readonly ISceneFlowService sceneFlow; private readonly IPrizeFlowService prizeFlow; @@ -64,7 +64,7 @@ namespace DanroJump.Gameplay /// /// Фактическая текущая высота игрока над стартом. /// - public float CurrentHeight => player != null ? Mathf.Max(0f, player.transform.position.y) : 0f; + public float CurrentHeight => player != null ? Mathf.Max(0f, player.Transform.position.y) : 0f; /// /// Максимальная высота, достигнутая в текущем забеге. @@ -100,7 +100,7 @@ namespace DanroJump.Gameplay /// Создает сессию и подписывается на события смерти/respawn игрока. /// public GameplaySession( - JumpPlayerController player, + IPlayerController player, [Zenject.InjectOptional] IReadOnlyServiceSettings serviceSettings = null, [Zenject.InjectOptional] ISceneFlowService sceneFlow = null, [Zenject.InjectOptional] IPrizeFlowService prizeFlow = null, @@ -220,7 +220,7 @@ namespace DanroJump.Gameplay /// /// Обновляет состояние сессии после смерти игрока. /// - private void HandlePlayerDied(JumpPlayerController _) + private void HandlePlayerDied(IPlayerController _) { audioService?.Play(GameAudioEvent.PlayerDeath); DeathCount++; @@ -249,7 +249,7 @@ namespace DanroJump.Gameplay /// /// Возвращает сессию в Running после respawn, если игра еще не закончена. /// - private void HandlePlayerRespawned(JumpPlayerController _) + private void HandlePlayerRespawned(IPlayerController _) { if (State != GameplaySessionState.GameOver) { diff --git a/Assets/Scripts/Runtime/Gameplay/IPlayerController.cs b/Assets/Scripts/Runtime/Gameplay/IPlayerController.cs new file mode 100644 index 0000000..b4f04a4 --- /dev/null +++ b/Assets/Scripts/Runtime/Gameplay/IPlayerController.cs @@ -0,0 +1,23 @@ +using UnityEngine; + +namespace DanroJump.Gameplay +{ + /// + /// Интерфейс управления игроком для ослабления связей и переиспользования логики сессий/камеры. + /// + public interface IPlayerController + { + event System.Action Died; + event System.Action Respawned; + + Transform Transform { get; } + float HighestY { get; } + float DeathRespawnDelay { get; } + + void ResetRun(); + void BlockPendingRespawn(); + void AllowRespawn(); + void Respawn(); + void ScheduleRespawn(float delay); + } +} diff --git a/Assets/Scripts/Runtime/Gameplay/IPlayerController.cs.meta b/Assets/Scripts/Runtime/Gameplay/IPlayerController.cs.meta new file mode 100644 index 0000000..9c4bbe6 --- /dev/null +++ b/Assets/Scripts/Runtime/Gameplay/IPlayerController.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0b7a8f45ca6f47f40b9ed704d203af9a \ No newline at end of file diff --git a/Assets/Scripts/Runtime/Gameplay/JumpPlayerController.cs b/Assets/Scripts/Runtime/Gameplay/JumpPlayerController.cs index f5f3da1..267c3fb 100644 --- a/Assets/Scripts/Runtime/Gameplay/JumpPlayerController.cs +++ b/Assets/Scripts/Runtime/Gameplay/JumpPlayerController.cs @@ -16,7 +16,7 @@ namespace DanroJump.Gameplay /// [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(Collider2D))] - public sealed class JumpPlayerController : MonoBehaviour + public sealed class JumpPlayerController : MonoBehaviour, IPlayerController { [SerializeField] private float moveSpeed = 7.5f; [SerializeField] private float initialJumpVelocity = 15f; @@ -182,8 +182,10 @@ namespace DanroJump.Gameplay /// public bool IsDead { get; private set; } - public event System.Action Died; - public event System.Action Respawned; + public event System.Action Died; + public event System.Action Respawned; + + public Transform Transform => transform; /// /// Получает gameplay-камеру через SceneContext. diff --git a/Assets/Scripts/Runtime/Gameplay/VerticalCameraFollow.cs b/Assets/Scripts/Runtime/Gameplay/VerticalCameraFollow.cs index fa2e995..b4a76e4 100644 --- a/Assets/Scripts/Runtime/Gameplay/VerticalCameraFollow.cs +++ b/Assets/Scripts/Runtime/Gameplay/VerticalCameraFollow.cs @@ -18,9 +18,9 @@ namespace DanroJump.Gameplay /// Получает игрока через SceneContext. /// [Inject] - public void Construct(JumpPlayerController playerController) + public void Construct(IPlayerController playerController) { - target = playerController.transform; + target = playerController.Transform; } /// diff --git a/ProjectSettings/EditorSettings.asset b/ProjectSettings/EditorSettings.asset index c78fbbf..9c80174 100644 --- a/ProjectSettings/EditorSettings.asset +++ b/ProjectSettings/EditorSettings.asset @@ -27,7 +27,7 @@ EditorSettings: m_UnlockBlockShaders: 0 m_PrefabModeAllowAutoSave: 1 m_EnterPlayModeOptionsEnabled: 1 - m_EnterPlayModeOptions: 0 + m_EnterPlayModeOptions: 1 m_GameObjectNamingDigits: 1 m_GameObjectNamingScheme: 2 m_AssetNamingUsesSpace: 1