diff --git a/Assets/Resources/Managers/GameManager.prefab b/Assets/Resources/Managers/GameManager.prefab index 5223a31..321064a 100644 --- a/Assets/Resources/Managers/GameManager.prefab +++ b/Assets/Resources/Managers/GameManager.prefab @@ -10,8 +10,6 @@ GameObject: m_Component: - component: {fileID: 158905820630581587} - component: {fileID: 158905820630581586} - - component: {fileID: 158905820630581596} - - component: {fileID: 6316647355651322741} m_Layer: 0 m_Name: GameManager m_TagString: Untagged @@ -47,31 +45,3 @@ MonoBehaviour: m_EditorClassIdentifier: preStageUiPrefab: {fileID: 4994633962466276707, guid: 1f5ebc13237e070449ea8bc9e8b07ac8, type: 3} ---- !u!114 &158905820630581596 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 158905820630581597} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 308dfc6b26c3b422faf1717231fc888b, type: 3} - m_Name: - m_EditorClassIdentifier: - boardHolder: {fileID: 0} - startPosition: {fileID: 0} - indestructibleWallPrefab: {fileID: 5996206011854593075, guid: 84b92ac1e96d940bda97d1b1125887d7, - type: 3} ---- !u!114 &6316647355651322741 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 158905820630581597} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e64481d2e18e4b6ca4f22926a5061450, type: 3} - m_Name: - m_EditorClassIdentifier: diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index bae3c0f..ad67fe2 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -272,13 +272,11 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 158905820630581596, guid: fdaa7451ab31b477b930076bbc888bab, - type: 3} + - target: {fileID: 0} propertyPath: boardHolder value: objectReference: {fileID: 585332173} - - target: {fileID: 158905820630581596, guid: fdaa7451ab31b477b930076bbc888bab, - type: 3} + - target: {fileID: 0} propertyPath: startPosition value: objectReference: {fileID: 185746015} diff --git a/Assets/Scripts/src/Ammo/BombCameraShake.cs b/Assets/Scripts/src/Ammo/BombCameraShake.cs index f8066a2..49430fc 100644 --- a/Assets/Scripts/src/Ammo/BombCameraShake.cs +++ b/Assets/Scripts/src/Ammo/BombCameraShake.cs @@ -8,7 +8,7 @@ namespace src.Ammo { public class BombCameraShake : GameplayComponent { - private readonly BombsUtilManager _bombsUtilManager = BombsUtilManager.Instance; + private BombsUtilManager _bombsUtilManager; public float amplitudeGain = 3f; public float frequencyGain = 3f; @@ -18,6 +18,7 @@ namespace src.Ammo // Start is called before the first frame update private void Start() { + _bombsUtilManager = BombsUtilManager.instance; _virtualCamera = GetComponent(); _noiseMachine = _virtualCamera.GetCinemachineComponent(); } diff --git a/Assets/Scripts/src/Ammo/BombController.cs b/Assets/Scripts/src/Ammo/BombController.cs index 566044f..c527978 100644 --- a/Assets/Scripts/src/Ammo/BombController.cs +++ b/Assets/Scripts/src/Ammo/BombController.cs @@ -11,7 +11,7 @@ namespace src.Ammo public GameObject explosionPrefab; private BombCameraShake _cameraShake; - private readonly BombsUtilManager _bombsUtil = BombsUtilManager.Instance; + private readonly BombsUtilManager _bombsUtil = BombsUtilManager.instance; private bool _exploded; // Start is called before the first frame update diff --git a/Assets/Scripts/src/Ammo/BombsSpawner.cs b/Assets/Scripts/src/Ammo/BombsSpawner.cs index a0a4c72..64e62c0 100644 --- a/Assets/Scripts/src/Ammo/BombsSpawner.cs +++ b/Assets/Scripts/src/Ammo/BombsSpawner.cs @@ -1,4 +1,5 @@ -using src.Base; +using System; +using src.Base; using src.Managers; using UnityEngine; @@ -8,12 +9,18 @@ namespace src.Ammo { public GameObject bombPrefab; - private readonly BombsUtilManager _bombsUtil = BombsUtilManager.Instance; + private BombsUtilManager _bombsUtil; - public void PlaceBomb(Transform transform) + public void Start() { - var absX = Mathf.RoundToInt(transform.position.x); - var absY = Mathf.RoundToInt(transform.position.y); + _bombsUtil = BombsUtilManager.instance; + } + + public void PlaceBomb(Transform location) + { + var position1 = location.position; + var absX = Mathf.RoundToInt(position1.x); + var absY = Mathf.RoundToInt(position1.y); var position = new Vector2(absX, absY); if (_bombsUtil.CanPlaceBomb(position)) { diff --git a/Assets/Scripts/src/Ammo/Explosion.cs b/Assets/Scripts/src/Ammo/Explosion.cs index ec30d55..3d379a8 100644 --- a/Assets/Scripts/src/Ammo/Explosion.cs +++ b/Assets/Scripts/src/Ammo/Explosion.cs @@ -5,7 +5,7 @@ namespace src.Ammo { public class Explosion : GameplayComponent { - private readonly BombsUtilManager _bombUtil = BombsUtilManager.Instance; + private readonly BombsUtilManager _bombUtil = BombsUtilManager.instance; public void Start() { diff --git a/Assets/Scripts/src/Base/EnemyBase.cs b/Assets/Scripts/src/Base/EnemyBase.cs index ecd3469..4db57b5 100644 --- a/Assets/Scripts/src/Base/EnemyBase.cs +++ b/Assets/Scripts/src/Base/EnemyBase.cs @@ -6,10 +6,10 @@ using UnityEngine; namespace src.Base { - public abstract class EnemyBase : MonoBehaviour, IExplosable + public abstract class EnemyBase : GameplayComponent, IExplosable { private readonly Vector2[] _directions = {Vector3.up, Vector3.down, Vector3.left, Vector3.right}; - private readonly GameStateManager _gameStateManager = GameStateManager.Instance; + private readonly GameStateManager _gameStateManager = GameStateManager.instance; protected Rigidbody2D Rigidbody2d { get; set; } private Collider2D Collider2D { get; set; } diff --git a/Assets/Scripts/src/Base/UpgradeBase.cs b/Assets/Scripts/src/Base/UpgradeBase.cs index 5aa312e..75f74c2 100644 --- a/Assets/Scripts/src/Base/UpgradeBase.cs +++ b/Assets/Scripts/src/Base/UpgradeBase.cs @@ -6,13 +6,13 @@ namespace src.Base { public class UpgradeBase : GameplayComponent, IUpgrade { - protected GameManager GameManager; + protected GameManager gameManager; private UpgradeManager _upgradeManager; public void Start() { - GameManager = GameManager.Instance; - _upgradeManager = UpgradeManager.Instance; + gameManager = GameManager.instance; + _upgradeManager = UpgradeManager.instance; } public virtual void PerformUpgrade() diff --git a/Assets/Scripts/src/Helpers/ApplicationActions.cs b/Assets/Scripts/src/Helpers/ApplicationActions.cs index 39da0f5..0ed6dee 100644 --- a/Assets/Scripts/src/Helpers/ApplicationActions.cs +++ b/Assets/Scripts/src/Helpers/ApplicationActions.cs @@ -5,7 +5,7 @@ namespace src.Helpers { public static class ApplicationActions { - private static GameStateManager _gameStateManager = GameStateManager.Instance; + private static GameStateManager _gameStateManager = GameStateManager.instance; public static void QuitGame() { diff --git a/Assets/Scripts/src/Helpers/PrefabAtlas.cs b/Assets/Scripts/src/Helpers/PrefabAtlas.cs index 3ca7ae2..e77e429 100644 --- a/Assets/Scripts/src/Helpers/PrefabAtlas.cs +++ b/Assets/Scripts/src/Helpers/PrefabAtlas.cs @@ -4,6 +4,10 @@ namespace src.Helpers { public static class PrefabAtlas { + /* UI */ + public static readonly GameObject PreStageUi = + Resources.Load("UI/PreStageUI"); + /* Snow Walls */ public static readonly GameObject DestructibleHighSnow = Resources.Load("Walls/destructible_high_snow"); diff --git a/Assets/Scripts/src/Level/LevelManager.cs b/Assets/Scripts/src/Level/LevelManager.cs index 3ee9cbf..5b190d6 100644 --- a/Assets/Scripts/src/Level/LevelManager.cs +++ b/Assets/Scripts/src/Level/LevelManager.cs @@ -34,10 +34,10 @@ namespace src.Level } /* Used to group spawned objects */ - public Transform boardHolder; + private Transform _boardHolder; /* Holds the starting position of the player */ - public Transform startPosition; + private Transform _startPosition; /* Holds references to prefabs for the specified level. */ private GameObject _indestructibleWallPrefab; @@ -61,7 +61,14 @@ namespace src.Level private List _enemies; /* Singletons */ - private GameStateManager _gameStateManager = GameStateManager.Instance; + private GameStateManager _gameStateManager; + + public void Awake() + { + _startPosition = GameObject.Find("RespawnPosition").GetComponent(); + _boardHolder = GameObject.Find("Grid").GetComponent(); + _gameStateManager = GameStateManager.instance; + } public void SetLevelData(LevelData levelData) { @@ -115,9 +122,9 @@ namespace src.Level } /* We want to iterate over the X axis taking into consideration the startPosition's offset */ - for (var x = startPosition.position.x; x < Columns; x++) + for (var x = _startPosition.position.x; x < Columns; x++) { - for (var y = startPosition.position.y; y > Rows * -1; y--) + for (var y = _startPosition.position.y; y > Rows * -1; y--) { /* We want the following positions to be a safe zone. */ /* Don't place anything on starting position */ @@ -182,7 +189,7 @@ namespace src.Level var randomWall = _destructibleWallPrefabs.ChoseRandom(); var instance = Instantiate(randomWall, position, Quaternion.identity); _destructibleWalls.Add(instance); - instance.transform.SetParent(boardHolder); + instance.transform.SetParent(_boardHolder); } private bool PlaceIndestructibleTile(float x, float y) @@ -198,7 +205,7 @@ namespace src.Level var instance = Instantiate(_indestructibleWallPrefab, new Vector3(x, y, 0f), Quaternion.identity); - instance.transform.SetParent(boardHolder); + instance.transform.SetParent(_boardHolder); return true; } @@ -223,7 +230,7 @@ namespace src.Level DebugHelper.LogVerbose($"PlaceEnemy: x:{position.x} y:{position.y}"); var randomEnemy = _enemiesPrefab.ChoseRandom(); var instance = Instantiate(randomEnemy, position, Quaternion.identity); - instance.transform.SetParent(boardHolder); + instance.transform.SetParent(_boardHolder); _enemies.Add(instance); } diff --git a/Assets/Scripts/src/Managers/BombsUtilManager.cs b/Assets/Scripts/src/Managers/BombsUtilManager.cs index 3935c5d..2820176 100644 --- a/Assets/Scripts/src/Managers/BombsUtilManager.cs +++ b/Assets/Scripts/src/Managers/BombsUtilManager.cs @@ -1,9 +1,10 @@ using System.Collections.Generic; +using src.Base; using UnityEngine; namespace src.Managers { - public sealed class BombsUtilManager + public sealed class BombsUtilManager : GameplayComponent { private readonly HashSet _usedPosition = new HashSet(); @@ -20,12 +21,20 @@ namespace src.Managers public float ExplosionDuration { get; } = 0.55f; - private BombsUtilManager() + public static BombsUtilManager instance; + + public void Awake() { + if (instance == null) + { + instance = this; + } + else if (instance != null) + { + Destroy(gameObject); + } } - public static BombsUtilManager Instance { get; } = new BombsUtilManager(); - public void IncreasePower() { if (Power <= MaxPower) diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index cd68580..a925a9b 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -1,5 +1,4 @@ using System.Collections; -using src.Ammo; using src.Helpers; using src.Level; using src.Level.src.Level; @@ -10,23 +9,22 @@ namespace src.Managers { public class GameManager : MonoBehaviour { - public static GameManager Instance; + public static GameManager instance; + + // Inner Components + private PlayerController _playerController; + private GameStateManager _gameStateManager; private LevelManager _levelManager; private UpgradeManager _upgradeManager; private BombsUtilManager _bombsUtilManager; - // External Components - public GameObject preStageUiPrefab; - private PlayerController _playerController; - private readonly GameStateManager _gameStateManager = GameStateManager.Instance; - public void Awake() { - if (Instance == null) + if (instance == null) { - Instance = this; + instance = this; } - else if (Instance != null) + else if (instance != null) { Destroy(gameObject); } @@ -34,10 +32,12 @@ namespace src.Managers /* Don't destroy when reloading the scene */ DontDestroyOnLoad(gameObject); - // Load inner components - _levelManager = GetComponent(); - _upgradeManager = GetComponent(); - _bombsUtilManager = BombsUtilManager.Instance; + // Load singletons + _bombsUtilManager = gameObject.AddComponent(); + _gameStateManager = gameObject.AddComponent(); + _levelManager = gameObject.AddComponent(); + _upgradeManager = gameObject.AddComponent(); + gameObject.AddComponent(); // Load external components _playerController = GameObject.Find("Player").GetComponent(); @@ -72,7 +72,7 @@ namespace src.Managers private IEnumerator PreInitGame() { - var preStageUi = Instantiate(preStageUiPrefab); // Will destroy itself. + var preStageUi = Instantiate(PrefabAtlas.PreStageUi); // Will destroy itself. preStageUi.SetActive(true); yield return new WaitForSeconds(1f); Destroy(preStageUi); diff --git a/Assets/Scripts/src/Managers/GameStateManager.cs b/Assets/Scripts/src/Managers/GameStateManager.cs index 3533686..f45110d 100644 --- a/Assets/Scripts/src/Managers/GameStateManager.cs +++ b/Assets/Scripts/src/Managers/GameStateManager.cs @@ -1,12 +1,26 @@ +using src.Base; +using UnityEngine; + namespace src.Managers { - public class GameStateManager + public class GameStateManager : GameplayComponent { - public static GameStateManager Instance { get; } = new GameStateManager(); + public static GameStateManager instance; public bool IsGamePaused { get; internal set; } public bool IsPlayerMovementForbidden { get; internal set; } public int Level { get; private set; } = 1; - + + public void Awake() + { + if (instance == null) + { + instance = this; + } + else if (instance != null) + { + Destroy(gameObject); + } + } public void IncreaseLevel() { diff --git a/Assets/Scripts/src/Managers/UpgradeManager.cs b/Assets/Scripts/src/Managers/UpgradeManager.cs index 9469e1f..eb972a7 100644 --- a/Assets/Scripts/src/Managers/UpgradeManager.cs +++ b/Assets/Scripts/src/Managers/UpgradeManager.cs @@ -10,17 +10,17 @@ namespace src.Managers { public class UpgradeManager : GameplayComponent, IDynamicLevelData { - public static UpgradeManager Instance; + public static UpgradeManager instance; private List _unclaimedUpgrades = new List(); private GameObject[] _upgradePrefabs; private void Awake() { - if (Instance == null) + if (instance == null) { - Instance = this; + instance = this; } - else if (Instance != null) + else if (instance != null) { Destroy(gameObject); } diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 45e3d27..e3e4bbb 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -8,7 +8,7 @@ namespace src.Player { public class PlayerController : GameplayComponent, IExplosable { - private readonly GameStateManager _gameStateManager = GameStateManager.Instance; + private GameStateManager _gameStateManager; private Rigidbody2D _rigidbody2d; private Collider2D _collider2D; private Transform _respawnPosition; @@ -25,14 +25,16 @@ namespace src.Player private bool _isDead; protected void Start() - { + { + _gameStateManager = GameStateManager.instance; + _playerUpgrade = PlayerUpgrade.instance; + _rigidbody2d = GetComponent(); _collider2D = GetComponent(); _animator = GetComponentInChildren(); _respawnPosition = GameObject.Find("RespawnPosition").transform; _bombsSpawner = GameObject.Find("BombSpawner").GetComponent(); - - _playerUpgrade = PlayerUpgrade.Instance; + movementSpeed = _playerUpgrade.GetMovementSpeed(); _playerUpgrade.PlayerSpeed += OnSpeedUpgrade; diff --git a/Assets/Scripts/src/Player/PlayerUpgrade.cs b/Assets/Scripts/src/Player/PlayerUpgrade.cs index 8a3d369..a98ae1e 100644 --- a/Assets/Scripts/src/Player/PlayerUpgrade.cs +++ b/Assets/Scripts/src/Player/PlayerUpgrade.cs @@ -1,16 +1,25 @@ +using src.Base; + namespace src.Player { - public class PlayerUpgrade + public class PlayerUpgrade : GameplayComponent { public delegate void IncreaseSpeedDelegate(float speed); - public static PlayerUpgrade Instance = new PlayerUpgrade(); + public static PlayerUpgrade instance; public event IncreaseSpeedDelegate PlayerSpeed; public const float MaxPlayerSpeed = 8f; private float _movementSpeed = 4f; - private PlayerUpgrade() + public void Awake() { - + if (instance == null) + { + instance = this; + } + else if (instance != null) + { + Destroy(gameObject); + } } public float GetMovementSpeed() @@ -25,7 +34,7 @@ namespace src.Player return; } _movementSpeed += speed; - PlayerSpeed.Invoke(speed); + PlayerSpeed?.Invoke(speed); } } } \ No newline at end of file diff --git a/Assets/Scripts/src/UI/PreStageUiScript.cs b/Assets/Scripts/src/UI/PreStageUiScript.cs index d05826e..b8061f1 100644 --- a/Assets/Scripts/src/UI/PreStageUiScript.cs +++ b/Assets/Scripts/src/UI/PreStageUiScript.cs @@ -7,7 +7,7 @@ namespace src.UI { public class PreStageUiScript : GameplayComponent { - private readonly GameStateManager _gameStateManager = GameStateManager.Instance; + private readonly GameStateManager _gameStateManager = GameStateManager.instance; private Text _stageText; public void Start() diff --git a/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs b/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs index 9402172..b46e361 100644 --- a/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/BombFlamesUpgrade.cs @@ -6,7 +6,7 @@ namespace src.Upgrade { public override void PerformUpgrade() { - var bombManager = GameManager.GetBombsUtilManager(); + var bombManager = gameManager.GetBombsUtilManager(); bombManager.IncreasePower(); } } diff --git a/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs b/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs index 89497ab..39b16ad 100644 --- a/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/BombPlacementUpgrade.cs @@ -6,7 +6,7 @@ namespace src.Upgrade { public override void PerformUpgrade() { - var bombManager = GameManager.GetBombsUtilManager(); + var bombManager = gameManager.GetBombsUtilManager(); bombManager.IncreaseAllowedBombs(); } } diff --git a/Assets/Scripts/src/Upgrade/GoldenBombUpgrade.cs b/Assets/Scripts/src/Upgrade/GoldenBombUpgrade.cs index afb993e..acf0bff 100644 --- a/Assets/Scripts/src/Upgrade/GoldenBombUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/GoldenBombUpgrade.cs @@ -7,7 +7,7 @@ namespace src.Upgrade { public override void PerformUpgrade() { - var bombManager = GameManager.GetBombsUtilManager(); + var bombManager = gameManager.GetBombsUtilManager(); bombManager.IncreaseAllowedBombs(); bombManager.IncreasePower(); } diff --git a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs index 013a47b..94558e0 100644 --- a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs @@ -7,7 +7,7 @@ namespace src.Upgrade { public override void PerformUpgrade() { - var player = PlayerUpgrade.Instance; + var player = PlayerUpgrade.instance; player.IncreaseSpeed(.5f); } } diff --git a/Assets/Scripts/src/Wall/DestructibleWall.cs b/Assets/Scripts/src/Wall/DestructibleWall.cs index d27663e..54f26b1 100644 --- a/Assets/Scripts/src/Wall/DestructibleWall.cs +++ b/Assets/Scripts/src/Wall/DestructibleWall.cs @@ -18,7 +18,7 @@ namespace src.Wall private void Start() { - _upgradeManager = GameManager.Instance.GetUpgradeManager(); + _upgradeManager = GameManager.instance.GetUpgradeManager(); _animator = GetComponentInChildren(); // _animator.speed = 0; } diff --git a/Assets/Scripts/src/Wall/ExitDoor.cs b/Assets/Scripts/src/Wall/ExitDoor.cs index 07709d4..b0d0444 100644 --- a/Assets/Scripts/src/Wall/ExitDoor.cs +++ b/Assets/Scripts/src/Wall/ExitDoor.cs @@ -12,7 +12,7 @@ namespace src.Wall private void Start() { - _gameManager = GameManager.Instance; + _gameManager = GameManager.instance; _collider2D = GetComponent(); }