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:
1 parent
c25d0777c2
commit
706100e322
8 files changed
+21
-56
No files matched your search
@@ -12,13 +12,14 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: d395190edf0c4124382f84bc10ba3b22, type: 3}
|
||||
m_Name: Hey
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Prototype.SoundEffect
|
||||
distanceRange: {fileID: 11400000, guid: a1e7b7b0fca7d504dbf0a8ea6a4787c8, type: 2}
|
||||
volumeMultiplier: {x: 1, y: 1}
|
||||
pitch: {x: 0.95, y: 1.05}
|
||||
audioMixerGroup: {fileID: 24300002, guid: 4c2f5be6ec68f3e4aa5ef0471d7f2e22, type: 2}
|
||||
volumeMultiplierFactor: 1
|
||||
loop: 0
|
||||
_3d: 1
|
||||
spatialize: 1
|
||||
occlusion: 1
|
||||
defaultVolume: 0.8
|
||||
additionalGain: 0
|
||||
maxPlayInterval: 0
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 523ce7d83fde21c419a5d637cbe7bf04, type: 3}
|
||||
m_Name: Sound Effect Distance Range
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Prototype.SoundEffectDistanceRange
|
||||
range: {x: 0.5, y: 40}
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1e7b7b0fca7d504dbf0a8ea6a4787c8
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user