папочка навёл порядок в папках
This commit is contained in:
1 parent
9374a984e6
commit
b407380203
1123 files changed
+2764
-133233
No files matched your search
@@ -0,0 +1,130 @@
|
||||
|
||||
using Boxes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[Header("Ссылки на UI")]
|
||||
public TextMeshProUGUI timerText;
|
||||
public TextMeshProUGUI boxesText;
|
||||
public GameObject endGameScreen;
|
||||
public TextMeshProUGUI finalScoreText;
|
||||
|
||||
private int _boxesCollected;
|
||||
private float _timeAlive;
|
||||
private bool _isPlaying = true;
|
||||
private int _scoreMultiplier = 1;
|
||||
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null) Instance = this;
|
||||
else Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
GameEvents.OnBoxCollected += OnBoxCollected;
|
||||
GameEvents.OnPlayerDied += EndGame;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GameEvents.OnBoxCollected -= OnBoxCollected;
|
||||
GameEvents.OnPlayerDied -= EndGame;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_scoreMultiplier = 1;
|
||||
_timeAlive = 0f;
|
||||
_isPlaying = true;
|
||||
_boxesCollected = 0;
|
||||
|
||||
if (endGameScreen != null) endGameScreen.SetActive(false);
|
||||
|
||||
Time.timeScale = 1f;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!_isPlaying) return;
|
||||
_timeAlive += Time.deltaTime;
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void OnBoxCollected(BoxData boxData)
|
||||
{
|
||||
if (!_isPlaying) return;
|
||||
|
||||
switch (boxData.effectType)
|
||||
{
|
||||
case BoxData.BoxEffectType.AddScore:
|
||||
int addAmount = (int)boxData.effectValue * _scoreMultiplier;
|
||||
for(int i = 0; i < addAmount; i++)
|
||||
{
|
||||
_boxesCollected++;
|
||||
GameEvents.OnBoxAddedToTruck?.Invoke();
|
||||
}
|
||||
break;
|
||||
|
||||
case BoxData.BoxEffectType.LoseScore:
|
||||
int loseAmount = (int)boxData.effectValue;
|
||||
for(int i = 0; i < loseAmount; i++)
|
||||
{
|
||||
if (_boxesCollected > 0)
|
||||
{
|
||||
_boxesCollected--;
|
||||
GameEvents.OnBoxLostFromTruck?.Invoke();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BoxData.BoxEffectType.SpecialFurniture:
|
||||
|
||||
Debug.Log("Собрана мебель!");
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void SetScoreMultiplier(int multiplier)
|
||||
{
|
||||
_scoreMultiplier = multiplier;
|
||||
}
|
||||
|
||||
void UpdateUI()
|
||||
{
|
||||
if (timerText != null)
|
||||
{
|
||||
timerText.text = $"Время: {Mathf.FloorToInt(_timeAlive / 60):00}:{Mathf.FloorToInt(_timeAlive % 60):00}";
|
||||
}
|
||||
if (boxesText != null)
|
||||
{
|
||||
boxesText.text = $"Собрано: {_boxesCollected}";
|
||||
}
|
||||
}
|
||||
|
||||
void EndGame()
|
||||
{
|
||||
if (!_isPlaying) return;
|
||||
_isPlaying = false;
|
||||
|
||||
if (endGameScreen != null) endGameScreen.SetActive(true);
|
||||
if (finalScoreText != null)
|
||||
{
|
||||
finalScoreText.text = $"Вы собрали: {_boxesCollected} коробок!";
|
||||
}
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user