Spatial lawnmower audio implemented

This commit is contained in:
2025-10-20 16:21:32 +02:00
parent b49bb43f79
commit c07f64ea4f
16 changed files with 884 additions and 2 deletions

View File

@@ -0,0 +1,62 @@
using AudioSourceEvents;
using System;
using System.Diagnostics.Tracing;
using UnityEngine;
using UnityEngine.Audio;
public class GardenerAudioController : MonoBehaviour
{
public AudioSource gardenerAudioPlayer;
public AudioSource 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()
{
}
void GardenerIsOnScreen()
{
Debug.Log("Gardener spotted!");
}
public void StartMowerSound()
{
mowerAudioPlayer.Play();
_eventSource = mowerAudioPlayer.RequestEventHandlers();
_eventSource.AudioStopped += PlayMowerLoop;
}
private void PlayMowerLoop(object sender, EventArgs e)
{
_eventSource.AudioStopped -= PlayMowerLoop;
mowerAudioPlayer.resource = mowerLoopAudio;
mowerAudioPlayer.loop = true;
mowerAudioPlayer.Play();
}
public void PlayGardenerVOClip(bool fleeing)
{
if (gardenerAudioPlayer.isPlaying) { return; }
if (fleeing) {
gardenerAudioPlayer.resource = gardenerFleeAudioClip;
gardenerAudioPlayer.Play();
}
if (!fleeing)
{
gardenerAudioPlayer.resource = gardenerChaseAudioClip;
gardenerAudioPlayer.Play();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f0f1834ce0c7b0b42b633a6d2bd67698

View File

@@ -0,0 +1,21 @@
using TMPro;
using UnityEngine;
public class GardenerVisibilityDetection : MonoBehaviour
{
public GardenerAudioController gardenerAudioController;
private Animator _animator;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_animator = GetComponent<Animator>();
}
private void OnBecameVisible()
{
gardenerAudioController.PlayGardenerVOClip(_animator.GetBool("IsScared?"));
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 52a39ff5639315a499266196941d6894