Danro/Assets/Scripts/UI/UICreditsTextController.cs

57 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using RR.Common.Managers;
using RR.Game2D.Core.Managers;
using TMPro;
using UnityEngine;
namespace RR.Common.UI
{
public class UICreditsTextController : MonoBehaviour
{
// UI elements
[SerializeField] private TextMeshProUGUI livesIncreaseText;
[SerializeField] private TextMeshProUGUI livesText;
// Strings to display
[SerializeField] private string livesIncreaseString = "{0}";
[SerializeField] private string livesString = "У вас будет {0}";
private GameManager _gameManager;
private SettingsManager _settingsManager;
private void Start()
{
_gameManager = GameManager.Instance;
if (_gameManager == null) return;
_settingsManager = _gameManager.Settings;
if (_settingsManager == null) _settingsManager = SettingsManager.Instance;
UpdateLivesText(_gameManager.MaxLives);
UpdateLivesIncreaseText();
_gameManager.MaxLivesChanged += (UpdateLivesText);
_gameManager.Settings.OnSettingsLoaded += UpdateLivesIncreaseText;
_gameManager.Settings.OnSettingsSaved += UpdateLivesIncreaseText;
}
private void OnDestroy()
{
if (_gameManager == null) _gameManager = GameManager.Instance;
if (_gameManager != null) _gameManager.MaxLivesChanged -= UpdateLivesText;
}
private void UpdateLivesIncreaseText()
{
livesIncreaseText.text = string.Format(livesIncreaseString, _settingsManager.GetCurrentGameSettings().livesIncreasedByCredits);
}
private void UpdateLivesText(int newLives)
{
livesText.text = string.Format(livesString, newLives);
}
}
}