Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
- Добавил новую систему настроек, возможности:
- Динамически создает список настроек
- Сохраняет настройки в JSON-файл
- Возможность группировать настройки
- Широкие возможности по кастомизации
- Применение настроек в реальном времени (частично)
- Добавил префабы для новых элементов настроек
- Изменил поведение игры исходя из нового формата настроек
66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
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);
|
||
}
|
||
}
|
||
} |