Что я сдал
This commit is contained in:
1 parent
24b1157026
commit
a5665f0101
2838 files changed
+129953
-1304
No files matched your search
@@ -1,3 +1,8 @@
|
||||
using System.Threading;
|
||||
using Alchemy.Inspector;
|
||||
using Code.Audio;
|
||||
using Code.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
@@ -6,13 +11,21 @@ namespace Code.GameplayServices
|
||||
{
|
||||
public static GameplayManager Instance { get; private set; }
|
||||
|
||||
private bool _onPause;
|
||||
private bool _onPause = true;
|
||||
public bool OnPause => _onPause;
|
||||
|
||||
[TabGroup("Gameplay")]
|
||||
[SerializeField] [Range(0f, 30f)] private float gameSpeed;
|
||||
[TabGroup("Gameplay")]
|
||||
[SerializeField] [Range(0f, 30f)] private float gameSpeedIncrement;
|
||||
|
||||
[TabGroup("UI")]
|
||||
[SerializeField]
|
||||
private RestartPanel restartPanel;
|
||||
|
||||
private float _currentGameSpeed;
|
||||
public float GameSpeed => _currentGameSpeed;
|
||||
private float _incrementedGameSpeed;
|
||||
public float GameSpeed => _currentGameSpeed > 0.1f ? _currentGameSpeed + _incrementedGameSpeed : _currentGameSpeed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -25,25 +38,51 @@ namespace Code.GameplayServices
|
||||
ResetGame();
|
||||
ResumeGame();
|
||||
}
|
||||
public void PlayerDead()
|
||||
public void PlayerDied()
|
||||
{
|
||||
PauseGame();
|
||||
restartPanel.gameObject.SetActive(true);
|
||||
PlayerScoreService.Instance.ResetScore();
|
||||
AudioManager.Instance.PlayGameOver();
|
||||
}
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
_onPause = true;
|
||||
_currentGameSpeed = 0f;
|
||||
AudioManager.Instance.StopMusic();
|
||||
_cycleTokenSource.Cancel();
|
||||
}
|
||||
public void ResumeGame()
|
||||
{
|
||||
_onPause = false;
|
||||
_currentGameSpeed = gameSpeed;
|
||||
AudioManager.Instance.StartMusic();
|
||||
DifficultyCycle().Forget();
|
||||
}
|
||||
|
||||
private void ResetGame()
|
||||
{
|
||||
_incrementedGameSpeed = 0f;
|
||||
PassingObjectsManager.Instance.ResetObjects();
|
||||
PlayerScoreService.Instance.ResetScore();
|
||||
}
|
||||
|
||||
private CancellationTokenSource _cycleTokenSource;
|
||||
private async UniTaskVoid DifficultyCycle()
|
||||
{
|
||||
_cycleTokenSource = new();
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
await UniTask.WaitForSeconds(10).AttachExternalCancellation(_cycleTokenSource.Token);
|
||||
_incrementedGameSpeed += gameSpeedIncrement;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_cycleTokenSource.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user