Improve diapason

This commit is contained in:
2026-02-03 18:50:04 +01:00
parent 23d3cb5d2c
commit 71c44eb39e
12 changed files with 1172 additions and 602 deletions
@@ -59,12 +59,6 @@ namespace Unheimlich.Audio
[SerializeField] private float _maxDistance = 10f;
[SerializeField] private AnimationCurve _distanceAttenuation = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f);
[Header("Vibration Settings")]
[SerializeField] private bool _enableVibration = true;
[SerializeField] private float _vibrationIntensityMin = 0.1f;
[SerializeField] private float _vibrationIntensityMax = 0.5f;
[SerializeField] private float _vibrationFrequency = 10f;
[Header("Visual Feedback")]
[SerializeField] private ParticleSystem _emitterParticles;
@@ -168,17 +162,6 @@ namespace Unheimlich.Audio
duration);
}
public void ResetConcentrationVolume()
{
TweenHelper.CancelTween(ref _concentrationFadeTweenId);
if (_continuousAudioSource == null)
return;
float baselineVolume = _continuousBaseVolume * BASELINE_VOLUME_MULTIPLIER;
_continuousAudioSource.volume = baselineVolume;
}
/// <summary>
/// Starts the listening sequence for this emitter.
/// Blocked if the emitter has already been tapped during this session.
@@ -253,9 +236,6 @@ namespace Unheimlich.Audio
_audioSource.loop = _loopStaticAudio;
_audioSource.Play();
}
if (_enableVibration)
StartVibration();
}
/// <summary>
@@ -295,7 +275,6 @@ namespace Unheimlich.Audio
}
EnableReverb(false);
StopVibration();
}
private void Update()
@@ -311,8 +290,6 @@ namespace Unheimlich.Audio
PlayProceduralSound();
_nextProceduralEventTime = _listeningTimer + Random.Range(_durationMin, _durationMax);
}
UpdateVibration();
}
@@ -420,39 +397,6 @@ namespace Unheimlich.Audio
}
}
private void StartVibration()
{
if (Gamepad.current == null)
return;
float distance = Vector3.Distance(_listenerPosition, transform.position);
float distanceFactor = Mathf.Clamp01(1f - (distance / _maxDistance));
float intensity = Mathf.Lerp(_vibrationIntensityMin, _vibrationIntensityMax, distanceFactor);
Gamepad.current.SetMotorSpeeds(intensity, intensity);
}
private void UpdateVibration()
{
if (!_enableVibration || Gamepad.current == null)
return;
float distance = Vector3.Distance(_listenerPosition, transform.position);
float distanceFactor = Mathf.Clamp01(1f - (distance / _maxDistance));
float intensity = Mathf.Lerp(_vibrationIntensityMin, _vibrationIntensityMax, distanceFactor);
float vibrationPattern = Mathf.Abs(Mathf.Sin(Time.time * _vibrationFrequency));
intensity *= vibrationPattern;
Gamepad.current.SetMotorSpeeds(intensity, intensity);
}
private void StopVibration()
{
if (Gamepad.current != null)
Gamepad.current.SetMotorSpeeds(0f, 0f);
}
private void OnDisable()
{
StopListening();
@@ -1,91 +0,0 @@
using UnityEngine;
using UnityEngine.Events;
namespace Unheimlich.Audio
{
public class AudioListenableEvent : MonoBehaviour
{
[Header("Event Settings")]
[SerializeField] private bool _triggerOnce = false;
[SerializeField] private float _delayBeforeEvent = 0f;
[Header("Events")]
[SerializeField] private UnityEvent _onListeningStarted;
[SerializeField] private UnityEvent _onListeningStopped;
[SerializeField] private UnityEvent _onFirstListen;
private AudioListenable _listenable;
private bool _hasBeenListenedTo = false;
private bool _isCurrentlyListening = false;
private void Awake()
{
_listenable = GetComponent<AudioListenable>();
if (_listenable == null)
{
Debug.LogError($"AudioListenableEvent on {gameObject.name} requires AudioListenable component!");
enabled = false;
}
}
private void Update()
{
if (_listenable == null)
return;
bool wasListening = _isCurrentlyListening;
if (wasListening && !_isCurrentlyListening)
{
OnListeningStopped();
}
}
public void OnListeningStart()
{
if (_triggerOnce && _hasBeenListenedTo)
return;
_isCurrentlyListening = true;
if (_delayBeforeEvent > 0)
Invoke(nameof(TriggerListeningStartedEvent), _delayBeforeEvent);
else
TriggerListeningStartedEvent();
if (!_hasBeenListenedTo)
{
_hasBeenListenedTo = true;
_onFirstListen?.Invoke();
}
}
private void TriggerListeningStartedEvent()
{
_onListeningStarted?.Invoke();
}
private void OnListeningStopped()
{
_isCurrentlyListening = false;
_onListeningStopped?.Invoke();
}
public void EnableListenable()
{
if (_listenable != null)
_listenable.enabled = true;
}
public void DisableListenable()
{
if (_listenable != null)
_listenable.enabled = false;
}
public void ResetTrigger()
{
_hasBeenListenedTo = false;
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 522dcfb634e07d240afa8ae5344fc785
@@ -249,36 +249,6 @@ namespace Unheimlich.Audio
}
}
private float CalculateVolumeFromDistance(float distance, AudioSource source)
{
float baseVolume = source.volume;
AudioSourceDemo demo = source.GetComponent<AudioSourceDemo>();
if (demo != null)
baseVolume = demo.OriginalVolume;
if (distance > source.maxDistance)
return 0f;
if (distance < source.minDistance)
return baseVolume;
switch (source.rolloffMode)
{
case AudioRolloffMode.Logarithmic:
float normalizedDist = (distance - source.minDistance) / (source.maxDistance - source.minDistance);
float logVolume = baseVolume * (1f / (1f + normalizedDist * 10f));
return logVolume * Mathf.Pow(1f - normalizedDist, _volumeRolloffPower);
case AudioRolloffMode.Linear:
float linearFactor = 1f - ((distance - source.minDistance) / (source.maxDistance - source.minDistance));
linearFactor = Mathf.Pow(linearFactor, _volumeRolloffPower);
return baseVolume * Mathf.Max(0f, linearFactor);
default:
return baseVolume;
}
}
private AudioSource GetOrCreateProxy(AudioSource remoteSource)
{
@@ -1,102 +0,0 @@
using UnityEngine;
namespace Unheimlich.Audio
{
[RequireComponent(typeof(AudioListenable))]
public class ThroughWallListener : MonoBehaviour
{
[Header("Behind Wall Detection")]
[SerializeField] private LayerMask _detectionLayers;
[SerializeField] private float _detectionDistance = 2f;
[SerializeField] private float _detectionRadius = 1f;
[Header("Audio Feedback")]
[SerializeField] private AudioClip _nothingBehindClip;
[SerializeField] private AudioClip _somethingBehindClip;
[SerializeField] private AudioClip _importantObjectClip;
[SerializeField] private string _importantObjectTag = "Important";
[Header("Visual Feedback")]
[SerializeField] private GameObject _highlightEffectPrefab;
[SerializeField] private float _highlightDuration = 3f;
private AudioSource _audioSource;
private AudioListenable _listenable;
private GameObject _currentHighlight;
private void Awake()
{
_listenable = GetComponent<AudioListenable>();
_audioSource = GetComponent<AudioSource>();
if (_audioSource == null)
_audioSource = gameObject.AddComponent<AudioSource>();
}
private void Update()
{
}
public void OnWallListened()
{
Vector3 checkPosition = transform.position + transform.forward * (_detectionDistance * 0.5f);
Collider[] hitColliders = Physics.OverlapSphere(checkPosition, _detectionRadius, _detectionLayers);
if (hitColliders.Length > 0)
{
bool foundImportant = false;
foreach (Collider col in hitColliders)
{
if (col.CompareTag(_importantObjectTag))
{
foundImportant = true;
PlayFeedbackSound(_importantObjectClip);
ShowHighlight(col.transform.position);
break;
}
}
if (!foundImportant)
{
PlayFeedbackSound(_somethingBehindClip);
}
}
else
{
PlayFeedbackSound(_nothingBehindClip);
}
}
private void PlayFeedbackSound(AudioClip clip)
{
if (clip != null && _audioSource != null)
{
_audioSource.PlayOneShot(clip);
}
}
private void ShowHighlight(Vector3 position)
{
if (_highlightEffectPrefab != null)
{
if (_currentHighlight != null)
Destroy(_currentHighlight);
_currentHighlight = Instantiate(_highlightEffectPrefab, position, Quaternion.identity);
Destroy(_currentHighlight, _highlightDuration);
}
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Vector3 checkPosition = transform.position + transform.forward * (_detectionDistance * 0.5f);
Gizmos.DrawWireSphere(checkPosition, _detectionRadius);
Gizmos.color = Color.blue;
Gizmos.DrawRay(transform.position, transform.forward * _detectionDistance);
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 3fad34f7be8a64242984b14410478690