56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using AudioSourceEvents;
|
|
using Input;
|
|
using System;
|
|
using System.Diagnostics.Tracing;
|
|
using UnityEngine;
|
|
using UnityEngine.Audio;
|
|
|
|
public class BushAudioController : MonoBehaviour
|
|
{
|
|
private IAudioEventSource _eventSource;
|
|
public AudioSource VOPlayer;
|
|
public AudioSource SFXPlayer;
|
|
public AudioResource reactionClipToPlay;
|
|
public AudioResource flashSFXClipToPlay;
|
|
|
|
public BirdGameStats birdGameStats;
|
|
public AudioResource[] birdCounterClip;
|
|
private int _birdCounter;
|
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
_eventSource = VOPlayer.RequestEventHandlers();
|
|
_eventSource.AudioStopped += PlayBirdCounter;
|
|
|
|
}
|
|
|
|
public void PlayPhotoSoundBite()
|
|
{
|
|
VOPlayer.resource = reactionClipToPlay;
|
|
VOPlayer.Play();
|
|
}
|
|
|
|
public void PlayFlashSound()
|
|
{
|
|
SFXPlayer.resource = flashSFXClipToPlay;
|
|
SFXPlayer.Play();
|
|
}
|
|
|
|
private void PlayBirdCounter(object sender, EventArgs e)
|
|
{
|
|
VOPlayer.resource = birdCounterClip[birdGameStats.birdsFoundInLevel];
|
|
VOPlayer.Play();
|
|
birdGameStats.BirdFound();
|
|
_eventSource.AudioStopped -= PlayBirdCounter;
|
|
}
|
|
|
|
public void OnDisable()
|
|
{
|
|
// Unsubscribe from events when disabled
|
|
_eventSource.AudioStopped -= PlayBirdCounter;
|
|
}
|
|
}
|