60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using AudioSourceEvents;
|
|
using System;
|
|
using System.Diagnostics.Tracing;
|
|
using UnityEngine;
|
|
using UnityEngine.Audio;
|
|
|
|
public class GardenerAudioController : MonoBehaviour
|
|
{
|
|
|
|
public AppleAudioSource gardenerIdleAudioPlayer;
|
|
public AppleAudioSource gardenerRunningAudioPlayer;
|
|
public AppleAudioSource mowerAudioPlayer;
|
|
public AudioResource mowerStartAudio;
|
|
public AudioResource mowerLoopAudio;
|
|
public AudioResource gardenerFleeAudioClip;
|
|
public AudioResource gardenerChaseAudioClip;
|
|
|
|
public SpriteRenderer gardenerSprite;
|
|
|
|
private IAudioEventSource _eventSource;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
|
|
public void StartMowerSound()
|
|
{
|
|
mowerAudioPlayer.Play(0);
|
|
_eventSource = mowerAudioPlayer.audioSource.RequestEventHandlers();
|
|
_eventSource.AudioStopped += PlayMowerLoop;
|
|
|
|
}
|
|
|
|
private void PlayMowerLoop(object sender, EventArgs e)
|
|
{
|
|
_eventSource.AudioStopped -= PlayMowerLoop;
|
|
mowerAudioPlayer.audioSource.resource = mowerLoopAudio;
|
|
mowerAudioPlayer.audioSource.loop = true;
|
|
mowerAudioPlayer.Play(0);
|
|
}
|
|
|
|
public void PlayGardenerVOClip(bool fleeing)
|
|
{
|
|
if (gardenerRunningAudioPlayer.audioSource.isPlaying) { return; }
|
|
if (fleeing) {
|
|
gardenerRunningAudioPlayer.audioSource.resource = gardenerFleeAudioClip;
|
|
gardenerRunningAudioPlayer.Play(1);
|
|
}
|
|
if (!fleeing)
|
|
{
|
|
gardenerRunningAudioPlayer.audioSource.resource = gardenerChaseAudioClip;
|
|
gardenerRunningAudioPlayer.Play(1);
|
|
|
|
}
|
|
|
|
}
|
|
}
|