Что я сдал
This commit is contained in:
1 parent
24b1157026
commit
a5665f0101
2838 files changed
+129953
-1304
No files matched your search
@@ -0,0 +1,64 @@
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class BonusService : MonoBehaviour
|
||||
{
|
||||
public static BonusService Instance { get; private set; }
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public bool CoinBoost { get; private set; }
|
||||
public bool Invincibility { get; private set; }
|
||||
|
||||
|
||||
private CancellationTokenSource _coinBoostCancellationTokenSource;
|
||||
|
||||
public async UniTaskVoid GiveCoinBoost()
|
||||
{
|
||||
if (_coinBoostCancellationTokenSource != null && _coinBoostCancellationTokenSource.Token.CanBeCanceled)
|
||||
_coinBoostCancellationTokenSource.Cancel();
|
||||
|
||||
_coinBoostCancellationTokenSource = new();
|
||||
try
|
||||
{
|
||||
CoinBoost = true;
|
||||
|
||||
await UniTask.WaitForSeconds(5f)
|
||||
.AttachExternalCancellation(_coinBoostCancellationTokenSource.Token);
|
||||
|
||||
CoinBoost = false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_coinBoostCancellationTokenSource.Dispose();
|
||||
}
|
||||
}
|
||||
private CancellationTokenSource _invincibilityCancellationTokenSource;
|
||||
|
||||
public async UniTaskVoid GiveInvincibility()
|
||||
{
|
||||
if (_invincibilityCancellationTokenSource != null && _invincibilityCancellationTokenSource.Token.CanBeCanceled)
|
||||
_invincibilityCancellationTokenSource.Cancel();
|
||||
|
||||
_invincibilityCancellationTokenSource = new();
|
||||
try
|
||||
{
|
||||
Invincibility = true;
|
||||
|
||||
await UniTask.WaitForSeconds(5f)
|
||||
.AttachExternalCancellation(_invincibilityCancellationTokenSource.Token);
|
||||
|
||||
Invincibility = false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_invincibilityCancellationTokenSource.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8b67c863184e58b33bd510cda6493c
|
||||
timeCreated: 1777906697
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cdf72ee53f84d76ab57d0dcd7798e75
|
||||
timeCreated: 1777833499
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -5
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,39 @@ using Random = UnityEngine.Random;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
// [OnListViewChanged(
|
||||
// OnItemChanged = nameof(OnPassingObjectsPresetsChanged),
|
||||
// OnItemsAdded = nameof(OnPassingObjectsPresetsAdded),
|
||||
// OnItemsRemoved = nameof(OnPassingObjectsPresetsRemoved),
|
||||
// OnSelectedIndicesChanged = nameof(OnPassingObjectsPresetsIndicesChanged),
|
||||
// OnItemIndexChanged = nameof(OnPassingObjectsPresetsIndexChanged))
|
||||
// ]
|
||||
// public float[] array;
|
||||
//
|
||||
// void OnPassingObjectsPresetsChanged(int index, PassingObjectsPreset item)
|
||||
// {
|
||||
// Debug.Log($"Changed: [{index}] -> {item}");
|
||||
// }
|
||||
//
|
||||
// void OnPassingObjectsPresetsAdded(IEnumerable<int> indices)
|
||||
// {
|
||||
// Debug.Log($"Added: [{string.Join(',', indices)}]");
|
||||
// }
|
||||
//
|
||||
// void OnPassingObjectsPresetsRemoved(IEnumerable<int> indices)
|
||||
// {
|
||||
// Debug.Log($"Removed: [{string.Join(',', indices)}]");
|
||||
// }
|
||||
//
|
||||
// void OnPassingObjectsPresetsIndicesChanged(IEnumerable<int> indices)
|
||||
// {
|
||||
// Debug.Log($"Selected: [{string.Join(',', indices)}]");
|
||||
// }
|
||||
//
|
||||
// void OnPassingObjectsPresetsIndexChanged(int before, int after)
|
||||
// {
|
||||
// Debug.Log($"Index Changed: [{before} -> {after}]");
|
||||
// }
|
||||
public class PassingObjectsManager : MonoBehaviour
|
||||
{
|
||||
[TabGroup("Spawn")] [SerializeField] private List<Transform> spawnPoints;
|
||||
@@ -18,9 +51,43 @@ namespace Code.GameplayServices
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float obstacleCooldown;
|
||||
|
||||
[OnListViewChanged(
|
||||
OnItemChanged = nameof(OnPassingObjectsPresetsChanged),
|
||||
OnItemsAdded = nameof(OnPassingObjectsPresetsAdded),
|
||||
OnItemsRemoved = nameof(OnPassingObjectsPresetsRemoved),
|
||||
OnSelectedIndicesChanged = nameof(OnPassingObjectsPresetsIndicesChanged),
|
||||
OnItemIndexChanged = nameof(OnPassingObjectsPresetsIndexChanged))
|
||||
]
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private List<PassingObjectsPreset> obstaclesPresets;
|
||||
|
||||
|
||||
void OnPassingObjectsPresetsChanged(int index, PassingObjectsPreset item)
|
||||
{
|
||||
float totalChance = 0f;
|
||||
for (var i = 0; i < obstaclesPresets.Count; i++)
|
||||
{
|
||||
if (i == index) continue;
|
||||
totalChance += obstaclesPresets[i].chance;
|
||||
}
|
||||
|
||||
if(item.chance > 1 - totalChance) item.chance = 1 - totalChance;
|
||||
}
|
||||
|
||||
void OnPassingObjectsPresetsAdded(IEnumerable<int> indices)
|
||||
{
|
||||
}
|
||||
|
||||
void OnPassingObjectsPresetsRemoved(IEnumerable<int> indices)
|
||||
{
|
||||
}
|
||||
|
||||
void OnPassingObjectsPresetsIndicesChanged(IEnumerable<int> indices)
|
||||
{
|
||||
}
|
||||
|
||||
void OnPassingObjectsPresetsIndexChanged(int before, int after)
|
||||
{
|
||||
}
|
||||
private List<GameObject> _spawnedObjects = new();
|
||||
public float BehindPlayerThreshold => behindPlayerThreshold;
|
||||
public static PassingObjectsManager Instance { get; private set; }
|
||||
@@ -62,6 +129,7 @@ namespace Code.GameplayServices
|
||||
if (prefabs.Count == 0 && obstaclesPresets.Count > 0) return;
|
||||
|
||||
var presetId = Random.Range(0, obstaclesPresets.Count);
|
||||
var chance = Random.Range(0,1f);
|
||||
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
@@ -87,5 +155,7 @@ namespace Code.GameplayServices
|
||||
public int prefabId1;
|
||||
public int prefabId2;
|
||||
public int prefabId3;
|
||||
[Range(0,1f)]
|
||||
public float chance;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95f7cf3ef95244ca9903d804eb9463d7
|
||||
timeCreated: 1777828525
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -10
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -5,10 +7,21 @@ namespace Code.GameplayServices
|
||||
{
|
||||
public class PlayerScoreService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
|
||||
private int _score;
|
||||
[SerializeField] private ScoreTable scoreTable;
|
||||
|
||||
public void ShowScoreTable()
|
||||
{
|
||||
scoreTable.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
[SerializeField] private TMP_Text playerNameText;
|
||||
|
||||
private List<ScoreData> _scores = new();
|
||||
public List<ScoreData> Scores => _scores;
|
||||
private int _score;
|
||||
private string _playerName;
|
||||
|
||||
public static PlayerScoreService Instance { get; private set; }
|
||||
public int Score => _score;
|
||||
|
||||
@@ -19,7 +32,7 @@ namespace Code.GameplayServices
|
||||
|
||||
public void AddScore(int score)
|
||||
{
|
||||
_score += score;
|
||||
_score += BonusService.Instance.CoinBoost ? score * 2 : score;
|
||||
UpdateScoreTextWithScoreValue();
|
||||
}
|
||||
|
||||
@@ -30,8 +43,30 @@ namespace Code.GameplayServices
|
||||
|
||||
public void ResetScore()
|
||||
{
|
||||
_scores.Add(new ScoreData(_playerName, _score));
|
||||
|
||||
_score = 0;
|
||||
// _playerName = string.Empty;
|
||||
|
||||
scoreText.text = _score.ToString();
|
||||
}
|
||||
|
||||
public void SetPlayerName(string playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
playerNameText.text = _playerName;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ScoreData
|
||||
{
|
||||
public string name;
|
||||
public int score;
|
||||
|
||||
public ScoreData(string name, int score)
|
||||
{
|
||||
this.name = name;
|
||||
this.score = score;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e330c677aa54ef6a017e7bab9ebd104
|
||||
timeCreated: 1777831807
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -20
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user