Decouple gameplay sessions and camera follow from concrete JumpPlayerController

- Создан интерфейс IPlayerController, абстрагирующий состояние и действия игрока.
- JumpPlayerController изменен для реализации интерфейса IPlayerController.
- GameplaySession и VerticalCameraFollow переведены на использование IPlayerController для ослабления связей.
- В GameplayInstaller добавлена регистрация зависимости IPlayerController в Zenject.
This commit is contained in:
Данил Ярош 2026-06-23 10:56:44 +03:00
parent d39d160d92
commit cbc49d4384
7 changed files with 39 additions and 11 deletions

View File

@ -28,6 +28,7 @@ namespace DanroJump.Gameplay
}
Container.BindInstance(player).AsSingle();
Container.Bind<IPlayerController>().FromInstance(player).AsSingle();
Container.BindInstance(gameplayCamera).AsSingle();
Container.BindInstance(platformSpawner).AsSingle();
Container.BindInstance(difficultyProgression).AsSingle();

View File

@ -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
/// <summary>
/// Фактическая текущая высота игрока над стартом.
/// </summary>
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;
/// <summary>
/// Максимальная высота, достигнутая в текущем забеге.
@ -100,7 +100,7 @@ namespace DanroJump.Gameplay
/// Создает сессию и подписывается на события смерти/respawn игрока.
/// </summary>
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
/// <summary>
/// Обновляет состояние сессии после смерти игрока.
/// </summary>
private void HandlePlayerDied(JumpPlayerController _)
private void HandlePlayerDied(IPlayerController _)
{
audioService?.Play(GameAudioEvent.PlayerDeath);
DeathCount++;
@ -249,7 +249,7 @@ namespace DanroJump.Gameplay
/// <summary>
/// Возвращает сессию в Running после respawn, если игра еще не закончена.
/// </summary>
private void HandlePlayerRespawned(JumpPlayerController _)
private void HandlePlayerRespawned(IPlayerController _)
{
if (State != GameplaySessionState.GameOver)
{

View File

@ -0,0 +1,23 @@
using UnityEngine;
namespace DanroJump.Gameplay
{
/// <summary>
/// Интерфейс управления игроком для ослабления связей и переиспользования логики сессий/камеры.
/// </summary>
public interface IPlayerController
{
event System.Action<IPlayerController> Died;
event System.Action<IPlayerController> Respawned;
Transform Transform { get; }
float HighestY { get; }
float DeathRespawnDelay { get; }
void ResetRun();
void BlockPendingRespawn();
void AllowRespawn();
void Respawn();
void ScheduleRespawn(float delay);
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b7a8f45ca6f47f40b9ed704d203af9a

View File

@ -16,7 +16,7 @@ namespace DanroJump.Gameplay
/// </summary>
[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
/// </summary>
public bool IsDead { get; private set; }
public event System.Action<JumpPlayerController> Died;
public event System.Action<JumpPlayerController> Respawned;
public event System.Action<IPlayerController> Died;
public event System.Action<IPlayerController> Respawned;
public Transform Transform => transform;
/// <summary>
/// Получает gameplay-камеру через SceneContext.

View File

@ -18,9 +18,9 @@ namespace DanroJump.Gameplay
/// Получает игрока через SceneContext.
/// </summary>
[Inject]
public void Construct(JumpPlayerController playerController)
public void Construct(IPlayerController playerController)
{
target = playerController.transform;
target = playerController.Transform;
}
/// <summary>

View File

@ -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