Danro/Assets/Scripts/UI/UICreditsTextController.cs
Danil Iarosh 4d05d1adbb
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
FEAT: Added new settings system
- Добавил новую систему настроек, возможности:
    - Динамически создает список настроек
    - Сохраняет настройки в JSON-файл
    - Возможность группировать настройки
    - Широкие возможности по кастомизации
    - Применение настроек в реальном времени (частично)
- Добавил префабы для новых элементов настроек
- Изменил поведение игры исходя из нового формата настроек
2026-02-04 14:32:15 +03:00

66 lines
2.1 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 RR.Game2D.Core.Managers;
using RR.Common.Settings;
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;
if (_settingsManager != null)
{
_settingsManager.OnSettingsLoaded += UpdateLivesIncreaseText;
_settingsManager.OnSettingsSaved += UpdateLivesIncreaseText;
}
}
private void OnDestroy()
{
if (_gameManager == null) _gameManager = GameManager.Instance;
if (_gameManager != null) _gameManager.MaxLivesChanged -= UpdateLivesText;
if (_settingsManager != null)
{
_settingsManager.OnSettingsLoaded -= UpdateLivesIncreaseText;
_settingsManager.OnSettingsSaved -= UpdateLivesIncreaseText;
}
}
private void UpdateLivesIncreaseText()
{
if (_settingsManager != null)
livesIncreaseText.text = string.Format(livesIncreaseString, _settingsManager.GetInt("gameplay.additionalLives"));
}
private void UpdateLivesText(int newLives)
{
livesText.text = string.Format(livesString, (object)newLives);
}
}
}