Audio: per-SoundEffect occlusion via Steam Audio + 3D flag refactor

- New occlusion opt-in on SoundEffect: spatialized instances get a
  SteamAudioSource with raycast occlusion + frequency-dependent
  transmission (walls muffle instead of hard-mute)
- Replace SoundEffectDistanceRange asset indirection with an explicit
  _3d bool (user refactor); rolloff/distance now left to defaults
- Hey.asset: occlusion enabled

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Fable 5 committed 2026-07-11 23:33:29 +02:00
1 parent c25d0777c2
commit 706100e322
8 files changed
+21 -56

No files matched your search

+5 -2
View File
@@ -7,7 +7,6 @@ namespace Prototype
[CreateAssetMenu(menuName = "Prototype/Sound Effect")]
public class SoundEffect : ScriptableObject
{
[SerializeField] SoundEffectDistanceRange distanceRange;
[SerializeField] Vector2 volumeMultiplier = new(1, 1);
[SerializeField] Vector2 pitch = new(.95f, 1.05f);
@@ -15,7 +14,10 @@ namespace Prototype
public AudioMixerGroup audioMixerGroup;
public float volumeMultiplierFactor = 1;
[SerializeField] bool loop;
[SerializeField] bool _3d;
[SerializeField] bool spatialize;
[Tooltip("Occlude/muffle the sound behind walls via Steam Audio. Requires spatialize and exported scene geometry.")]
[SerializeField] bool occlusion;
[Header("Additional Settings")]
[SerializeField, Range(0, 1)] float defaultVolume = .8f;
@@ -35,8 +37,9 @@ namespace Prototype
volumeMultiplier = Random.Range(volumeMultiplier.x, volumeMultiplier.y) * volumeMultiplierFactor,
pitch = Random.Range(pitch.x, pitch.y),
loop = loop,
_3d = _3d,
spatialize = spatialize,
distanceRange = distanceRange ? distanceRange.range : null
occlusion = occlusion
};
#if UNITY_EDITOR
@@ -1,10 +0,0 @@
using UnityEngine;
namespace Prototype
{
[CreateAssetMenu(menuName = "Prototype/Sound Effect Distance Range")]
public class SoundEffectDistanceRange : UnityEngine.ScriptableObject
{
public Vector2 range = new SoundEffectOptions().GetDistanceRange();
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 523ce7d83fde21c419a5d637cbe7bf04
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+9 -6
View File
@@ -23,16 +23,19 @@ namespace Prototype
audioSource.volume = options.GetVolume();
audioSource.pitch = options.GetPitch();
var range = options.GetDistanceRange();
audioSource.spatialBlend = range.x == 0 && range.y == 0 ? 0 : 1;
audioSource.spatialBlend = options.Get3D() ? 1 : 0;
audioSource.spatialize = options.GetSpatialize() && audioSource.spatialBlend > 0;
audioSource.rolloffMode = AudioRolloffMode.Linear;
audioSource.minDistance = range.x;
audioSource.maxDistance = range.y;
audioSource.loop = options.GetLoop();
}
if (audioSource.spatialize && options.GetOcclusion())
{
var steamAudioSource = gameObject.AddComponent<SteamAudio.SteamAudioSource>();
steamAudioSource.occlusion = true;
steamAudioSource.transmission = true;
steamAudioSource.transmissionType = SteamAudio.TransmissionType.FrequencyDependent;
}
if (!options.ShouldDestroyOnLoad())
{
DontDestroyOnLoad(this);
+5 -3
View File
@@ -1,4 +1,3 @@
using UnityEngine;
using UnityEngine.Audio;
namespace Prototype
@@ -17,8 +16,8 @@ namespace Prototype
public bool? loop;
public bool GetLoop() => loop ?? false;
public Vector2? distanceRange;
public Vector2 GetDistanceRange() => distanceRange ?? new(30, 200);
public bool? _3d;
public bool Get3D() => _3d ?? false;
public bool? destroyOnLoad;
public bool ShouldDestroyOnLoad() => destroyOnLoad ?? true;
@@ -28,5 +27,8 @@ namespace Prototype
public bool? spatialize;
public bool GetSpatialize() => spatialize ?? false;
public bool? occlusion;
public bool GetOcclusion() => occlusion ?? false;
}
}