Danro/Assets/Scripts/UI/TopPanelTextController.cs
Danil Iarosh 152066e9a3 feat(game): implement win/lose events and UI updates- Added GameOverEvent and GameWonEvent with total play time
- Updated ContinueGame method to reset lives and coins- Modified GameOver and GameWin methods to invoke events
- Adjusted stage count per world from5 to 3
- Added win banner UI with header text and layout changes
- Updated canvas elements positioning and sizing
- Included new UI elements for win/lose states- Reorganized UI hierarchy in Level UI scene
- Added menu and continue buttons in win panel
- Fixed text components naming and alignment
- Added game start time tracking for play duration
2025-10-31 17:03:20 +03:00

60 lines
1.7 KiB
C#

using UnityEngine;
using TMPro;
using RR.Game2D.Core.Managers;
namespace RR.Common.UI
{
public class TopPanelTextController : MonoBehaviour
{
[SerializeField] private int livesCount;
[SerializeField] private int coinsCount;
[SerializeField] private string levelNumber;
[SerializeField] private TextMeshProUGUI livesText;
[SerializeField] private TextMeshProUGUI coinsText;
[SerializeField] private TextMeshProUGUI levelText;
private void OnEnable()
{
if (GameManager.Instance != null)
{
GameManager.Instance.CoinsChanged += OnCoinsChanged;
GameManager.Instance.LivesChanged += OnLivesChanged;
}
}
private void OnDisable()
{
if (GameManager.Instance != null)
{
GameManager.Instance.CoinsChanged -= OnCoinsChanged;
GameManager.Instance.LivesChanged -= OnLivesChanged;
}
}
void Start()
{
livesCount = GameManager.Instance.Lives;
coinsCount = GameManager.Instance.Coins;
levelNumber = $"{GameManager.Instance.World}-{GameManager.Instance.Stage}";
livesText.text = livesCount.ToString();
coinsText.text = coinsCount.ToString();
levelText.text = levelNumber;
}
private void OnCoinsChanged(int newCoins)
{
if (coinsCount != newCoins)
{
coinsCount = newCoins;
coinsText.text = coinsCount.ToString();
}
}
private void OnLivesChanged(int newLives)
{
livesText.text = newLives.ToString();
}
}
}