diff --git a/.build/Build/.build.data.gz b/.build/Build/.build.data.gz index 2af29a06..10e723c0 100644 Binary files a/.build/Build/.build.data.gz and b/.build/Build/.build.data.gz differ diff --git a/.build/Build/.build.framework.js.gz b/.build/Build/.build.framework.js.gz index 10a816ba..feeabd5e 100644 Binary files a/.build/Build/.build.framework.js.gz and b/.build/Build/.build.framework.js.gz differ diff --git a/.build/Build/.build.wasm.gz b/.build/Build/.build.wasm.gz index b7772141..e2215954 100644 Binary files a/.build/Build/.build.wasm.gz and b/.build/Build/.build.wasm.gz differ diff --git a/.build/index.zip b/.build/index.zip index 51531d9a..4e2a1d98 100644 Binary files a/.build/index.zip and b/.build/index.zip differ diff --git a/Assets/Scripts/Game/GameService.cs b/Assets/Scripts/Game/GameService.cs index d3e28582..3a63eb64 100644 --- a/Assets/Scripts/Game/GameService.cs +++ b/Assets/Scripts/Game/GameService.cs @@ -9,7 +9,7 @@ using ServiceLocator.Sound; using ServiceLocator.UI; -public class GameService : GenericMonoSingleton +public class GameService : MonoBehaviour { public PlayerService PlayerService { get; private set; } public EventService EventService { get; private set; } @@ -31,7 +31,7 @@ public class GameService : GenericMonoSingleton [SerializeField] private AudioSource audioEffects; [SerializeField] private AudioSource backgroundMusic; - protected override void Initialize() + private void Awake() { initializeServices(); injectDependencies(); @@ -49,8 +49,8 @@ private void initializeServices() private void injectDependencies() { PlayerService.Init(MapService, SoundService, UIService); MapService.Init(EventService); - WaveService.Init(EventService, MapService, SoundService, UIService); - UIService.Init(EventService, WaveService); + WaveService.Init(EventService, MapService, PlayerService, SoundService, UIService); + UIService.Init(EventService, PlayerService, WaveService); } private void Start() @@ -61,7 +61,6 @@ private void Start() SoundService.Start(); } - private void Update() { PlayerService.Update(); diff --git a/Assets/Scripts/Player/MonkeyController.cs b/Assets/Scripts/Player/MonkeyController.cs index 68fafd2d..20a24a55 100644 --- a/Assets/Scripts/Player/MonkeyController.cs +++ b/Assets/Scripts/Player/MonkeyController.cs @@ -15,15 +15,19 @@ public class MonkeyController private float attackTimer; private List bloons; - public MonkeyController(MonkeyScriptableObject monkeyScriptableObject, ProjectilePool projectilePool) + private SoundService soundService; + + public MonkeyController(MonkeyScriptableObject monkeyScriptableObject, ProjectilePool projectilePool, SoundService soundService) { this.monkeyScriptableObject = monkeyScriptableObject; this.projectilePool = projectilePool; + this.soundService = soundService; bloons = new List(); CreateMonkeyView(); ResetAttackTimer(); + this.soundService = soundService; } private void CreateMonkeyView() @@ -72,7 +76,7 @@ private void ShootAtTarget(BloonController bloon) ProjectileController projectile = projectilePool.GetProjectile(monkeyScriptableObject.projectileType); projectile.SetPosition(monkeyView.transform.position); projectile.SetTarget(bloon); - GameService.Instance.SoundService.PlaySoundEffects(Sound.SoundType.MonkeyShoot); + soundService.PlaySoundEffects(Sound.SoundType.MonkeyShoot); ResetAttackTimer(); } } diff --git a/Assets/Scripts/Player/PlayerService.cs b/Assets/Scripts/Player/PlayerService.cs index 6b5e0cee..51f74f8c 100644 --- a/Assets/Scripts/Player/PlayerService.cs +++ b/Assets/Scripts/Player/PlayerService.cs @@ -39,7 +39,7 @@ public void Init(MapService mapService, SoundService soundService, UIService uiS public void Start() { - projectilePool = new ProjectilePool(playerScriptableObject.ProjectilePrefab, playerScriptableObject.ProjectileScriptableObjects); + projectilePool = new ProjectilePool(playerScriptableObject.ProjectilePrefab, playerScriptableObject.ProjectileScriptableObjects, this); } private void InitializeVariables() @@ -120,7 +120,7 @@ public void TrySpawningMonkey(MonkeyType monkeyType, int monkeyCost, Vector3 dro public void SpawnMonkey(MonkeyType monkeyType, Vector3 spawnPosition) { MonkeyScriptableObject monkeyScriptableObject = GetMonkeyScriptableObjectByType(monkeyType); - MonkeyController monkey = new MonkeyController(monkeyScriptableObject, projectilePool); + MonkeyController monkey = new MonkeyController(monkeyScriptableObject, projectilePool, soundService); monkey.SetPosition(spawnPosition); activeMonkeys.Add(monkey); diff --git a/Assets/Scripts/Player/Projectile/ProjectileController.cs b/Assets/Scripts/Player/Projectile/ProjectileController.cs index acbf7a0e..5f77c9e1 100644 --- a/Assets/Scripts/Player/Projectile/ProjectileController.cs +++ b/Assets/Scripts/Player/Projectile/ProjectileController.cs @@ -11,8 +11,12 @@ public class ProjectileController private BloonController target; private ProjectileState currentState; - public ProjectileController(ProjectileView projectilePrefab, Transform projectileContainer) + private PlayerService playerService; + + public ProjectileController(ProjectileView projectilePrefab, Transform projectileContainer, PlayerService playerService) { + this.playerService = playerService; + projectileView = Object.Instantiate(projectilePrefab, projectileContainer); projectileView.SetController(this); } @@ -61,7 +65,7 @@ public void ResetProjectile() { target = null; projectileView.gameObject.SetActive(false); - GameService.Instance.PlayerService.ReturnProjectileToPool(this); + playerService.ReturnProjectileToPool(this); } private void SetState(ProjectileState newState) => currentState = newState; diff --git a/Assets/Scripts/Player/Projectile/ProjectilePool.cs b/Assets/Scripts/Player/Projectile/ProjectilePool.cs index 65742416..7ec800ff 100644 --- a/Assets/Scripts/Player/Projectile/ProjectilePool.cs +++ b/Assets/Scripts/Player/Projectile/ProjectilePool.cs @@ -16,11 +16,14 @@ public class ProjectilePool : GenericObjectPool private List projectileScriptableObjects; private Transform projectileContainer; - public ProjectilePool(ProjectileView projectilePrefab, List projectileScriptableObjects) + private PlayerService playerService; + + public ProjectilePool(ProjectileView projectilePrefab, List projectileScriptableObjects, PlayerService playerService) { this.projectilePrefab = projectilePrefab; this.projectileScriptableObjects = projectileScriptableObjects; this.projectileContainer = new GameObject("Projectile Container").transform; + this.playerService = playerService; } public ProjectileController GetProjectile(ProjectileType projectileType) @@ -31,6 +34,6 @@ public ProjectileController GetProjectile(ProjectileType projectileType) return projectile; } - protected override ProjectileController CreateItem() => new ProjectileController(projectilePrefab, projectileContainer); + protected override ProjectileController CreateItem() => new ProjectileController(projectilePrefab, projectileContainer, playerService); } } \ No newline at end of file diff --git a/Assets/Scripts/UI/MapButton.cs b/Assets/Scripts/UI/MapButton.cs index e4c4b63a..59316ed2 100644 --- a/Assets/Scripts/UI/MapButton.cs +++ b/Assets/Scripts/UI/MapButton.cs @@ -8,9 +8,15 @@ public class MapButton : MonoBehaviour { [SerializeField] private int MapId; + private EventService eventService; + public void Init(EventService eventService) + { + this.eventService = eventService; + } + private void Start() => GetComponent