refactor: extract GameUiCoordinator from GameBootstrap
This commit is contained in:
@@ -2,7 +2,6 @@ using System.Collections;
|
|||||||
using Core.Domain;
|
using Core.Domain;
|
||||||
using Core.Domain.Status.Effects;
|
using Core.Domain.Status.Effects;
|
||||||
using Core.Ports;
|
using Core.Ports;
|
||||||
using TMPro;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
@@ -23,12 +22,7 @@ namespace Infrastructure.Unity
|
|||||||
[SerializeField] private HunterNpcController hunterNpcPrefab;
|
[SerializeField] private HunterNpcController hunterNpcPrefab;
|
||||||
[SerializeField] private FloorVisibilityManager floorVisibilityManager;
|
[SerializeField] private FloorVisibilityManager floorVisibilityManager;
|
||||||
|
|
||||||
[Header("Ui")]
|
[SerializeField] private GameUiCoordinator uiCoordinator;
|
||||||
[SerializeField] private TMP_Text scoreText;
|
|
||||||
[SerializeField] private TMP_Text highScoreText;
|
|
||||||
[SerializeField] private GameObject gameOverUi;
|
|
||||||
[SerializeField] private GameObject pauseUi;
|
|
||||||
[SerializeField] private GameObject startScreenUi;
|
|
||||||
|
|
||||||
[Header("Settings")]
|
[Header("Settings")]
|
||||||
[SerializeField] private float restartTime = 3f;
|
[SerializeField] private float restartTime = 3f;
|
||||||
@@ -44,11 +38,11 @@ namespace Infrastructure.Unity
|
|||||||
private GameObject _currentOrbInstance;
|
private GameObject _currentOrbInstance;
|
||||||
private bool _isGameRunning;
|
private bool _isGameRunning;
|
||||||
private int _currentPlayerFloorIndex;
|
private int _currentPlayerFloorIndex;
|
||||||
private int _currentDisplayedScore;
|
|
||||||
private float _inputBlockTimer;
|
private float _inputBlockTimer;
|
||||||
private bool _isPaused;
|
private bool _isPaused;
|
||||||
private bool _levelGenerated;
|
private bool _levelGenerated;
|
||||||
|
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
_actions = new InputSystem_Actions();
|
_actions = new InputSystem_Actions();
|
||||||
@@ -88,18 +82,16 @@ namespace Infrastructure.Unity
|
|||||||
SpawnDeathPlane();
|
SpawnDeathPlane();
|
||||||
SpawnPlayer();
|
SpawnPlayer();
|
||||||
|
|
||||||
if (gameOverUi) gameOverUi.SetActive(false);
|
uiCoordinator?.ShowStartScreen();
|
||||||
if (startScreenUi) startScreenUi.SetActive(true); // Show start screen NOW
|
uiCoordinator?.UpdateHighScore(_gameSession.HighScore);
|
||||||
|
|
||||||
WireEvents();
|
WireEvents();
|
||||||
UpdateScoreUi(_gameSession.Score);
|
|
||||||
|
|
||||||
_levelGenerated = true;
|
_levelGenerated = true;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameOverUi) gameOverUi.SetActive(false);
|
uiCoordinator?.ShowStartScreen();
|
||||||
if (startScreenUi) startScreenUi.SetActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
@@ -172,14 +164,14 @@ namespace Infrastructure.Unity
|
|||||||
{
|
{
|
||||||
Time.timeScale = 0f;
|
Time.timeScale = 0f;
|
||||||
if (soundManager) soundManager.SetPaused(true);
|
if (soundManager) soundManager.SetPaused(true);
|
||||||
if (pauseUi) pauseUi.SetActive(true);
|
uiCoordinator?.ShowPauseUi();
|
||||||
if (rumbleManager) rumbleManager.SetPaused(true);
|
if (rumbleManager) rumbleManager.SetPaused(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Time.timeScale = 1f;
|
Time.timeScale = 1f;
|
||||||
if (soundManager) soundManager.SetPaused(false);
|
if (soundManager) soundManager.SetPaused(false);
|
||||||
if (pauseUi) pauseUi.SetActive(false);
|
uiCoordinator?.HidePauseUi();
|
||||||
if (rumbleManager) rumbleManager.SetPaused(false);
|
if (rumbleManager) rumbleManager.SetPaused(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,34 +199,6 @@ namespace Infrastructure.Unity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateScoreUi(int newScore)
|
|
||||||
{
|
|
||||||
if (!scoreText) return;
|
|
||||||
|
|
||||||
LeanTween.cancel(scoreText.gameObject);
|
|
||||||
|
|
||||||
scoreText.rectTransform.localScale = Vector3.one;
|
|
||||||
LeanTween.scale(scoreText.rectTransform, Vector3.one * 1.5f, 0.5f)
|
|
||||||
.setEasePunch();
|
|
||||||
|
|
||||||
LeanTween.value(scoreText.gameObject, (float val) =>
|
|
||||||
{
|
|
||||||
var currentVal = Mathf.RoundToInt(val);
|
|
||||||
|
|
||||||
var combo = _gameSession?.ComboMultiplier ?? 1;
|
|
||||||
var comboText = combo > 1 ? $" <color=yellow>x{combo}</color>" : "";
|
|
||||||
|
|
||||||
scoreText.text = $"{currentVal}{comboText}";
|
|
||||||
}, _currentDisplayedScore, newScore, 0.5f)
|
|
||||||
.setEaseOutExpo();
|
|
||||||
|
|
||||||
_currentDisplayedScore = newScore;
|
|
||||||
|
|
||||||
if (highScoreText && _gameSession != null)
|
|
||||||
highScoreText.text = $"BEST: {_gameSession.HighScore}";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SpawnPlayer()
|
private void SpawnPlayer()
|
||||||
{
|
{
|
||||||
var spawnPos = new Vector3(0f, 5f, 0f);
|
var spawnPos = new Vector3(0f, 5f, 0f);
|
||||||
@@ -268,8 +232,6 @@ namespace Infrastructure.Unity
|
|||||||
_isGameRunning = false;
|
_isGameRunning = false;
|
||||||
|
|
||||||
if (beatPulseController) beatPulseController.StopTracking();
|
if (beatPulseController) beatPulseController.StopTracking();
|
||||||
|
|
||||||
if (gameOverUi) gameOverUi.SetActive(true);
|
|
||||||
|
|
||||||
StartCoroutine(RestartRoutine());
|
StartCoroutine(RestartRoutine());
|
||||||
}
|
}
|
||||||
@@ -283,7 +245,7 @@ namespace Infrastructure.Unity
|
|||||||
|
|
||||||
private void WireEvents()
|
private void WireEvents()
|
||||||
{
|
{
|
||||||
_gameSession.OnScoreChanged += UpdateScoreUi;
|
uiCoordinator?.Subscribe(_gameSession);
|
||||||
_gameSession.OnOrbSpawned += SpawnVisualOrb;
|
_gameSession.OnOrbSpawned += SpawnVisualOrb;
|
||||||
_gameSession.OnOrbReset += HandleOrbReset;
|
_gameSession.OnOrbReset += HandleOrbReset;
|
||||||
_gameSession.OnGameOver += HandleGameOver;
|
_gameSession.OnGameOver += HandleGameOver;
|
||||||
@@ -340,9 +302,8 @@ namespace Infrastructure.Unity
|
|||||||
private void StartGameSequence()
|
private void StartGameSequence()
|
||||||
{
|
{
|
||||||
_isGameRunning = true;
|
_isGameRunning = true;
|
||||||
_currentDisplayedScore = 0;
|
|
||||||
|
uiCoordinator?.HideStartScreen();
|
||||||
if (startScreenUi) startScreenUi.SetActive(false);
|
|
||||||
|
|
||||||
if (soundManager)
|
if (soundManager)
|
||||||
{
|
{
|
||||||
|
|||||||
79
Assets/Scripts/Infrastructure/Unity/GameUiCoordinator.cs
Normal file
79
Assets/Scripts/Infrastructure/Unity/GameUiCoordinator.cs
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
using Core.Domain;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Infrastructure.Unity
|
||||||
|
{
|
||||||
|
public class GameUiCoordinator : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("References")]
|
||||||
|
[SerializeField] private TMP_Text scoreText;
|
||||||
|
[SerializeField] private TMP_Text highScoreText;
|
||||||
|
[SerializeField] private GameObject gameOverUi;
|
||||||
|
[SerializeField] private GameObject pauseUi;
|
||||||
|
[SerializeField] private GameObject startScreenUi;
|
||||||
|
|
||||||
|
private GameSession _session;
|
||||||
|
private int _currentDisplayedScore;
|
||||||
|
|
||||||
|
public void Subscribe(GameSession session)
|
||||||
|
{
|
||||||
|
_session = session;
|
||||||
|
session.OnScoreChanged += UpdateScore;
|
||||||
|
session.OnGameOver += ShowGameOverUi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowStartScreen()
|
||||||
|
{
|
||||||
|
if (gameOverUi) gameOverUi.SetActive(false);
|
||||||
|
if (startScreenUi) startScreenUi.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideStartScreen()
|
||||||
|
{
|
||||||
|
if (startScreenUi) startScreenUi.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowGameOverUi()
|
||||||
|
{
|
||||||
|
if (gameOverUi) gameOverUi.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowPauseUi()
|
||||||
|
{
|
||||||
|
if (pauseUi) pauseUi.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HidePauseUi()
|
||||||
|
{
|
||||||
|
if (pauseUi) pauseUi.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateHighScore(int highScore)
|
||||||
|
{
|
||||||
|
if (highScoreText) highScoreText.text = $"BEST: {highScore}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateScore(int newScore)
|
||||||
|
{
|
||||||
|
if (!scoreText) return;
|
||||||
|
|
||||||
|
LeanTween.cancel(scoreText.gameObject);
|
||||||
|
scoreText.rectTransform.localScale = Vector3.one;
|
||||||
|
LeanTween.scale(scoreText.rectTransform, Vector3.one * 1.5f, 0.5f).setEasePunch();
|
||||||
|
|
||||||
|
LeanTween.value(scoreText.gameObject, (float val) =>
|
||||||
|
{
|
||||||
|
var combo = _session?.ComboMultiplier ?? 1;
|
||||||
|
var comboText = combo > 1 ? $" <color=yellow>x{combo}</color>" : "";
|
||||||
|
scoreText.text = $"{Mathf.RoundToInt(val)}{comboText}";
|
||||||
|
}, _currentDisplayedScore, newScore, 0.5f)
|
||||||
|
.setEaseOutExpo();
|
||||||
|
|
||||||
|
_currentDisplayedScore = newScore;
|
||||||
|
|
||||||
|
if (highScoreText && _session != null)
|
||||||
|
highScoreText.text = $"BEST: {_session.HighScore}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user