조개 사운드

This commit is contained in:
2026-06-24 14:40:39 +09:00
parent 59bf6f0555
commit 513fa94ab9
28 changed files with 626 additions and 4 deletions

View File

@@ -23,6 +23,24 @@ public class FallingStalactite : MonoBehaviour
[Tooltip("떨어지기 전에는 데미지를 끄고, 떨어질 때 켭니다.")]
[SerializeField] private bool damageOnlyWhileFalling = true;
[Header("Sound")]
[SerializeField] private AudioSource audioSource;
[Tooltip("종유석이 떨어지기 시작할 때 재생할 소리입니다.")]
[SerializeField] private AudioClip fallSound;
[Range(0f, 1f)]
[SerializeField] private float fallSoundVolume = 1f;
[Tooltip("리셋 후 다시 떨어질 때도 소리를 재생할지 여부입니다.")]
[SerializeField] private bool playSoundEveryFall = true;
[Tooltip("Play through the shared 2D SFX pool when available so the fall cue is always audible.")]
[SerializeField] private bool playThroughSoundManager = true;
[Tooltip("Force the fallback AudioSource to 2D playback.")]
[SerializeField] private bool playFallSoundAs2D = true;
[Header("Reset Option")]
[SerializeField] private bool resetAfterFall = true;
@@ -38,6 +56,7 @@ public class FallingStalactite : MonoBehaviour
private Vector3 startPosition;
private Quaternion startRotation;
private bool hasFallen;
private bool hasPlayedSound;
private Coroutine fallRoutine;
public bool HasFallen => hasFallen;
@@ -62,6 +81,9 @@ private void ResolveReferences()
if (damageObstacle == null)
damageObstacle = GetComponent<DamageObstacle>();
if (audioSource == null)
audioSource = GetComponent<AudioSource>();
}
private void PrepareStalactite()
@@ -85,7 +107,21 @@ private void PrepareStalactite()
damageCollider.enabled = true;
}
if (audioSource != null)
{
audioSource.playOnAwake = false;
audioSource.mute = false;
if (playFallSoundAs2D)
audioSource.spatialBlend = 0f;
}
PreloadFallSound();
hasFallen = false;
if (playSoundEveryFall)
hasPlayedSound = false;
}
public void TriggerFall()
@@ -106,6 +142,8 @@ private IEnumerator FallRoutine()
if (fallDelay > 0f)
yield return new WaitForSeconds(fallDelay);
PlayFallSound();
if (damageObstacle != null)
{
damageObstacle.SetDamage(damage);
@@ -137,6 +175,71 @@ private IEnumerator FallRoutine()
fallRoutine = null;
}
private AudioClip GetFallClip()
{
if (fallSound != null)
return fallSound;
if (audioSource != null)
return audioSource.clip;
return null;
}
private void PreloadFallSound()
{
AudioClip clipToLoad = GetFallClip();
if (clipToLoad != null && clipToLoad.loadState == AudioDataLoadState.Unloaded)
clipToLoad.LoadAudioData();
}
private void PlayFallSound()
{
if (hasPlayedSound && !playSoundEveryFall)
return;
AudioClip clipToPlay = GetFallClip();
if (clipToPlay == null)
{
if (showDebugLog)
Debug.LogWarning($"[FallingStalactite] {name} Fall Sound가 연결되지 않았습니다.", this);
return;
}
if (clipToPlay.loadState == AudioDataLoadState.Unloaded)
clipToPlay.LoadAudioData();
if (playThroughSoundManager && SoundManager.Instance != null)
{
SoundManager.Instance.PlaySFX(clipToPlay, fallSoundVolume);
}
else if (audioSource != null)
{
audioSource.enabled = true;
audioSource.mute = false;
audioSource.playOnAwake = false;
if (audioSource.volume <= 0f)
audioSource.volume = 1f;
if (playFallSoundAs2D)
audioSource.spatialBlend = 0f;
audioSource.PlayOneShot(clipToPlay, fallSoundVolume);
}
else
{
AudioSource.PlayClipAtPoint(clipToPlay, transform.position, fallSoundVolume);
}
hasPlayedSound = true;
if (showDebugLog)
Debug.Log($"[FallingStalactite] {name} 낙하 사운드 재생: {clipToPlay.name}", this);
}
public void ResetStalactite()
{
if (rb != null)
@@ -161,6 +264,11 @@ public void ResetStalactite()
hasFallen = false;
}
if (playSoundEveryFall)
{
hasPlayedSound = false;
}
if (showDebugLog)
Debug.Log($"[FallingStalactite] {name} 원위치 리셋", this);
}