Add SFX and SFX logic

This commit is contained in:
BuyMyMojo 2023-03-03 05:10:23 +11:00
parent f0e4f6c9ba
commit 1aa97baff4
19 changed files with 504 additions and 8 deletions

View file

@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -5,6 +6,8 @@ using UnityEngine;
public class BaseCounter : MonoBehaviour, IKitchenObjectParent
{
public static event EventHandler OnAnyObjectPlaced;
[SerializeField] private Transform counterTopPoint;
private KitchenObject kitchenObject;
@ -28,6 +31,11 @@ public class BaseCounter : MonoBehaviour, IKitchenObjectParent
public void SetKitchenObject(KitchenObject kitchenObject)
{
this.kitchenObject = kitchenObject;
if (kitchenObject != null )
{
OnAnyObjectPlaced?.Invoke(this, EventArgs.Empty);
}
}
public KitchenObject GetKitchenObject()

View file

@ -6,6 +6,8 @@ using UnityEngine;
public class CuttingCounter : BaseCounter, IHasProgress
{
public static event EventHandler OnAnyCut;
public event EventHandler<IHasProgress.OnProgressChangeEventsArgs> OnProgressChange;
public event EventHandler OnCut;
@ -72,6 +74,7 @@ public class CuttingCounter : BaseCounter, IHasProgress
cuttingProgress++;
OnCut?.Invoke(this, EventArgs.Empty);
OnAnyCut?.Invoke(this, EventArgs.Empty);
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());

View file

@ -1,9 +1,18 @@
using ERP.Discord;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeliveryCounter : BaseCounter
{
public static DeliveryCounter Instance { get; private set; }
private void Awake()
{
Instance = this;
}
public override void Interact(Player player)
{
if (player.HasKitchenObject())

View file

@ -1,14 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrashCounter : BaseCounter
{
public static event EventHandler OnAnyObjectTrashed;
public override void Interact(Player player)
{
if (player.HasKitchenObject())
{
player.GetKitchenObject().DestroySelf();
OnAnyObjectTrashed?.Invoke(this, EventArgs.Empty);
}
}
}

View file

@ -8,6 +8,8 @@ public class DeliveryManager : MonoBehaviour
public event EventHandler OnRecipeSpawned;
public event EventHandler OnRecipeCompleted;
public event EventHandler OnRecipeSuccess;
public event EventHandler OnRecipeFailed;
public static DeliveryManager Instance { get; private set; }
[SerializeField] private RecipeListSO recipeListSO;
@ -80,11 +82,11 @@ public class DeliveryManager : MonoBehaviour
if (plateContentsMatchesRecipe)
{
// Player delivered correct recipe
Debug.Log("Player delivered a recipe from the waiting list!");
waitingRecipeSOList.RemoveAt(i);
OnRecipeCompleted?.Invoke(this, EventArgs.Empty);
OnRecipeSuccess?.Invoke(this, EventArgs.Empty);
return;
}
@ -94,7 +96,8 @@ public class DeliveryManager : MonoBehaviour
// No matches found!
// Player brought the wrong recipe!
Debug.Log("Player brought the wrong recipe!");
OnRecipeFailed?.Invoke(this, EventArgs.Empty);
}
public List<RecipeSO> GetWaitingRecipeSOList()

View file

@ -9,6 +9,7 @@ public class Player : MonoBehaviour, IKitchenObjectParent
public static Player Instance { get; private set; }
public event EventHandler OnPickedUpSomething;
public event EventHandler<OnSelectedCounterChangedEventArgs> OnSelectedcounterChanged;
public class OnSelectedCounterChangedEventArgs : EventArgs
{
@ -190,6 +191,11 @@ public class Player : MonoBehaviour, IKitchenObjectParent
public void SetKitchenObject(KitchenObject kitchenObject)
{
this.kitchenObject = kitchenObject;
if (kitchenObject != null)
{
OnPickedUpSomething?.Invoke(this, EventArgs.Empty);
}
}
public KitchenObject GetKitchenObject()

View file

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSounds : MonoBehaviour
{
private Player player;
private float footstepTimer;
private float footstepTimerMax = .1f;
private void Awake()
{
player = GetComponent<Player>();
}
private void Update()
{
footstepTimer -= Time.deltaTime;
if (footstepTimer < 0f )
{
footstepTimer = footstepTimerMax;
if (player.IsWalking())
{
float volume = 1f;
SoundManager.Instance.PlayFootsteps(player.transform.position, volume);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cf7fadd8f8bd7a548ad5f84a17b100e9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu()]
public class AudioClipsRefsSO : ScriptableObject
{
public AudioClip[] chop;
public AudioClip[] deliveryFail;
public AudioClip[] deliverySuccess;
public AudioClip[] footstep;
public AudioClip[] objectDrop;
public AudioClip[] objectPickup;
public AudioClip stoveSizzle;
public AudioClip[] trash;
public AudioClip[] warning;
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6398abfe3947f214aae1dfd889dc05dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bebe77aac6b586c4aabb54e536895c69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StoveCounterSound : MonoBehaviour
{
[SerializeField] private StoveCounter stoveCounter;
private AudioSource audioSource;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
}
private void Start()
{
stoveCounter.OnStateChanged += StoveCounter_OnStateChanged;
}
private void StoveCounter_OnStateChanged(object sender, StoveCounter.OnStateChangedEventArgs e)
{
bool playSound = e.state == StoveCounter.State.Frying || e.state == StoveCounter.State.Fried;
if (playSound)
{
audioSource.Play();
} else
{
audioSource.Pause();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a58f05adbbecd024eacd08f86e3c175c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: