Added audio to the decorations minigame and switched the rock for the fez

This commit is contained in:
journaliciouz
2025-11-28 15:28:15 +01:00
parent fbf9ee464a
commit 652e3ab814
4 changed files with 232 additions and 11 deletions

View File

@@ -1,6 +1,12 @@
using Core;
using Core.Lifecycle;
using Minigames.StatueDressup.Data;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace Minigames.StatueDressup.Events
{
@@ -11,7 +17,12 @@ namespace Minigames.StatueDressup.Events
public class DecorationEventsManager : ManagedBehaviour
{
public static DecorationEventsManager Instance { get; private set; }
private AppleAudioSource _targetAudioPlayer;
// Dictionary to track addressable handles by AudioManager
private Dictionary<AppleAudioSource, AsyncOperationHandle<AudioResource>> _addressableHandles
= new Dictionary<AppleAudioSource, AsyncOperationHandle<AudioResource>>();
// Static events for decoration state changes
public static event System.Action<DecorationEventData> OnDecorationTappedInGrid;
public static event System.Action<DecorationEventData> OnDecorationTappedOnStatue;
@@ -34,6 +45,10 @@ namespace Minigames.StatueDressup.Events
}
Instance = this;
// Get ref to AudioComponent
_targetAudioPlayer = GetComponent<AppleAudioSource>();
// Subscribe to all events
OnDecorationTappedInGrid += HandleDecorationTappedInGrid;
@@ -57,13 +72,32 @@ namespace Minigames.StatueDressup.Events
OnDecorationDroppedOnStatue -= HandleDecorationDroppedOnStatue;
OnDecorationDroppedOut -= HandleDecorationDroppedOut;
OnDecorationFinishedDroppingOut -= HandleDecorationFinishedDroppingOut;
ReleaseAllHandles();
Instance = null;
}
}
private void OnApplicationQuit()
{
ReleaseAllHandles();
}
private void ReleaseAllHandles()
{
foreach (var handle in _addressableHandles.Values)
{
if (handle.IsValid())
{
Addressables.Release(handle);
}
}
_addressableHandles.Clear();
}
#region Static Broadcasting Methods
/// <summary>
/// Broadcast that a decoration was tapped in the grid menu
/// </summary>
@@ -127,19 +161,20 @@ namespace Minigames.StatueDressup.Events
private void HandleDecorationTappedInGrid(DecorationEventData eventData)
{
Logging.Debug($"[DecorationEventsManager] Decoration tapped in grid: {eventData.DecorationData?.DecorationId}");
// TODO: Play tap SFX/VFX
}
private void HandleDecorationTappedOnStatue(DecorationEventData eventData)
{
Logging.Debug($"[DecorationEventsManager] Decoration tapped on statue: {eventData.DecorationData?.DecorationId}");
// TODO: Play tap SFX/VFX (different from grid tap?)
}
private void HandleDecorationStartedDragging(DecorationEventData eventData)
{
Logging.Debug($"[DecorationEventsManager] Decoration started dragging: {eventData.DecorationData?.DecorationId} (FromStatue: {eventData.FromStatue})");
// TODO: Play drag start SFX, maybe show drag VFX
//Play tap SFX/VFX
PlayAdressableAudio("card_albumdrop");
}
private void HandleDecorationFinishedDragging(DecorationEventData eventData)
@@ -151,13 +186,15 @@ namespace Minigames.StatueDressup.Events
private void HandleDecorationDroppedOnStatue(DecorationEventData eventData)
{
Logging.Debug($"[DecorationEventsManager] Decoration dropped on statue: {eventData.DecorationData?.DecorationId}");
// TODO: Play success SFX, maybe show placement VFX
// Play success SFX
PlayAdressableAudio("card_albumdrop_deep");
}
private void HandleDecorationDroppedOut(DecorationEventData eventData)
{
Logging.Debug($"[DecorationEventsManager] Decoration dropped out (animation starting): {eventData.DecorationData?.DecorationId}");
// TODO: Play drop-out SFX (whoosh/disappear sound?)
// Play disappear SFX SFX
PlayAdressableAudio("random_swoosh");
}
private void HandleDecorationFinishedDroppingOut(DecorationEventData eventData)
@@ -165,8 +202,23 @@ namespace Minigames.StatueDressup.Events
Logging.Debug($"[DecorationEventsManager] Decoration finished dropping out: {eventData.DecorationData?.DecorationId}");
// TODO: Play finish SFX (poof sound?), maybe show VFX
}
#endregion
public void PlayAdressableAudio(string key)
{
// Load the asset via addressables
var handle = Addressables.LoadAssetAsync<AudioResource>(key);
var result = handle.WaitForCompletion();
// Store the handle for later release
_addressableHandles[_targetAudioPlayer] = handle;
Logging.Debug($"[DecorationEventsManager] Loaded addressable audio clip: {key}");
_targetAudioPlayer.audioSource.resource = result;
_targetAudioPlayer.Play(0);
}
}
}

View File

@@ -310,7 +310,7 @@ public class AudioManager : ManagedBehaviour, IPausable
// Store the handle for later release
_addressableHandles[uiAudioSource] = handle;
Logging.Debug($"[CinematicsManager] Loaded addressable UI audio clip: {key}");
Logging.Debug($"[AudioManager] Loaded addressable UI audio clip: {key}");
_targetAudioPlayer.audioSource.resource = result;
_targetAudioPlayer.Play(0);