Skip to content

Commit ed0875a

Browse files
committed
refactor(SpawnManager): abstract hitable volume method
1 parent d022c6c commit ed0875a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Assets/Scripts/Gameplay/Services/SpawnManager.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void OnGetHitableFromPool(Hitable hitable) {
4747

4848
private void OnReleaseHitableToPool(Hitable hitable) {
4949
hitable.isReleased = true;
50-
hitable.transform.position = GenerateRandomPosition(hitable); // TODO: check if this is causing physics spike
50+
hitable.transform.position = GenerateRandomPosition(hitable);
5151
hitable.gameObject.SetActive(false);
5252
}
5353

@@ -57,13 +57,7 @@ private void SpawnHitable() {
5757
Hitable hitable = pool.Get();
5858
hitable.GetComponent<Hitable>().SetKill(hitable => Kill(pool, hitable));
5959

60-
AudioSource[] audioSources = hitable.GetComponents<AudioSource>(); // TODO: abstract
61-
if (audioSources != null && audioSources.Length != 0) {
62-
foreach (AudioSource audioSource in audioSources) {
63-
float obstacleVolume = AudioManager.Instance.GetTrackVolume(2) == 0 ? 0 : AudioManager.Instance.GetTrackVolume(2) + .2f;
64-
audioSource.volume = obstacleVolume;
65-
}
66-
}
60+
SetHitableVolume(hitable);
6761

6862
if (!CheckShouldSpawn(hitable))
6963
pool.Release(hitable);
@@ -72,6 +66,17 @@ private void SpawnHitable() {
7266
_isSelectingPool = true;
7367
}
7468

69+
private void SetHitableVolume(Hitable hitable) {
70+
AudioSource[] audioSources = hitable.GetComponents<AudioSource>();
71+
72+
if (audioSources != null && audioSources.Length != 0) {
73+
foreach (AudioSource audioSource in audioSources) {
74+
float obstacleVolume = AudioManager.Instance.GetTrackVolume(2) == 0 ? 0 : AudioManager.Instance.GetTrackVolume(2) + .2f;
75+
audioSource.volume = obstacleVolume;
76+
}
77+
}
78+
}
79+
7580
private bool CheckShouldSpawn(Hitable hitable) {
7681
if (hitable.SpawnRate <= 0f)
7782
return false;

0 commit comments

Comments
 (0)