Project
This commit is contained in:
1 parent
e1a474d4ac
commit
24b1157026
164 files changed
+68527
No files matched your search
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class GameplayManager : MonoBehaviour
|
||||
{
|
||||
public static GameplayManager Instance { get; private set; }
|
||||
|
||||
private bool _onPause;
|
||||
public bool OnPause => _onPause;
|
||||
|
||||
[SerializeField] [Range(0f, 30f)] private float gameSpeed;
|
||||
|
||||
private float _currentGameSpeed;
|
||||
public float GameSpeed => _currentGameSpeed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
_currentGameSpeed = gameSpeed;
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
{
|
||||
ResetGame();
|
||||
ResumeGame();
|
||||
}
|
||||
public void PlayerDead()
|
||||
{
|
||||
PauseGame();
|
||||
}
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
_onPause = true;
|
||||
_currentGameSpeed = 0f;
|
||||
}
|
||||
public void ResumeGame()
|
||||
{
|
||||
_onPause = false;
|
||||
_currentGameSpeed = gameSpeed;
|
||||
}
|
||||
private void ResetGame()
|
||||
{
|
||||
PassingObjectsManager.Instance.ResetObjects();
|
||||
PlayerScoreService.Instance.ResetScore();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cdf72ee53f84d76ab57d0dcd7798e75
|
||||
timeCreated: 1777833499
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Alchemy.Inspector;
|
||||
using Code.PassingObjects;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class PassingObjectsManager : MonoBehaviour
|
||||
{
|
||||
[TabGroup("Spawn")] [SerializeField] private List<Transform> spawnPoints;
|
||||
[TabGroup("Spawn")] [SerializeField] private List<GameObject> prefabs;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float behindPlayerThreshold;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float obstacleCooldown;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private List<PassingObjectsPreset> obstaclesPresets;
|
||||
|
||||
private List<GameObject> _spawnedObjects = new();
|
||||
public float BehindPlayerThreshold => behindPlayerThreshold;
|
||||
public static PassingObjectsManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void ResetObjects()
|
||||
{
|
||||
foreach (var spawnedObject in _spawnedObjects)
|
||||
{
|
||||
Destroy(spawnedObject);
|
||||
}
|
||||
_spawnedObjects.Clear();
|
||||
_timer = 0f;
|
||||
}
|
||||
public void KillChild(PassingObject child)
|
||||
{
|
||||
if (!_spawnedObjects.Contains(child.gameObject)) return;
|
||||
|
||||
_spawnedObjects.Remove(child.gameObject);
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
private float _timer;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(GameplayManager.Instance.OnPause) return;
|
||||
|
||||
_timer += Time.deltaTime;
|
||||
|
||||
if (!(_timer > obstacleCooldown)) return;
|
||||
|
||||
_timer = 0f;
|
||||
|
||||
if (prefabs.Count == 0 && obstaclesPresets.Count > 0) return;
|
||||
|
||||
var presetId = Random.Range(0, obstaclesPresets.Count);
|
||||
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId1],
|
||||
spawnPoints[0].position,
|
||||
spawnPoints[0].rotation));
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId2],
|
||||
spawnPoints[1].position,
|
||||
spawnPoints[1].rotation));
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId3],
|
||||
spawnPoints[2].position,
|
||||
spawnPoints[2].rotation));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PassingObjectsPreset
|
||||
{
|
||||
public int prefabId1;
|
||||
public int prefabId2;
|
||||
public int prefabId3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95f7cf3ef95244ca9903d804eb9463d7
|
||||
timeCreated: 1777828525
|
||||
@@ -0,0 +1,37 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class PlayerScoreService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
|
||||
private int _score;
|
||||
|
||||
public static PlayerScoreService Instance { get; private set; }
|
||||
public int Score => _score;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void AddScore(int score)
|
||||
{
|
||||
_score += score;
|
||||
UpdateScoreTextWithScoreValue();
|
||||
}
|
||||
|
||||
private void UpdateScoreTextWithScoreValue()
|
||||
{
|
||||
scoreText.text = _score.ToString();
|
||||
}
|
||||
|
||||
public void ResetScore()
|
||||
{
|
||||
_score = 0;
|
||||
scoreText.text = _score.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e330c677aa54ef6a017e7bab9ebd104
|
||||
timeCreated: 1777831807
|
||||
Reference in new issue
Block a user