Add SFX and SFX logic
This commit is contained in:
parent
f0e4f6c9ba
commit
1aa97baff4
19 changed files with 504 additions and 8 deletions
77
Assets/Scripts/SoundManager.cs
Normal file
77
Assets/Scripts/SoundManager.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SoundManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static SoundManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private AudioClipsRefsSO audioClipsRefsSO;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
DeliveryManager.Instance.OnRecipeSuccess += DeliveryManager_OnRecipeSuccess;
|
||||
DeliveryManager.Instance.OnRecipeFailed += DeliveryManager_OnRecipeFailed;
|
||||
CuttingCounter.OnAnyCut += CuttingCounter_OnAnyCut;
|
||||
Player.Instance.OnPickedUpSomething += Player_OnPickedUpSomething;
|
||||
BaseCounter.OnAnyObjectPlaced += BaseCounter_OnAnyObjectPlaced;
|
||||
TrashCounter.OnAnyObjectTrashed += TrashCounter_OnAnyObjectTrashed;
|
||||
}
|
||||
|
||||
private void TrashCounter_OnAnyObjectTrashed(object sender, System.EventArgs e)
|
||||
{
|
||||
TrashCounter trashCounter = sender as TrashCounter;
|
||||
PlaySound(audioClipsRefsSO.trash, trashCounter.transform.position);
|
||||
}
|
||||
|
||||
private void BaseCounter_OnAnyObjectPlaced(object sender, System.EventArgs e)
|
||||
{
|
||||
BaseCounter counter = sender as BaseCounter;
|
||||
PlaySound(audioClipsRefsSO.objectDrop, counter.transform.position);
|
||||
}
|
||||
|
||||
private void Player_OnPickedUpSomething(object sender, System.EventArgs e)
|
||||
{
|
||||
PlaySound(audioClipsRefsSO.objectPickup, Player.Instance.transform.position);
|
||||
}
|
||||
|
||||
private void CuttingCounter_OnAnyCut(object sender, System.EventArgs e)
|
||||
{
|
||||
CuttingCounter cuttingCounter = sender as CuttingCounter;
|
||||
PlaySound(audioClipsRefsSO.chop, cuttingCounter.transform.position);
|
||||
}
|
||||
|
||||
private void DeliveryManager_OnRecipeFailed(object sender, System.EventArgs e)
|
||||
{
|
||||
DeliveryCounter deliveryCounter = DeliveryCounter.Instance;
|
||||
PlaySound(audioClipsRefsSO.deliveryFail, deliveryCounter.transform.position);
|
||||
}
|
||||
|
||||
private void DeliveryManager_OnRecipeSuccess(object sender, System.EventArgs e)
|
||||
{
|
||||
DeliveryCounter deliveryCounter = DeliveryCounter.Instance;
|
||||
PlaySound(audioClipsRefsSO.deliverySuccess, deliveryCounter.transform.position);
|
||||
}
|
||||
|
||||
private void PlaySound(AudioClip[] audioClipArray, Vector3 position, float volume = 1f)
|
||||
{
|
||||
PlaySound(audioClipArray[Random.Range(0, audioClipArray.Length)], position, volume);
|
||||
}
|
||||
|
||||
private void PlaySound(AudioClip audioClip, Vector3 position, float volume = 1f)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(audioClip, position, volume);
|
||||
}
|
||||
|
||||
public void PlayFootsteps(Vector3 position, float volume)
|
||||
{
|
||||
PlaySound(audioClipsRefsSO.footstep, position, volume);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue