From d2c9941a75b2e1d95377fc724ca7bf4ee998a1f3 Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Tue, 14 May 2024 04:06:02 +0200 Subject: [PATCH] 4.5.3 --- .gitattributes | 4 + Binaries.meta | 8 + Binaries/Android.meta | 8 + Binaries/Android/arm64.meta | 8 + .../Android/arm64/libaudioplugin_phonon.so | 3 + .../arm64/libaudioplugin_phonon.so.meta | 32 + Binaries/Android/arm64/libphonon.so | 3 + Binaries/Android/arm64/libphonon.so.meta | 32 + Binaries/Android/armv7.meta | 8 + .../Android/armv7/libaudioplugin_phonon.so | 3 + .../armv7/libaudioplugin_phonon.so.meta | 32 + Binaries/Android/armv7/libphonon.so | 3 + Binaries/Android/armv7/libphonon.so.meta | 32 + Binaries/Android/x86.meta | 8 + Binaries/Android/x86/libaudioplugin_phonon.so | 3 + .../Android/x86/libaudioplugin_phonon.so.meta | 32 + Binaries/Android/x86/libphonon.so | 3 + Binaries/Android/x86/libphonon.so.meta | 32 + Binaries/Linux.meta | 8 + Binaries/Linux/x86.meta | 9 + Binaries/Linux/x86/libaudioplugin_phonon.so | 3 + .../Linux/x86/libaudioplugin_phonon.so.meta | 121 + Binaries/Linux/x86/libphonon.so | 3 + Binaries/Linux/x86/libphonon.so.meta | 121 + Binaries/Linux/x86_64.meta | 9 + .../Linux/x86_64/libaudioplugin_phonon.so | 3 + .../x86_64/libaudioplugin_phonon.so.meta | 121 + Binaries/Linux/x86_64/libphonon.so | 3 + Binaries/Linux/x86_64/libphonon.so.meta | 121 + Binaries/Windows.meta | 8 + Binaries/Windows/x86.meta | 8 + Binaries/Windows/x86/audioplugin_phonon.dll | 3 + .../Windows/x86/audioplugin_phonon.dll.meta | 121 + Binaries/Windows/x86/phonon.dll | 3 + Binaries/Windows/x86/phonon.dll.meta | 121 + Binaries/Windows/x86_64.meta | 8 + Binaries/Windows/x86_64/GPUUtilities.dll | 3 + Binaries/Windows/x86_64/GPUUtilities.dll.meta | 63 + Binaries/Windows/x86_64/TrueAudioNext.dll | 3 + .../Windows/x86_64/TrueAudioNext.dll.meta | 63 + .../Windows/x86_64/audioplugin_phonon.dll | 3 + .../x86_64/audioplugin_phonon.dll.meta | 121 + Binaries/Windows/x86_64/phonon.dll | 3 + Binaries/Windows/x86_64/phonon.dll.meta | 109 + Resources.meta | 8 + Resources/Materials.meta | 8 + Resources/Materials/Brick.asset | 21 + Resources/Materials/Brick.asset.meta | 8 + Resources/Materials/Carpet.asset | 21 + Resources/Materials/Carpet.asset.meta | 8 + Resources/Materials/Ceramic.asset | 21 + Resources/Materials/Ceramic.asset.meta | 8 + Resources/Materials/Concrete.asset | 21 + Resources/Materials/Concrete.asset.meta | 8 + Resources/Materials/Default.asset | 21 + Resources/Materials/Default.asset.meta | 8 + Resources/Materials/Glass.asset | 21 + Resources/Materials/Glass.asset.meta | 8 + Resources/Materials/Gravel.asset | 21 + Resources/Materials/Gravel.asset.meta | 8 + Resources/Materials/Metal.asset | 21 + Resources/Materials/Metal.asset.meta | 8 + Resources/Materials/Plaster.asset | 21 + Resources/Materials/Plaster.asset.meta | 8 + Resources/Materials/Rock.asset | 21 + Resources/Materials/Rock.asset.meta | 8 + Resources/Materials/Wood.asset | 21 + Resources/Materials/Wood.asset.meta | 8 + Resources/SteamAudioSettings.asset | 59 + Resources/SteamAudioSettings.asset.meta | 8 + Scripts.meta | 8 + Scripts/Editor.meta | 8 + Scripts/Editor/Build.cs | 105 + Scripts/Editor/Build.cs.meta | 11 + Scripts/Editor/SOFAFileEditor.cs | 33 + Scripts/Editor/SOFAFileEditor.cs.meta | 11 + Scripts/Editor/SOFAFileImporter.cs | 50 + Scripts/Editor/SOFAFileImporter.cs.meta | 11 + Scripts/Editor/SOFAFileImporterEditor.cs | 41 + Scripts/Editor/SOFAFileImporterEditor.cs.meta | 11 + Scripts/Editor/SerializedDataInspector.cs | 41 + .../Editor/SerializedDataInspector.cs.meta | 11 + .../SteamAudioAmbisonicSourceInspector.cs | 50 + ...SteamAudioAmbisonicSourceInspector.cs.meta | 11 + .../SteamAudioBakedListenerInspector.cs | 97 + .../SteamAudioBakedListenerInspector.cs.meta | 11 + .../Editor/SteamAudioBakedSourceInspector.cs | 97 + .../SteamAudioBakedSourceInspector.cs.meta | 11 + .../SteamAudioDynamicObjectInspector.cs | 75 + .../SteamAudioDynamicObjectInspector.cs.meta | 11 + Scripts/Editor/SteamAudioGeometryInspector.cs | 70 + .../SteamAudioGeometryInspector.cs.meta | 11 + Scripts/Editor/SteamAudioListenerInspector.cs | 108 + .../SteamAudioListenerInspector.cs.meta | 11 + Scripts/Editor/SteamAudioManagerInspector.cs | 57 + .../Editor/SteamAudioManagerInspector.cs.meta | 11 + Scripts/Editor/SteamAudioMaterialInspector.cs | 59 + .../SteamAudioMaterialInspector.cs.meta | 12 + Scripts/Editor/SteamAudioMixerReturnGUI.cs | 74 + .../Editor/SteamAudioMixerReturnGUI.cs.meta | 12 + .../Editor/SteamAudioProbeBatchInspector.cs | 143 ++ .../SteamAudioProbeBatchInspector.cs.meta | 11 + Scripts/Editor/SteamAudioReverbGUI.cs | 74 + Scripts/Editor/SteamAudioReverbGUI.cs.meta | 12 + Scripts/Editor/SteamAudioSettingsInspector.cs | 233 ++ .../SteamAudioSettingsInspector.cs.meta | 11 + Scripts/Editor/SteamAudioSourceInspector.cs | 346 +++ .../Editor/SteamAudioSourceInspector.cs.meta | 11 + .../Editor/SteamAudioStaticMeshInspector.cs | 75 + .../SteamAudioStaticMeshInspector.cs.meta | 11 + Scripts/Editor/SteamAudioUnityEditor.asmdef | 17 + .../Editor/SteamAudioUnityEditor.asmdef.meta | 7 + Scripts/Runtime.meta | 8 + Scripts/Runtime/AudioEngineAmbisonicSource.cs | 46 + .../AudioEngineAmbisonicSource.cs.meta | 11 + Scripts/Runtime/AudioEngineSource.cs | 59 + Scripts/Runtime/AudioEngineSource.cs.meta | 11 + Scripts/Runtime/AudioEngineState.cs | 89 + Scripts/Runtime/AudioEngineState.cs.meta | 11 + Scripts/Runtime/Baker.cs | 349 +++ Scripts/Runtime/Baker.cs.meta | 11 + Scripts/Runtime/Common.cs | 188 ++ Scripts/Runtime/Common.cs.meta | 11 + Scripts/Runtime/Context.cs | 84 + Scripts/Runtime/Context.cs.meta | 11 + Scripts/Runtime/EmbreeDevice.cs | 54 + Scripts/Runtime/EmbreeDevice.cs.meta | 11 + .../Runtime/FMODStudioAudioEngineSource.cs | 186 ++ .../FMODStudioAudioEngineSource.cs.meta | 11 + Scripts/Runtime/FMODStudioAudioEngineState.cs | 109 + .../FMODStudioAudioEngineState.cs.meta | 11 + Scripts/Runtime/HRTF.cs | 102 + Scripts/Runtime/HRTF.cs.meta | 11 + Scripts/Runtime/InstancedMesh.cs | 77 + Scripts/Runtime/InstancedMesh.cs.meta | 11 + Scripts/Runtime/OpenCLDevice.cs | 94 + Scripts/Runtime/OpenCLDevice.cs.meta | 11 + Scripts/Runtime/ProbeBatch.cs | 151 ++ Scripts/Runtime/ProbeBatch.cs.meta | 11 + Scripts/Runtime/RadeonRaysDevice.cs | 54 + Scripts/Runtime/RadeonRaysDevice.cs.meta | 11 + Scripts/Runtime/SOFAFile.cs | 38 + Scripts/Runtime/SOFAFile.cs.meta | 11 + Scripts/Runtime/Scene.cs | 114 + Scripts/Runtime/Scene.cs.meta | 11 + Scripts/Runtime/SerializedData.cs | 45 + Scripts/Runtime/SerializedData.cs.meta | 11 + Scripts/Runtime/SerializedObject.cs | 141 ++ Scripts/Runtime/SerializedObject.cs.meta | 11 + Scripts/Runtime/Simulator.cs | 152 ++ Scripts/Runtime/Simulator.cs.meta | 11 + Scripts/Runtime/StaticMesh.cs | 136 ++ Scripts/Runtime/StaticMesh.cs.meta | 11 + Scripts/Runtime/SteamAudio.cs | 1372 +++++++++++ Scripts/Runtime/SteamAudio.cs.meta | 11 + Scripts/Runtime/SteamAudioAmbisonicSource.cs | 74 + .../Runtime/SteamAudioAmbisonicSource.cs.meta | 11 + Scripts/Runtime/SteamAudioBakedListener.cs | 150 ++ .../Runtime/SteamAudioBakedListener.cs.meta | 11 + Scripts/Runtime/SteamAudioBakedSource.cs | 150 ++ Scripts/Runtime/SteamAudioBakedSource.cs.meta | 11 + Scripts/Runtime/SteamAudioDynamicObject.cs | 82 + .../Runtime/SteamAudioDynamicObject.cs.meta | 11 + Scripts/Runtime/SteamAudioFMODStudio.cs | 76 + Scripts/Runtime/SteamAudioFMODStudio.cs.meta | 11 + Scripts/Runtime/SteamAudioGeometry.cs | 74 + Scripts/Runtime/SteamAudioGeometry.cs.meta | 12 + Scripts/Runtime/SteamAudioListener.cs | 247 ++ Scripts/Runtime/SteamAudioListener.cs.meta | 11 + Scripts/Runtime/SteamAudioManager.cs | 2059 +++++++++++++++++ Scripts/Runtime/SteamAudioManager.cs.meta | 11 + Scripts/Runtime/SteamAudioMaterial.cs | 55 + Scripts/Runtime/SteamAudioMaterial.cs.meta | 11 + Scripts/Runtime/SteamAudioProbeBatch.cs | 344 +++ Scripts/Runtime/SteamAudioProbeBatch.cs.meta | 11 + Scripts/Runtime/SteamAudioSettings.cs | 163 ++ Scripts/Runtime/SteamAudioSettings.cs.meta | 12 + Scripts/Runtime/SteamAudioSource.cs | 544 +++++ Scripts/Runtime/SteamAudioSource.cs.meta | 11 + Scripts/Runtime/SteamAudioStaticMesh.cs | 80 + Scripts/Runtime/SteamAudioStaticMesh.cs.meta | 11 + Scripts/Runtime/TrueAudioNextDevice.cs | 58 + Scripts/Runtime/TrueAudioNextDevice.cs.meta | 11 + .../UnityAudioEngineAmbisonicSource.cs | 40 + .../UnityAudioEngineAmbisonicSource.cs.meta | 11 + Scripts/Runtime/UnityAudioEngineSource.cs | 94 + .../Runtime/UnityAudioEngineSource.cs.meta | 11 + Scripts/Runtime/UnityAudioEngineState.cs | 76 + Scripts/Runtime/UnityAudioEngineState.cs.meta | 11 + SteamAudioUnity.asmdef | 14 + SteamAudioUnity.asmdef.meta | 7 + 191 files changed, 12353 insertions(+) create mode 100644 .gitattributes create mode 100755 Binaries.meta create mode 100755 Binaries/Android.meta create mode 100755 Binaries/Android/arm64.meta create mode 100755 Binaries/Android/arm64/libaudioplugin_phonon.so create mode 100755 Binaries/Android/arm64/libaudioplugin_phonon.so.meta create mode 100755 Binaries/Android/arm64/libphonon.so create mode 100755 Binaries/Android/arm64/libphonon.so.meta create mode 100755 Binaries/Android/armv7.meta create mode 100755 Binaries/Android/armv7/libaudioplugin_phonon.so create mode 100755 Binaries/Android/armv7/libaudioplugin_phonon.so.meta create mode 100755 Binaries/Android/armv7/libphonon.so create mode 100755 Binaries/Android/armv7/libphonon.so.meta create mode 100755 Binaries/Android/x86.meta create mode 100755 Binaries/Android/x86/libaudioplugin_phonon.so create mode 100755 Binaries/Android/x86/libaudioplugin_phonon.so.meta create mode 100755 Binaries/Android/x86/libphonon.so create mode 100755 Binaries/Android/x86/libphonon.so.meta create mode 100755 Binaries/Linux.meta create mode 100755 Binaries/Linux/x86.meta create mode 100755 Binaries/Linux/x86/libaudioplugin_phonon.so create mode 100755 Binaries/Linux/x86/libaudioplugin_phonon.so.meta create mode 100755 Binaries/Linux/x86/libphonon.so create mode 100755 Binaries/Linux/x86/libphonon.so.meta create mode 100755 Binaries/Linux/x86_64.meta create mode 100755 Binaries/Linux/x86_64/libaudioplugin_phonon.so create mode 100755 Binaries/Linux/x86_64/libaudioplugin_phonon.so.meta create mode 100755 Binaries/Linux/x86_64/libphonon.so create mode 100755 Binaries/Linux/x86_64/libphonon.so.meta create mode 100755 Binaries/Windows.meta create mode 100755 Binaries/Windows/x86.meta create mode 100755 Binaries/Windows/x86/audioplugin_phonon.dll create mode 100755 Binaries/Windows/x86/audioplugin_phonon.dll.meta create mode 100755 Binaries/Windows/x86/phonon.dll create mode 100755 Binaries/Windows/x86/phonon.dll.meta create mode 100755 Binaries/Windows/x86_64.meta create mode 100755 Binaries/Windows/x86_64/GPUUtilities.dll create mode 100755 Binaries/Windows/x86_64/GPUUtilities.dll.meta create mode 100755 Binaries/Windows/x86_64/TrueAudioNext.dll create mode 100755 Binaries/Windows/x86_64/TrueAudioNext.dll.meta create mode 100755 Binaries/Windows/x86_64/audioplugin_phonon.dll create mode 100755 Binaries/Windows/x86_64/audioplugin_phonon.dll.meta create mode 100755 Binaries/Windows/x86_64/phonon.dll create mode 100755 Binaries/Windows/x86_64/phonon.dll.meta create mode 100755 Resources.meta create mode 100755 Resources/Materials.meta create mode 100755 Resources/Materials/Brick.asset create mode 100755 Resources/Materials/Brick.asset.meta create mode 100755 Resources/Materials/Carpet.asset create mode 100755 Resources/Materials/Carpet.asset.meta create mode 100755 Resources/Materials/Ceramic.asset create mode 100755 Resources/Materials/Ceramic.asset.meta create mode 100755 Resources/Materials/Concrete.asset create mode 100755 Resources/Materials/Concrete.asset.meta create mode 100755 Resources/Materials/Default.asset create mode 100755 Resources/Materials/Default.asset.meta create mode 100755 Resources/Materials/Glass.asset create mode 100755 Resources/Materials/Glass.asset.meta create mode 100755 Resources/Materials/Gravel.asset create mode 100755 Resources/Materials/Gravel.asset.meta create mode 100755 Resources/Materials/Metal.asset create mode 100755 Resources/Materials/Metal.asset.meta create mode 100755 Resources/Materials/Plaster.asset create mode 100755 Resources/Materials/Plaster.asset.meta create mode 100755 Resources/Materials/Rock.asset create mode 100755 Resources/Materials/Rock.asset.meta create mode 100755 Resources/Materials/Wood.asset create mode 100755 Resources/Materials/Wood.asset.meta create mode 100644 Resources/SteamAudioSettings.asset create mode 100644 Resources/SteamAudioSettings.asset.meta create mode 100755 Scripts.meta create mode 100755 Scripts/Editor.meta create mode 100755 Scripts/Editor/Build.cs create mode 100755 Scripts/Editor/Build.cs.meta create mode 100755 Scripts/Editor/SOFAFileEditor.cs create mode 100755 Scripts/Editor/SOFAFileEditor.cs.meta create mode 100755 Scripts/Editor/SOFAFileImporter.cs create mode 100755 Scripts/Editor/SOFAFileImporter.cs.meta create mode 100755 Scripts/Editor/SOFAFileImporterEditor.cs create mode 100755 Scripts/Editor/SOFAFileImporterEditor.cs.meta create mode 100755 Scripts/Editor/SerializedDataInspector.cs create mode 100755 Scripts/Editor/SerializedDataInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs create mode 100755 Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioBakedListenerInspector.cs create mode 100755 Scripts/Editor/SteamAudioBakedListenerInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioBakedSourceInspector.cs create mode 100755 Scripts/Editor/SteamAudioBakedSourceInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioDynamicObjectInspector.cs create mode 100755 Scripts/Editor/SteamAudioDynamicObjectInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioGeometryInspector.cs create mode 100755 Scripts/Editor/SteamAudioGeometryInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioListenerInspector.cs create mode 100755 Scripts/Editor/SteamAudioListenerInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioManagerInspector.cs create mode 100755 Scripts/Editor/SteamAudioManagerInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioMaterialInspector.cs create mode 100755 Scripts/Editor/SteamAudioMaterialInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioMixerReturnGUI.cs create mode 100755 Scripts/Editor/SteamAudioMixerReturnGUI.cs.meta create mode 100755 Scripts/Editor/SteamAudioProbeBatchInspector.cs create mode 100755 Scripts/Editor/SteamAudioProbeBatchInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioReverbGUI.cs create mode 100755 Scripts/Editor/SteamAudioReverbGUI.cs.meta create mode 100755 Scripts/Editor/SteamAudioSettingsInspector.cs create mode 100755 Scripts/Editor/SteamAudioSettingsInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioSourceInspector.cs create mode 100755 Scripts/Editor/SteamAudioSourceInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioStaticMeshInspector.cs create mode 100755 Scripts/Editor/SteamAudioStaticMeshInspector.cs.meta create mode 100755 Scripts/Editor/SteamAudioUnityEditor.asmdef create mode 100755 Scripts/Editor/SteamAudioUnityEditor.asmdef.meta create mode 100755 Scripts/Runtime.meta create mode 100755 Scripts/Runtime/AudioEngineAmbisonicSource.cs create mode 100755 Scripts/Runtime/AudioEngineAmbisonicSource.cs.meta create mode 100755 Scripts/Runtime/AudioEngineSource.cs create mode 100755 Scripts/Runtime/AudioEngineSource.cs.meta create mode 100755 Scripts/Runtime/AudioEngineState.cs create mode 100755 Scripts/Runtime/AudioEngineState.cs.meta create mode 100755 Scripts/Runtime/Baker.cs create mode 100755 Scripts/Runtime/Baker.cs.meta create mode 100755 Scripts/Runtime/Common.cs create mode 100755 Scripts/Runtime/Common.cs.meta create mode 100755 Scripts/Runtime/Context.cs create mode 100755 Scripts/Runtime/Context.cs.meta create mode 100755 Scripts/Runtime/EmbreeDevice.cs create mode 100755 Scripts/Runtime/EmbreeDevice.cs.meta create mode 100755 Scripts/Runtime/FMODStudioAudioEngineSource.cs create mode 100755 Scripts/Runtime/FMODStudioAudioEngineSource.cs.meta create mode 100755 Scripts/Runtime/FMODStudioAudioEngineState.cs create mode 100755 Scripts/Runtime/FMODStudioAudioEngineState.cs.meta create mode 100755 Scripts/Runtime/HRTF.cs create mode 100755 Scripts/Runtime/HRTF.cs.meta create mode 100755 Scripts/Runtime/InstancedMesh.cs create mode 100755 Scripts/Runtime/InstancedMesh.cs.meta create mode 100755 Scripts/Runtime/OpenCLDevice.cs create mode 100755 Scripts/Runtime/OpenCLDevice.cs.meta create mode 100755 Scripts/Runtime/ProbeBatch.cs create mode 100755 Scripts/Runtime/ProbeBatch.cs.meta create mode 100755 Scripts/Runtime/RadeonRaysDevice.cs create mode 100755 Scripts/Runtime/RadeonRaysDevice.cs.meta create mode 100755 Scripts/Runtime/SOFAFile.cs create mode 100755 Scripts/Runtime/SOFAFile.cs.meta create mode 100755 Scripts/Runtime/Scene.cs create mode 100755 Scripts/Runtime/Scene.cs.meta create mode 100755 Scripts/Runtime/SerializedData.cs create mode 100755 Scripts/Runtime/SerializedData.cs.meta create mode 100755 Scripts/Runtime/SerializedObject.cs create mode 100755 Scripts/Runtime/SerializedObject.cs.meta create mode 100755 Scripts/Runtime/Simulator.cs create mode 100755 Scripts/Runtime/Simulator.cs.meta create mode 100755 Scripts/Runtime/StaticMesh.cs create mode 100755 Scripts/Runtime/StaticMesh.cs.meta create mode 100755 Scripts/Runtime/SteamAudio.cs create mode 100755 Scripts/Runtime/SteamAudio.cs.meta create mode 100755 Scripts/Runtime/SteamAudioAmbisonicSource.cs create mode 100755 Scripts/Runtime/SteamAudioAmbisonicSource.cs.meta create mode 100755 Scripts/Runtime/SteamAudioBakedListener.cs create mode 100755 Scripts/Runtime/SteamAudioBakedListener.cs.meta create mode 100755 Scripts/Runtime/SteamAudioBakedSource.cs create mode 100755 Scripts/Runtime/SteamAudioBakedSource.cs.meta create mode 100755 Scripts/Runtime/SteamAudioDynamicObject.cs create mode 100755 Scripts/Runtime/SteamAudioDynamicObject.cs.meta create mode 100755 Scripts/Runtime/SteamAudioFMODStudio.cs create mode 100755 Scripts/Runtime/SteamAudioFMODStudio.cs.meta create mode 100755 Scripts/Runtime/SteamAudioGeometry.cs create mode 100755 Scripts/Runtime/SteamAudioGeometry.cs.meta create mode 100755 Scripts/Runtime/SteamAudioListener.cs create mode 100755 Scripts/Runtime/SteamAudioListener.cs.meta create mode 100755 Scripts/Runtime/SteamAudioManager.cs create mode 100755 Scripts/Runtime/SteamAudioManager.cs.meta create mode 100755 Scripts/Runtime/SteamAudioMaterial.cs create mode 100755 Scripts/Runtime/SteamAudioMaterial.cs.meta create mode 100755 Scripts/Runtime/SteamAudioProbeBatch.cs create mode 100755 Scripts/Runtime/SteamAudioProbeBatch.cs.meta create mode 100755 Scripts/Runtime/SteamAudioSettings.cs create mode 100755 Scripts/Runtime/SteamAudioSettings.cs.meta create mode 100755 Scripts/Runtime/SteamAudioSource.cs create mode 100755 Scripts/Runtime/SteamAudioSource.cs.meta create mode 100755 Scripts/Runtime/SteamAudioStaticMesh.cs create mode 100755 Scripts/Runtime/SteamAudioStaticMesh.cs.meta create mode 100755 Scripts/Runtime/TrueAudioNextDevice.cs create mode 100755 Scripts/Runtime/TrueAudioNextDevice.cs.meta create mode 100755 Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs create mode 100755 Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs.meta create mode 100755 Scripts/Runtime/UnityAudioEngineSource.cs create mode 100755 Scripts/Runtime/UnityAudioEngineSource.cs.meta create mode 100755 Scripts/Runtime/UnityAudioEngineState.cs create mode 100755 Scripts/Runtime/UnityAudioEngineState.cs.meta create mode 100755 SteamAudioUnity.asmdef create mode 100755 SteamAudioUnity.asmdef.meta diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..12a3d01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.so filter=lfs diff=lfs merge=lfs -text +*.a filter=lfs diff=lfs merge=lfs -text +*.dll filter=lfs diff=lfs merge=lfs -text +*.bundle filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/Binaries.meta b/Binaries.meta new file mode 100755 index 0000000..384c0ed --- /dev/null +++ b/Binaries.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f382311500bdbdf4e90e5228cb2788bd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android.meta b/Binaries/Android.meta new file mode 100755 index 0000000..503aed9 --- /dev/null +++ b/Binaries/Android.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 702cfdc9907c1db4faf161f65ff4a94e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/arm64.meta b/Binaries/Android/arm64.meta new file mode 100755 index 0000000..f90277d --- /dev/null +++ b/Binaries/Android/arm64.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0c8f13fd3f59e3d4b870ff47df5d5960 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/arm64/libaudioplugin_phonon.so b/Binaries/Android/arm64/libaudioplugin_phonon.so new file mode 100755 index 0000000..e1b58a4 --- /dev/null +++ b/Binaries/Android/arm64/libaudioplugin_phonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2cbeea2f9e8a9574b82e8eddfd9ef01d4f65d28326c0136c7cb3985109110cb2 +size 2988128 diff --git a/Binaries/Android/arm64/libaudioplugin_phonon.so.meta b/Binaries/Android/arm64/libaudioplugin_phonon.so.meta new file mode 100755 index 0000000..902f3df --- /dev/null +++ b/Binaries/Android/arm64/libaudioplugin_phonon.so.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 65d940c607de5fe4083367b48ef41559 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 1 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: + CPU: ARM64 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/arm64/libphonon.so b/Binaries/Android/arm64/libphonon.so new file mode 100755 index 0000000..3d6e3c1 --- /dev/null +++ b/Binaries/Android/arm64/libphonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1beac2ebe1377ec424dc8f6315240426edd77a11aa95674296f3e83f43703d3a +size 23131504 diff --git a/Binaries/Android/arm64/libphonon.so.meta b/Binaries/Android/arm64/libphonon.so.meta new file mode 100755 index 0000000..c91c90a --- /dev/null +++ b/Binaries/Android/arm64/libphonon.so.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 32c74da812273c841a7c6f7adc2cda8f +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: + CPU: ARM64 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/armv7.meta b/Binaries/Android/armv7.meta new file mode 100755 index 0000000..daa177c --- /dev/null +++ b/Binaries/Android/armv7.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 035133931f34382429e3f8f973458818 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/armv7/libaudioplugin_phonon.so b/Binaries/Android/armv7/libaudioplugin_phonon.so new file mode 100755 index 0000000..0b92954 --- /dev/null +++ b/Binaries/Android/armv7/libaudioplugin_phonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8adaa665b95078b5d372f4eeb049a3c17fc346d66b5316b2b457da4b74be5833 +size 1987428 diff --git a/Binaries/Android/armv7/libaudioplugin_phonon.so.meta b/Binaries/Android/armv7/libaudioplugin_phonon.so.meta new file mode 100755 index 0000000..55fb8af --- /dev/null +++ b/Binaries/Android/armv7/libaudioplugin_phonon.so.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 45d56bf06868bce4d98f924a338394cf +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 1 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/armv7/libphonon.so b/Binaries/Android/armv7/libphonon.so new file mode 100755 index 0000000..b39eb63 --- /dev/null +++ b/Binaries/Android/armv7/libphonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c65e4adc09f2a1224d062bd1835dc8e435f0a9867aa46d844c9c36c251b18c0 +size 19627132 diff --git a/Binaries/Android/armv7/libphonon.so.meta b/Binaries/Android/armv7/libphonon.so.meta new file mode 100755 index 0000000..c59f75f --- /dev/null +++ b/Binaries/Android/armv7/libphonon.so.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 3280807063032c6488f8573e637182e0 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/x86.meta b/Binaries/Android/x86.meta new file mode 100755 index 0000000..163a59f --- /dev/null +++ b/Binaries/Android/x86.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 82f970e91fa348c4a9e1443d700f6765 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/x86/libaudioplugin_phonon.so b/Binaries/Android/x86/libaudioplugin_phonon.so new file mode 100755 index 0000000..03ae62c --- /dev/null +++ b/Binaries/Android/x86/libaudioplugin_phonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6572772b2aec9d9969c81339f71217139b060398de2569589a397ea0e4969c48 +size 2495272 diff --git a/Binaries/Android/x86/libaudioplugin_phonon.so.meta b/Binaries/Android/x86/libaudioplugin_phonon.so.meta new file mode 100755 index 0000000..3a9c94a --- /dev/null +++ b/Binaries/Android/x86/libaudioplugin_phonon.so.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 2580d2d5225cd4942b96af150d9380b8 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 1 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: + CPU: x86 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Android/x86/libphonon.so b/Binaries/Android/x86/libphonon.so new file mode 100755 index 0000000..9c314eb --- /dev/null +++ b/Binaries/Android/x86/libphonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c54d600bfc4215fb73d091dba03ec753ba928cc10ef2c6784bae4104849f424 +size 19807996 diff --git a/Binaries/Android/x86/libphonon.so.meta b/Binaries/Android/x86/libphonon.so.meta new file mode 100755 index 0000000..20310bf --- /dev/null +++ b/Binaries/Android/x86/libphonon.so.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: d6d5bdf8052a5e146b27c150cf967d7e +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: + CPU: x86 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux.meta b/Binaries/Linux.meta new file mode 100755 index 0000000..ad88673 --- /dev/null +++ b/Binaries/Linux.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4063b98da3a82e64ea56c5487aacd513 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux/x86.meta b/Binaries/Linux/x86.meta new file mode 100755 index 0000000..e55ae78 --- /dev/null +++ b/Binaries/Linux/x86.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 0b0df2bea2345aa4f9e86bcacbc9608c +folderAsset: yes +timeCreated: 1500590827 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux/x86/libaudioplugin_phonon.so b/Binaries/Linux/x86/libaudioplugin_phonon.so new file mode 100755 index 0000000..5b2c280 --- /dev/null +++ b/Binaries/Linux/x86/libaudioplugin_phonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d44f1b1a71e4572158c720bfe8343af60b6f5579e1bbad5373697564785fcbc6 +size 74648 diff --git a/Binaries/Linux/x86/libaudioplugin_phonon.so.meta b/Binaries/Linux/x86/libaudioplugin_phonon.so.meta new file mode 100755 index 0000000..1aa9b7d --- /dev/null +++ b/Binaries/Linux/x86/libaudioplugin_phonon.so.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: 2bcf76b2e4398cb49b45812674a7ec17 +timeCreated: 1500675747 +licenseType: Free +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 1 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 1 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 0 + Exclude Win64: 0 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86 + OS: Linux + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: x86 + data: + first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: x86 + data: + first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux/x86/libphonon.so b/Binaries/Linux/x86/libphonon.so new file mode 100755 index 0000000..ac1d5c2 --- /dev/null +++ b/Binaries/Linux/x86/libphonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea8609ab190d46cbe206672062005625fa3f67ff56b5372ba29c17e387f98fb5 +size 17604252 diff --git a/Binaries/Linux/x86/libphonon.so.meta b/Binaries/Linux/x86/libphonon.so.meta new file mode 100755 index 0000000..cbddf94 --- /dev/null +++ b/Binaries/Linux/x86/libphonon.so.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: b73d370ef894b8d409fc51247d5b13cf +timeCreated: 1500675748 +licenseType: Free +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 1 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 0 + Exclude Win64: 0 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86 + OS: Linux + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: x86 + data: + first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: x86 + data: + first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux/x86_64.meta b/Binaries/Linux/x86_64.meta new file mode 100755 index 0000000..07fbf06 --- /dev/null +++ b/Binaries/Linux/x86_64.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 72f15056fc1aa3e4e91f7d395110ca58 +folderAsset: yes +timeCreated: 1497043676 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux/x86_64/libaudioplugin_phonon.so b/Binaries/Linux/x86_64/libaudioplugin_phonon.so new file mode 100755 index 0000000..7557ebb --- /dev/null +++ b/Binaries/Linux/x86_64/libaudioplugin_phonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4824a29e7e3516f886513597b780899a6c6f5093457af8d6337bef5bd393099 +size 72792 diff --git a/Binaries/Linux/x86_64/libaudioplugin_phonon.so.meta b/Binaries/Linux/x86_64/libaudioplugin_phonon.so.meta new file mode 100755 index 0000000..a401379 --- /dev/null +++ b/Binaries/Linux/x86_64/libaudioplugin_phonon.so.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: 45e1d12e441bb9a4d875c1c402cc3bab +timeCreated: 1500675747 +licenseType: Free +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 1 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 1 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 0 + Exclude Win64: 0 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86_64 + OS: Linux + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: None + data: + first: + Facebook: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Linux + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: x86_64 + data: + first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Linux/x86_64/libphonon.so b/Binaries/Linux/x86_64/libphonon.so new file mode 100755 index 0000000..5e5cf94 --- /dev/null +++ b/Binaries/Linux/x86_64/libphonon.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a210a6fc5aa3e0d068a74c89b82eadec1fe199e270ef88b3f2ddf4b4c7277260 +size 20861840 diff --git a/Binaries/Linux/x86_64/libphonon.so.meta b/Binaries/Linux/x86_64/libphonon.so.meta new file mode 100755 index 0000000..b066dd8 --- /dev/null +++ b/Binaries/Linux/x86_64/libphonon.so.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: c9ba4a34d9f98f045ac750ca5a13cc0a +timeCreated: 1500675748 +licenseType: Free +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 1 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude Win: 0 + Exclude Win64: 0 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86_64 + OS: Linux + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: None + data: + first: + Facebook: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Linux + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: x86_64 + data: + first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows.meta b/Binaries/Windows.meta new file mode 100755 index 0000000..4a417dc --- /dev/null +++ b/Binaries/Windows.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8d2e4abd33c0b841a8641dfe8a55c02 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86.meta b/Binaries/Windows/x86.meta new file mode 100755 index 0000000..3f0ce5b --- /dev/null +++ b/Binaries/Windows/x86.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b350a431a2f520b4b9d3e7227b7ec517 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86/audioplugin_phonon.dll b/Binaries/Windows/x86/audioplugin_phonon.dll new file mode 100755 index 0000000..5096e97 --- /dev/null +++ b/Binaries/Windows/x86/audioplugin_phonon.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f48bde8e1c20d42341d1fed4fa902cc2e98deb97a6dfba356b86744a08292da8 +size 119808 diff --git a/Binaries/Windows/x86/audioplugin_phonon.dll.meta b/Binaries/Windows/x86/audioplugin_phonon.dll.meta new file mode 100755 index 0000000..708127c --- /dev/null +++ b/Binaries/Windows/x86/audioplugin_phonon.dll.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: 034df7716f3c2ee43b6049cbd524c6d7 +timeCreated: 1500675747 +licenseType: Free +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 1 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 0 + Exclude OSXIntel64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 1 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86 + OS: Windows + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: x86 + data: + first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: OSXIntel + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: OSXIntel64 + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86/phonon.dll b/Binaries/Windows/x86/phonon.dll new file mode 100755 index 0000000..2bde805 --- /dev/null +++ b/Binaries/Windows/x86/phonon.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d3651fe55fd9ae3678bdd23bbc721ee65939e81ae1992b4c9ccac5793c0ca00 +size 16401408 diff --git a/Binaries/Windows/x86/phonon.dll.meta b/Binaries/Windows/x86/phonon.dll.meta new file mode 100755 index 0000000..1247698 --- /dev/null +++ b/Binaries/Windows/x86/phonon.dll.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: df5a46ce5e3327545a16c08880340232 +timeCreated: 1500675748 +licenseType: Free +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 0 + Exclude OSXIntel64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 1 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86 + OS: Windows + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: x86 + data: + first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: OSXIntel + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: OSXIntel64 + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86_64.meta b/Binaries/Windows/x86_64.meta new file mode 100755 index 0000000..c619556 --- /dev/null +++ b/Binaries/Windows/x86_64.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7cba442208850444ea5f98da27753834 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86_64/GPUUtilities.dll b/Binaries/Windows/x86_64/GPUUtilities.dll new file mode 100755 index 0000000..112330c --- /dev/null +++ b/Binaries/Windows/x86_64/GPUUtilities.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e858bf4514aca48eab762adcecaeda1edeccdddfbe97feb8e67795329b2f37d2 +size 72192 diff --git a/Binaries/Windows/x86_64/GPUUtilities.dll.meta b/Binaries/Windows/x86_64/GPUUtilities.dll.meta new file mode 100755 index 0000000..9ab8450 --- /dev/null +++ b/Binaries/Windows/x86_64/GPUUtilities.dll.meta @@ -0,0 +1,63 @@ +fileFormatVersion: 2 +guid: 2a3c4cfa413248a4190297fbd3eb2de7 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 1 + Exclude Win64: 0 + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: x86_64 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86_64/TrueAudioNext.dll b/Binaries/Windows/x86_64/TrueAudioNext.dll new file mode 100755 index 0000000..b62c21f --- /dev/null +++ b/Binaries/Windows/x86_64/TrueAudioNext.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44e94a5de6345ffb2968fb1781e7edaab3ec3d2c0854f93be0bb581b94c5d48c +size 1772032 diff --git a/Binaries/Windows/x86_64/TrueAudioNext.dll.meta b/Binaries/Windows/x86_64/TrueAudioNext.dll.meta new file mode 100755 index 0000000..5959cc4 --- /dev/null +++ b/Binaries/Windows/x86_64/TrueAudioNext.dll.meta @@ -0,0 +1,63 @@ +fileFormatVersion: 2 +guid: 79aa0fc1a754b08408af853b0c212c19 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 1 + Exclude Win64: 0 + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: x86_64 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86_64/audioplugin_phonon.dll b/Binaries/Windows/x86_64/audioplugin_phonon.dll new file mode 100755 index 0000000..df97e6b --- /dev/null +++ b/Binaries/Windows/x86_64/audioplugin_phonon.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dad7fe151ae0f3a32d820a00c4c832c8bfe987bd8531f1a959815a49a9bfbe7 +size 154112 diff --git a/Binaries/Windows/x86_64/audioplugin_phonon.dll.meta b/Binaries/Windows/x86_64/audioplugin_phonon.dll.meta new file mode 100755 index 0000000..9d888b5 --- /dev/null +++ b/Binaries/Windows/x86_64/audioplugin_phonon.dll.meta @@ -0,0 +1,121 @@ +fileFormatVersion: 2 +guid: 5d6635a5cbc49144e9a2194784a1edc1 +timeCreated: 1497043676 +licenseType: Pro +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 1 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 0 + Exclude OSXIntel64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 1 + Exclude Win64: 0 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: x86_64 + OS: Windows + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: None + data: + first: + Facebook: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + data: + first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: OSXIntel + second: + enabled: 1 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Binaries/Windows/x86_64/phonon.dll b/Binaries/Windows/x86_64/phonon.dll new file mode 100755 index 0000000..9348b67 --- /dev/null +++ b/Binaries/Windows/x86_64/phonon.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d2a68d4017d1a1c50e2324da9d591788c351bf60e7a4ec4583c7de4c275433b +size 20901376 diff --git a/Binaries/Windows/x86_64/phonon.dll.meta b/Binaries/Windows/x86_64/phonon.dll.meta new file mode 100755 index 0000000..4299d80 --- /dev/null +++ b/Binaries/Windows/x86_64/phonon.dll.meta @@ -0,0 +1,109 @@ +fileFormatVersion: 2 +guid: 01f204cdd3aa0d449bff1ab94d059ce3 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 0 + Exclude OSXIntel64: 0 + Exclude OSXUniversal: 0 + Exclude Win: 1 + Exclude Win64: 0 + - first: + : Editor + second: + enabled: 0 + settings: + CPU: x86_64 + OS: Windows + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + - first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Facebook: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXIntel + second: + enabled: 1 + settings: + CPU: None + - first: + Standalone: OSXIntel64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources.meta b/Resources.meta new file mode 100755 index 0000000..0bfb0a6 --- /dev/null +++ b/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e5745ad563e845743b8920252a3e6611 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials.meta b/Resources/Materials.meta new file mode 100755 index 0000000..04faae4 --- /dev/null +++ b/Resources/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 88a93f7297473be4f8ebcdf7f46e5102 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Brick.asset b/Resources/Materials/Brick.asset new file mode 100755 index 0000000..1ef3bec --- /dev/null +++ b/Resources/Materials/Brick.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Brick + m_EditorClassIdentifier: + lowFreqAbsorption: 0.03 + midFreqAbsorption: 0.04 + highFreqAbsorption: 0.07 + scattering: 0.05 + lowFreqTransmission: 0.015 + midFreqTransmission: 0.015 + highFreqTransmission: 0.015 diff --git a/Resources/Materials/Brick.asset.meta b/Resources/Materials/Brick.asset.meta new file mode 100755 index 0000000..814358d --- /dev/null +++ b/Resources/Materials/Brick.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed65b244617a3154ba34ebdb722855a9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Carpet.asset b/Resources/Materials/Carpet.asset new file mode 100755 index 0000000..310eba4 --- /dev/null +++ b/Resources/Materials/Carpet.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Carpet + m_EditorClassIdentifier: + lowFreqAbsorption: 0.24 + midFreqAbsorption: 0.69 + highFreqAbsorption: 0.73 + scattering: 0.05 + lowFreqTransmission: 0.02 + midFreqTransmission: 0.005 + highFreqTransmission: 0.003 diff --git a/Resources/Materials/Carpet.asset.meta b/Resources/Materials/Carpet.asset.meta new file mode 100755 index 0000000..ba36996 --- /dev/null +++ b/Resources/Materials/Carpet.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4ef433d5b2fa5ad4a9e19a415c6ab619 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Ceramic.asset b/Resources/Materials/Ceramic.asset new file mode 100755 index 0000000..1d5d8fb --- /dev/null +++ b/Resources/Materials/Ceramic.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Ceramic + m_EditorClassIdentifier: + lowFreqAbsorption: 0.01 + midFreqAbsorption: 0.01 + highFreqAbsorption: 0.02 + scattering: 0.05 + lowFreqTransmission: 0.06 + midFreqTransmission: 0.044 + highFreqTransmission: 0.011 diff --git a/Resources/Materials/Ceramic.asset.meta b/Resources/Materials/Ceramic.asset.meta new file mode 100755 index 0000000..c1941c1 --- /dev/null +++ b/Resources/Materials/Ceramic.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1ae39e85ad35335439c46ec8a6d27ea9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Concrete.asset b/Resources/Materials/Concrete.asset new file mode 100755 index 0000000..b0b2ffb --- /dev/null +++ b/Resources/Materials/Concrete.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Concrete + m_EditorClassIdentifier: + lowFreqAbsorption: 0.05 + midFreqAbsorption: 0.07 + highFreqAbsorption: 0.08 + scattering: 0.05 + lowFreqTransmission: 0.015 + midFreqTransmission: 0.002 + highFreqTransmission: 0.001 diff --git a/Resources/Materials/Concrete.asset.meta b/Resources/Materials/Concrete.asset.meta new file mode 100755 index 0000000..065d9a5 --- /dev/null +++ b/Resources/Materials/Concrete.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2a011bab5de11df4c81c68931509f73a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Default.asset b/Resources/Materials/Default.asset new file mode 100755 index 0000000..86a2609 --- /dev/null +++ b/Resources/Materials/Default.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Default + m_EditorClassIdentifier: + lowFreqAbsorption: 0.1 + midFreqAbsorption: 0.2 + highFreqAbsorption: 0.3 + scattering: 0.05 + lowFreqTransmission: 0.1 + midFreqTransmission: 0.05 + highFreqTransmission: 0.03 diff --git a/Resources/Materials/Default.asset.meta b/Resources/Materials/Default.asset.meta new file mode 100755 index 0000000..b8f5e21 --- /dev/null +++ b/Resources/Materials/Default.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a086f686223eed942816c70be67841b0 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Glass.asset b/Resources/Materials/Glass.asset new file mode 100755 index 0000000..496a7db --- /dev/null +++ b/Resources/Materials/Glass.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Glass + m_EditorClassIdentifier: + lowFreqAbsorption: 0.06 + midFreqAbsorption: 0.03 + highFreqAbsorption: 0.02 + scattering: 0.05 + lowFreqTransmission: 0.06 + midFreqTransmission: 0.044 + highFreqTransmission: 0.011 diff --git a/Resources/Materials/Glass.asset.meta b/Resources/Materials/Glass.asset.meta new file mode 100755 index 0000000..08e2528 --- /dev/null +++ b/Resources/Materials/Glass.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 08bf73ad12cb44944875b02ce7f9d694 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Gravel.asset b/Resources/Materials/Gravel.asset new file mode 100755 index 0000000..e7769d6 --- /dev/null +++ b/Resources/Materials/Gravel.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Gravel + m_EditorClassIdentifier: + lowFreqAbsorption: 0.6 + midFreqAbsorption: 0.7 + highFreqAbsorption: 0.8 + scattering: 0.05 + lowFreqTransmission: 0.031 + midFreqTransmission: 0.012 + highFreqTransmission: 0.008 diff --git a/Resources/Materials/Gravel.asset.meta b/Resources/Materials/Gravel.asset.meta new file mode 100755 index 0000000..b34166e --- /dev/null +++ b/Resources/Materials/Gravel.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b1c2b85c159e39042b3aa49340f34357 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Metal.asset b/Resources/Materials/Metal.asset new file mode 100755 index 0000000..a80c01f --- /dev/null +++ b/Resources/Materials/Metal.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Metal + m_EditorClassIdentifier: + lowFreqAbsorption: 0.2 + midFreqAbsorption: 0.07 + highFreqAbsorption: 0.06 + scattering: 0.05 + lowFreqTransmission: 0.2 + midFreqTransmission: 0.025 + highFreqTransmission: 0.01 diff --git a/Resources/Materials/Metal.asset.meta b/Resources/Materials/Metal.asset.meta new file mode 100755 index 0000000..e160946 --- /dev/null +++ b/Resources/Materials/Metal.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d780f25df1d231d4aa9a31ab3ba935d0 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Plaster.asset b/Resources/Materials/Plaster.asset new file mode 100755 index 0000000..b8f770e --- /dev/null +++ b/Resources/Materials/Plaster.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Plaster + m_EditorClassIdentifier: + lowFreqAbsorption: 0.12 + midFreqAbsorption: 0.06 + highFreqAbsorption: 0.04 + scattering: 0.05 + lowFreqTransmission: 0.056 + midFreqTransmission: 0.056 + highFreqTransmission: 0.004 diff --git a/Resources/Materials/Plaster.asset.meta b/Resources/Materials/Plaster.asset.meta new file mode 100755 index 0000000..604c745 --- /dev/null +++ b/Resources/Materials/Plaster.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9e0a6d5705eaec64ab63e6ac7132e0a7 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Rock.asset b/Resources/Materials/Rock.asset new file mode 100755 index 0000000..ae6063c --- /dev/null +++ b/Resources/Materials/Rock.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Rock + m_EditorClassIdentifier: + lowFreqAbsorption: 0.13 + midFreqAbsorption: 0.2 + highFreqAbsorption: 0.24 + scattering: 0.05 + lowFreqTransmission: 0.015 + midFreqTransmission: 0.002 + highFreqTransmission: 0.001 diff --git a/Resources/Materials/Rock.asset.meta b/Resources/Materials/Rock.asset.meta new file mode 100755 index 0000000..f658d60 --- /dev/null +++ b/Resources/Materials/Rock.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5c0320d65bcecce4abf2efe02ff313aa +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/Materials/Wood.asset b/Resources/Materials/Wood.asset new file mode 100755 index 0000000..cb3b2ac --- /dev/null +++ b/Resources/Materials/Wood.asset @@ -0,0 +1,21 @@ +%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: 1cb82a87a4954a947923856a12b49b38, type: 3} + m_Name: Wood + m_EditorClassIdentifier: + lowFreqAbsorption: 0.11 + midFreqAbsorption: 0.07 + highFreqAbsorption: 0.06 + scattering: 0.05 + lowFreqTransmission: 0.07 + midFreqTransmission: 0.014 + highFreqTransmission: 0.005 diff --git a/Resources/Materials/Wood.asset.meta b/Resources/Materials/Wood.asset.meta new file mode 100755 index 0000000..ee6b381 --- /dev/null +++ b/Resources/Materials/Wood.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5272c55b882edd34a9d80b11bd6f240c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Resources/SteamAudioSettings.asset b/Resources/SteamAudioSettings.asset new file mode 100644 index 0000000..de0628c --- /dev/null +++ b/Resources/SteamAudioSettings.asset @@ -0,0 +1,59 @@ +%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: f3efcebd75ef2af49badc83215c91685, type: 3} + m_Name: SteamAudioSettings + m_EditorClassIdentifier: + audioEngine: 0 + perspectiveCorrection: 0 + perspectiveCorrectionFactor: 1 + hrtfVolumeGainDB: 0 + hrtfNormalizationType: 0 + SOFAFiles: [] + defaultMaterial: {fileID: 11400000, guid: a086f686223eed942816c70be67841b0, type: 2} + sceneType: 1 + layerMask: + serializedVersion: 2 + m_Bits: 0 + maxOcclusionSamples: 16 + realTimeRays: 4096 + realTimeBounces: 4 + realTimeDuration: 1 + realTimeAmbisonicOrder: 1 + realTimeMaxSources: 32 + realTimeCPUCoresPercentage: 5 + realTimeIrradianceMinDistance: 1 + bakeConvolution: 1 + bakeParametric: 0 + bakingRays: 16384 + bakingBounces: 16 + bakingDuration: 1 + bakingAmbisonicOrder: 1 + bakingCPUCoresPercentage: 50 + bakingIrradianceMinDistance: 1 + bakingVisibilitySamples: 4 + bakingVisibilityRadius: 1 + bakingVisibilityThreshold: 0.1 + bakingVisibilityRange: 1000 + bakingPathRange: 1000 + bakedPathingCPUCoresPercentage: 50 + simulationUpdateInterval: 0.1 + reflectionEffectType: 0 + hybridReverbTransitionTime: 1 + hybridReverbOverlapPercent: 25 + deviceType: 2 + maxReservedComputeUnits: 8 + fractionComputeUnitsForIRUpdate: 0.5 + bakingBatchSize: 8 + TANDuration: 1 + TANAmbisonicOrder: 1 + TANMaxSources: 32 + EnableValidation: 0 diff --git a/Resources/SteamAudioSettings.asset.meta b/Resources/SteamAudioSettings.asset.meta new file mode 100644 index 0000000..750d9c6 --- /dev/null +++ b/Resources/SteamAudioSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ff1b2a159df1c3cfdbe348cc31ca3268 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts.meta b/Scripts.meta new file mode 100755 index 0000000..8743aad --- /dev/null +++ b/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ea85a97536b166141a47b7f51400324c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor.meta b/Scripts/Editor.meta new file mode 100755 index 0000000..296117f --- /dev/null +++ b/Scripts/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5daecada1ea129e47a5e0decc073a3af +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/Build.cs b/Scripts/Editor/Build.cs new file mode 100755 index 0000000..5aa8ebd --- /dev/null +++ b/Scripts/Editor/Build.cs @@ -0,0 +1,105 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; // deleteme? +using UnityEditor; +#if UNITY_2021_2_OR_NEWER +using UnityEditor.Build; +#endif +using UnityEditor.Callbacks; +#if UNITY_IOS +using UnityEditor.iOS.Xcode; +#endif + +namespace SteamAudio +{ + public static class Build + { + public static void BuildSteamAudio() + { + var args = Environment.GetCommandLineArgs(); + var lastArg = args[args.Length - 1]; + + var fileName = "SteamAudio.unitypackage"; + if (lastArg != "SteamAudio.Build.BuildSteamAudio") + { + fileName = lastArg + "/" + fileName; + } + + var assets = new string[] { "Assets/Plugins" }; + + AssetDatabase.ExportPackage(assets, fileName, ExportPackageOptions.Recurse); + } + } + + [InitializeOnLoad] + public static class Defines + { + // Define the constant STEAMAUDIO_ENABLED for all platforms that are supported by + // Steam Audio. User scripts should check if this constant is defined + // (using #if STEAMAUDIO_ENABLED) before using any of the Steam Audio C# classes. + static Defines() + { +#if UNITY_2021_2_OR_NEWER + NamedBuildTarget[] supportedPlatforms = { + NamedBuildTarget.Standalone, + NamedBuildTarget.Android, + NamedBuildTarget.iOS, + }; + + foreach (var supportedPlatform in supportedPlatforms) + { + var defines = PlayerSettings.GetScriptingDefineSymbols(supportedPlatform); + if (!defines.Contains("STEAMAUDIO_ENABLED")) + { + if (defines.Length > 0) + { + defines += ";"; + } + + defines += "STEAMAUDIO_ENABLED"; + + PlayerSettings.SetScriptingDefineSymbols(supportedPlatform, defines); + } + } +#endif + } + } + + public static class BuildProcessor + { + [PostProcessBuild] + public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath) + { + if (buildTarget == BuildTarget.iOS) + { +#if UNITY_IOS + var projectPath = PBXProject.GetPBXProjectPath(buildPath); + + var project = new PBXProject(); + project.ReadFromFile(projectPath); + + var file = project.AddFile("usr/lib/libz.tbd", "Frameworks/libz.tbd", PBXSourceTree.Sdk); + var target = project.TargetGuidByName("UnityFramework"); + project.AddFileToBuild(target, file); + + project.WriteToFile(projectPath); +#endif + } + } + } +} diff --git a/Scripts/Editor/Build.cs.meta b/Scripts/Editor/Build.cs.meta new file mode 100755 index 0000000..a05ba06 --- /dev/null +++ b/Scripts/Editor/Build.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4cf552bb6c6d7894c8e64136a5d4a41c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SOFAFileEditor.cs b/Scripts/Editor/SOFAFileEditor.cs new file mode 100755 index 0000000..0d0465b --- /dev/null +++ b/Scripts/Editor/SOFAFileEditor.cs @@ -0,0 +1,33 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; + +namespace SteamAudio +{ + /* + * Custom editor GUI for SOFAFile assets. + */ + [CustomEditor(typeof(SOFAFile))] + public class SOFAFileEditor : Editor + { + public override void OnInspectorGUI() + { + EditorGUILayout.PropertyField(serializedObject.FindProperty("sofaName")); + EditorGUILayout.LabelField("Size", Common.HumanReadableDataSize(serializedObject.FindProperty("data").arraySize)); + } + } +} diff --git a/Scripts/Editor/SOFAFileEditor.cs.meta b/Scripts/Editor/SOFAFileEditor.cs.meta new file mode 100755 index 0000000..83de605 --- /dev/null +++ b/Scripts/Editor/SOFAFileEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad7854f3d94e96f4795542d446b68921 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SOFAFileImporter.cs b/Scripts/Editor/SOFAFileImporter.cs new file mode 100755 index 0000000..fa625b2 --- /dev/null +++ b/Scripts/Editor/SOFAFileImporter.cs @@ -0,0 +1,50 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System.IO; +using UnityEngine; +#if UNITY_2020_2_OR_NEWER +using UnityEditor.AssetImporters; +#else +using UnityEditor.Experimental.AssetImporters; +#endif + +namespace SteamAudio +{ + /* + * Imports .sofa files as SOFAFile asset objects. + */ + [ScriptedImporter(2, "sofa")] + public class SOFAFileImporter : ScriptedImporter + { + [Range(-12.0f, 12.0f)] + public float hrtfVolumeGainDB = 0.0f; + public HRTFNormType hrtfNormalizationType = HRTFNormType.None; + + public override void OnImportAsset(AssetImportContext ctx) + { + var sofaFile = ScriptableObject.CreateInstance(); + + sofaFile.sofaName = Path.GetFileName(ctx.assetPath); + sofaFile.data = File.ReadAllBytes(ctx.assetPath); + sofaFile.volume = hrtfVolumeGainDB; + sofaFile.normType = hrtfNormalizationType; + + ctx.AddObjectToAsset("sofa file", sofaFile); + ctx.SetMainObject(sofaFile); + } + } +} diff --git a/Scripts/Editor/SOFAFileImporter.cs.meta b/Scripts/Editor/SOFAFileImporter.cs.meta new file mode 100755 index 0000000..907f796 --- /dev/null +++ b/Scripts/Editor/SOFAFileImporter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1731f5ddf70efee4c8320ac591373b56 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SOFAFileImporterEditor.cs b/Scripts/Editor/SOFAFileImporterEditor.cs new file mode 100755 index 0000000..ba1895d --- /dev/null +++ b/Scripts/Editor/SOFAFileImporterEditor.cs @@ -0,0 +1,41 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; +#if UNITY_2020_2_OR_NEWER +using UnityEditor.AssetImporters; +#else +using UnityEditor.Experimental.AssetImporters; +#endif + +namespace SteamAudio +{ + /* + * Custom editor GUI for SOFAFile import settings. + */ + [CustomEditor(typeof(SOFAFileImporter))] + public class SOFAFileImporterEditor : ScriptedImporterEditor + { + public override void OnInspectorGUI() + { + serializedObject.Update(); + EditorGUILayout.PropertyField(serializedObject.FindProperty("hrtfVolumeGainDB"), new UnityEngine.GUIContent("HRTF Volume Gain (dB)")); + EditorGUILayout.PropertyField(serializedObject.FindProperty("hrtfNormalizationType"), new UnityEngine.GUIContent("HRTF Normalization Type")); + serializedObject.ApplyModifiedProperties(); + ApplyRevertGUI(); + } + } +} diff --git a/Scripts/Editor/SOFAFileImporterEditor.cs.meta b/Scripts/Editor/SOFAFileImporterEditor.cs.meta new file mode 100755 index 0000000..c78ac25 --- /dev/null +++ b/Scripts/Editor/SOFAFileImporterEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d3653cc84febdd64e8064c9e17883043 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SerializedDataInspector.cs b/Scripts/Editor/SerializedDataInspector.cs new file mode 100755 index 0000000..e4666ef --- /dev/null +++ b/Scripts/Editor/SerializedDataInspector.cs @@ -0,0 +1,41 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SerializedData))] + public class SerializedDataInspector : Editor + { + SerializedProperty mData; + + private void OnEnable() + { + mData = serializedObject.FindProperty("data"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + var size = mData.arraySize; + EditorGUILayout.LabelField("Serialized Data", Common.HumanReadableDataSize(size)); + + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/Scripts/Editor/SerializedDataInspector.cs.meta b/Scripts/Editor/SerializedDataInspector.cs.meta new file mode 100755 index 0000000..ab4ec2b --- /dev/null +++ b/Scripts/Editor/SerializedDataInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9184af0375b7f6140be4f789b5fc7083 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs b/Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs new file mode 100755 index 0000000..61022a7 --- /dev/null +++ b/Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs @@ -0,0 +1,50 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioAmbisonicSource))] + [CanEditMultipleObjects] + public class SteamAudioAmbisonicSourceInspector : Editor + { + SerializedProperty mApplyHRTF; + + private void OnEnable() + { + mApplyHRTF = serializedObject.FindProperty("applyHRTF"); + } + + public override void OnInspectorGUI() + { + if (SteamAudioSettings.Singleton.audioEngine != AudioEngineType.Unity) + { + EditorGUILayout.HelpBox( + "This component requires the audio engine to be set to Unity. Click" + + "Steam Audio > Settings to change this.", MessageType.Warning); + + return; + } + + serializedObject.Update(); + + EditorGUILayout.PropertyField(mApplyHRTF); + + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs.meta b/Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs.meta new file mode 100755 index 0000000..2f586c9 --- /dev/null +++ b/Scripts/Editor/SteamAudioAmbisonicSourceInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 93bd07e672dff904ea2291dd4ac45a45 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioBakedListenerInspector.cs b/Scripts/Editor/SteamAudioBakedListenerInspector.cs new file mode 100755 index 0000000..49844a2 --- /dev/null +++ b/Scripts/Editor/SteamAudioBakedListenerInspector.cs @@ -0,0 +1,97 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioBakedListener))] + public class SteamAudioBakedListenerInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mInfluenceRadius; + SerializedProperty mUseAllProbeBatches; + SerializedProperty mProbeBatches; + + bool mStatsFoldout = false; + bool mShouldShowProgressBar = false; + + private void OnEnable() + { + mInfluenceRadius = serializedObject.FindProperty("influenceRadius"); + mUseAllProbeBatches = serializedObject.FindProperty("useAllProbeBatches"); + mProbeBatches = serializedObject.FindProperty("probeBatches"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + var oldGUIEnabled = GUI.enabled; + GUI.enabled = !Baker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; + + var tgt = target as SteamAudioBakedListener; + + EditorGUILayout.PropertyField(mInfluenceRadius); + EditorGUILayout.PropertyField(mUseAllProbeBatches); + if (!mUseAllProbeBatches.boolValue) + { + EditorGUILayout.PropertyField(mProbeBatches); + } + + EditorGUILayout.Space(); + if (GUILayout.Button("Bake")) + { + tgt.BeginBake(); + mShouldShowProgressBar = true; + } + + GUI.enabled = oldGUIEnabled; + + if (mShouldShowProgressBar && !Baker.IsBakeActive()) + { + mShouldShowProgressBar = false; + } + + if (mShouldShowProgressBar) + { + Baker.DrawProgressBar(); + } + + Repaint(); + + EditorGUILayout.Space(); + mStatsFoldout = EditorGUILayout.Foldout(mStatsFoldout, "Baked Data Statistics"); + if (mStatsFoldout && !Baker.IsBakeActive()) + { + for (var i = 0; i < tgt.GetProbeBatchesUsed().Length; ++i) + { + EditorGUILayout.LabelField(tgt.GetProbeBatchesUsed()[i].gameObject.name, Common.HumanReadableDataSize(tgt.GetProbeDataSizes()[i])); + } + EditorGUILayout.LabelField("Total Size", Common.HumanReadableDataSize(tgt.GetTotalDataSize())); + } + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioBakedListenerInspector.cs.meta b/Scripts/Editor/SteamAudioBakedListenerInspector.cs.meta new file mode 100755 index 0000000..59e1307 --- /dev/null +++ b/Scripts/Editor/SteamAudioBakedListenerInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e99d6d8163e0e24cadf1add0983102e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioBakedSourceInspector.cs b/Scripts/Editor/SteamAudioBakedSourceInspector.cs new file mode 100755 index 0000000..afd558d --- /dev/null +++ b/Scripts/Editor/SteamAudioBakedSourceInspector.cs @@ -0,0 +1,97 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioBakedSource))] + public class SteamAudioBakedSourceInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mInfluenceRadius; + SerializedProperty mUseAllProbeBatches; + SerializedProperty mProbeBatches; + + bool mStatsFoldout = false; + bool mShouldShowProgressBar = false; + + private void OnEnable() + { + mInfluenceRadius = serializedObject.FindProperty("influenceRadius"); + mUseAllProbeBatches = serializedObject.FindProperty("useAllProbeBatches"); + mProbeBatches = serializedObject.FindProperty("probeBatches"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + var oldGUIEnabled = GUI.enabled; + GUI.enabled = !Baker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; + + var tgt = target as SteamAudioBakedSource; + + EditorGUILayout.PropertyField(mInfluenceRadius); + EditorGUILayout.PropertyField(mUseAllProbeBatches); + if (!mUseAllProbeBatches.boolValue) + { + EditorGUILayout.PropertyField(mProbeBatches); + } + + EditorGUILayout.Space(); + if (GUILayout.Button("Bake")) + { + tgt.BeginBake(); + mShouldShowProgressBar = true; + } + + GUI.enabled = oldGUIEnabled; + + if (mShouldShowProgressBar && !Baker.IsBakeActive()) + { + mShouldShowProgressBar = false; + } + + if (mShouldShowProgressBar) + { + Baker.DrawProgressBar(); + } + + Repaint(); + + EditorGUILayout.Space(); + mStatsFoldout = EditorGUILayout.Foldout(mStatsFoldout, "Baked Data Statistics"); + if (mStatsFoldout && !Baker.IsBakeActive()) + { + for (var i = 0; i < tgt.GetProbeBatchesUsed().Length; ++i) + { + EditorGUILayout.LabelField(tgt.GetProbeBatchesUsed()[i].gameObject.name, Common.HumanReadableDataSize(tgt.GetProbeDataSizes()[i])); + } + EditorGUILayout.LabelField("Total Size", Common.HumanReadableDataSize(tgt.GetTotalDataSize())); + } + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioBakedSourceInspector.cs.meta b/Scripts/Editor/SteamAudioBakedSourceInspector.cs.meta new file mode 100755 index 0000000..128c7e1 --- /dev/null +++ b/Scripts/Editor/SteamAudioBakedSourceInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3333927edc4e4ec4e880a1ff9e9a7a2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioDynamicObjectInspector.cs b/Scripts/Editor/SteamAudioDynamicObjectInspector.cs new file mode 100755 index 0000000..e9a3a7c --- /dev/null +++ b/Scripts/Editor/SteamAudioDynamicObjectInspector.cs @@ -0,0 +1,75 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEngine; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioDynamicObject))] + public class SteamAudioDynamicObjectInspector : Editor + { + #if STEAMAUDIO_ENABLED + SerializedProperty mAsset; + + private void OnEnable() + { + mAsset = serializedObject.FindProperty("asset"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(mAsset); + + if (mAsset.objectReferenceValue == null) + { + EditorGUILayout.HelpBox( + "This Dynamic Object has not been exported to an asset yet. Please click Export Dynamic Object " + + "to do so.", MessageType.Warning); + } + + EditorGUILayout.Space(); + + if (GUILayout.Button("Export Dynamic Object")) + { + if (mAsset.objectReferenceValue == null) + { + var name = (target as SteamAudioDynamicObject).gameObject.scene.name + "_" + target.name; + mAsset.objectReferenceValue = SerializedData.PromptForNewAsset(name); + serializedObject.ApplyModifiedProperties(); + } + + SteamAudioManager.ExportDynamicObject(target as SteamAudioDynamicObject, false); + } + + if (GUILayout.Button("Export Dynamic Object as OBJ")) + { + SteamAudioManager.ExportDynamicObject(target as SteamAudioDynamicObject, true); + } + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioDynamicObjectInspector.cs.meta b/Scripts/Editor/SteamAudioDynamicObjectInspector.cs.meta new file mode 100755 index 0000000..571d31f --- /dev/null +++ b/Scripts/Editor/SteamAudioDynamicObjectInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 980be31a5041c924094140b19f4276cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioGeometryInspector.cs b/Scripts/Editor/SteamAudioGeometryInspector.cs new file mode 100755 index 0000000..52e171b --- /dev/null +++ b/Scripts/Editor/SteamAudioGeometryInspector.cs @@ -0,0 +1,70 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioGeometry))] + [CanEditMultipleObjects] + public class SteamAudioGeometryInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mMaterial; + SerializedProperty mExportAllChildren; + SerializedProperty mTerrainSimplificationLevel; + + private void OnEnable() + { + mMaterial = serializedObject.FindProperty("material"); + mExportAllChildren = serializedObject.FindProperty("exportAllChildren"); + mTerrainSimplificationLevel = serializedObject.FindProperty("terrainSimplificationLevel"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + var tgt = target as SteamAudioGeometry; + + EditorGUILayout.PropertyField(mMaterial); + + if (tgt.transform.childCount != 0) + { + EditorGUILayout.PropertyField(mExportAllChildren); + } + + if (tgt.gameObject.GetComponent() != null) + { + EditorGUILayout.PropertyField(mTerrainSimplificationLevel); + } + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Geometry Statistics", EditorStyles.boldLabel); + EditorGUILayout.LabelField("Vertices", tgt.GetNumVertices().ToString()); + EditorGUILayout.LabelField("Triangles", tgt.GetNumTriangles().ToString()); + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioGeometryInspector.cs.meta b/Scripts/Editor/SteamAudioGeometryInspector.cs.meta new file mode 100755 index 0000000..b25c66c --- /dev/null +++ b/Scripts/Editor/SteamAudioGeometryInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58fcd8cc93a64734490ae21a46fb412d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioListenerInspector.cs b/Scripts/Editor/SteamAudioListenerInspector.cs new file mode 100755 index 0000000..e32ddf2 --- /dev/null +++ b/Scripts/Editor/SteamAudioListenerInspector.cs @@ -0,0 +1,108 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioListener))] + public class SteamAudioListenerInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mCurrentBakedListener; + SerializedProperty mApplyReverb; + SerializedProperty mReverbType; + SerializedProperty mUseAllProbeBatches; + SerializedProperty mProbeBatches; + + bool mStatsFoldout = false; + bool mShouldShowProgressBar = false; + + private void OnEnable() + { + mCurrentBakedListener = serializedObject.FindProperty("currentBakedListener"); + mApplyReverb = serializedObject.FindProperty("applyReverb"); + mReverbType = serializedObject.FindProperty("reverbType"); + mUseAllProbeBatches = serializedObject.FindProperty("useAllProbeBatches"); + mProbeBatches = serializedObject.FindProperty("probeBatches"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(mCurrentBakedListener); + + EditorGUILayout.PropertyField(mApplyReverb); + if (mApplyReverb.boolValue) + { + EditorGUILayout.PropertyField(mReverbType); + } + + var oldGUIEnabled = GUI.enabled; + GUI.enabled = !Baker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; + + var tgt = target as SteamAudioListener; + + EditorGUILayout.PropertyField(mUseAllProbeBatches); + if (!mUseAllProbeBatches.boolValue) + { + EditorGUILayout.PropertyField(mProbeBatches); + } + + EditorGUILayout.Space(); + if (GUILayout.Button("Bake")) + { + tgt.BeginBake(); + mShouldShowProgressBar = true; + } + + GUI.enabled = oldGUIEnabled; + + if (mShouldShowProgressBar && !Baker.IsBakeActive()) + { + mShouldShowProgressBar = false; + } + + if (mShouldShowProgressBar) + { + Baker.DrawProgressBar(); + } + + Repaint(); + + EditorGUILayout.Space(); + mStatsFoldout = EditorGUILayout.Foldout(mStatsFoldout, "Baked Data Statistics"); + if (mStatsFoldout && !Baker.IsBakeActive()) + { + for (var i = 0; i < tgt.GetProbeBatchesUsed().Length; ++i) + { + EditorGUILayout.LabelField(tgt.GetProbeBatchesUsed()[i].gameObject.name, Common.HumanReadableDataSize(tgt.GetProbeDataSizes()[i])); + } + EditorGUILayout.LabelField("Total Size", Common.HumanReadableDataSize(tgt.GetTotalDataSize())); + } + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioListenerInspector.cs.meta b/Scripts/Editor/SteamAudioListenerInspector.cs.meta new file mode 100755 index 0000000..a6dbbfd --- /dev/null +++ b/Scripts/Editor/SteamAudioListenerInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 68c66682e05a3a744896f1452c21c860 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioManagerInspector.cs b/Scripts/Editor/SteamAudioManagerInspector.cs new file mode 100755 index 0000000..7263f12 --- /dev/null +++ b/Scripts/Editor/SteamAudioManagerInspector.cs @@ -0,0 +1,57 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioManager))] + [CanEditMultipleObjects] + public class SteamAudioManagerInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mCurrentHRTF; + + private void OnEnable() + { + mCurrentHRTF = serializedObject.FindProperty("currentHRTF"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + var tgt = target as SteamAudioManager; + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("HRTF Settings", EditorStyles.boldLabel); + mCurrentHRTF.intValue = EditorGUILayout.Popup("Current HRTF", mCurrentHRTF.intValue, tgt.hrtfNames); + + EditorGUILayout.Space(); + EditorGUILayout.HelpBox( + "This component should not be added manually to any GameObject. It is automatically created and" + + "destroyed by Steam Audio.", MessageType.Warning); + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioManagerInspector.cs.meta b/Scripts/Editor/SteamAudioManagerInspector.cs.meta new file mode 100755 index 0000000..37b6184 --- /dev/null +++ b/Scripts/Editor/SteamAudioManagerInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e5adb5adac336b84fa2308b30315459d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioMaterialInspector.cs b/Scripts/Editor/SteamAudioMaterialInspector.cs new file mode 100755 index 0000000..741d438 --- /dev/null +++ b/Scripts/Editor/SteamAudioMaterialInspector.cs @@ -0,0 +1,59 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioMaterial))] + [CanEditMultipleObjects] + public class SteamAudioMaterialInspector : Editor + { + SerializedProperty lowFreqAbsorption; + SerializedProperty midFreqAbsorption; + SerializedProperty highFreqAbsorption; + SerializedProperty scattering; + SerializedProperty lowFreqTransmission; + SerializedProperty midFreqTransmission; + SerializedProperty highFreqTransmission; + + private void OnEnable() + { + lowFreqAbsorption = serializedObject.FindProperty("lowFreqAbsorption"); + midFreqAbsorption = serializedObject.FindProperty("midFreqAbsorption"); + highFreqAbsorption = serializedObject.FindProperty("highFreqAbsorption"); + scattering = serializedObject.FindProperty("scattering"); + lowFreqTransmission = serializedObject.FindProperty("lowFreqTransmission"); + midFreqTransmission = serializedObject.FindProperty("midFreqTransmission"); + highFreqTransmission = serializedObject.FindProperty("highFreqTransmission"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(lowFreqAbsorption); + EditorGUILayout.PropertyField(midFreqAbsorption); + EditorGUILayout.PropertyField(highFreqAbsorption); + EditorGUILayout.PropertyField(scattering); + EditorGUILayout.PropertyField(lowFreqTransmission); + EditorGUILayout.PropertyField(midFreqTransmission); + EditorGUILayout.PropertyField(highFreqTransmission); + + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/Scripts/Editor/SteamAudioMaterialInspector.cs.meta b/Scripts/Editor/SteamAudioMaterialInspector.cs.meta new file mode 100755 index 0000000..e0fed57 --- /dev/null +++ b/Scripts/Editor/SteamAudioMaterialInspector.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d390cf1bb6f67ca47b6b5d3c43ec5956 +timeCreated: 1499375927 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioMixerReturnGUI.cs b/Scripts/Editor/SteamAudioMixerReturnGUI.cs new file mode 100755 index 0000000..a1e7b81 --- /dev/null +++ b/Scripts/Editor/SteamAudioMixerReturnGUI.cs @@ -0,0 +1,74 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + public class SteamAudioMixerReturnGUI : IAudioEffectPluginGUI + { + public override string Name + { + get + { + return "Steam Audio Mixer Return"; + } + } + + public override string Vendor + { + get + { + return "Valve Corporation"; + } + } + + public override string Description + { + get + { + return "Enables accelerated mixing of reflections for sources spatialized using Steam Audio."; + } + } + + public override bool OnGUI(IAudioEffectPlugin plugin) + { + if (SteamAudioSettings.Singleton.audioEngine != AudioEngineType.Unity) + { + EditorGUILayout.HelpBox( + "This Audio Mixer effect requires the audio engine to be set to Unity. Click" + + "Steam Audio > Settings to change this.", MessageType.Warning); + + return false; + } + + var binauralValue = 0.0f; + + plugin.GetFloatParameter("Binaural", out binauralValue); + + var binaural = (binauralValue == 1.0f); + + binaural = EditorGUILayout.Toggle("Apply HRTF", binaural); + + binauralValue = (binaural) ? 1.0f : 0.0f; + + plugin.SetFloatParameter("Binaural", binauralValue); + + return false; + } + } +} diff --git a/Scripts/Editor/SteamAudioMixerReturnGUI.cs.meta b/Scripts/Editor/SteamAudioMixerReturnGUI.cs.meta new file mode 100755 index 0000000..7b6880b --- /dev/null +++ b/Scripts/Editor/SteamAudioMixerReturnGUI.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 03cab73d8173c364bb30b17574e2f240 +timeCreated: 1499881264 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioProbeBatchInspector.cs b/Scripts/Editor/SteamAudioProbeBatchInspector.cs new file mode 100755 index 0000000..06b0e7d --- /dev/null +++ b/Scripts/Editor/SteamAudioProbeBatchInspector.cs @@ -0,0 +1,143 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEngine.SceneManagement; +using UnityEditor; +using UnityEditor.SceneManagement; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioProbeBatch))] + public class SteamAudioProbeBatchInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mPlacementStrategy; + SerializedProperty mHorizontalSpacing; + SerializedProperty mHeightAboveFloor; + SerializedProperty mAsset; + + bool mShouldShowProgressBar = false; + + private void OnEnable() + { + mPlacementStrategy = serializedObject.FindProperty("placementStrategy"); + mHorizontalSpacing = serializedObject.FindProperty("horizontalSpacing"); + mHeightAboveFloor = serializedObject.FindProperty("heightAboveFloor"); + mAsset = serializedObject.FindProperty("asset"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + var oldGUIEnabled = GUI.enabled; + GUI.enabled = !Baker.IsBakeActive() && !EditorApplication.isPlayingOrWillChangePlaymode; + + var tgt = target as SteamAudioProbeBatch; + + EditorGUILayout.PropertyField(mAsset); + + EditorGUILayout.PropertyField(mPlacementStrategy); + if ((ProbeGenerationType) mPlacementStrategy.enumValueIndex == ProbeGenerationType.UniformFloor) + { + EditorGUILayout.PropertyField(mHorizontalSpacing); + EditorGUILayout.PropertyField(mHeightAboveFloor); + } + + EditorGUILayout.Space(); + if (GUILayout.Button("Generate Probes")) + { + tgt.GenerateProbes(); + EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); + } + + if (tgt.GetNumProbes() > 0) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Baked Pathing Settings", EditorStyles.boldLabel); + if (GUILayout.Button("Bake")) + { + tgt.BeginBake(); + mShouldShowProgressBar = true; + } + } + + GUI.enabled = oldGUIEnabled; + + if (mShouldShowProgressBar && !Baker.IsBakeActive()) + { + mShouldShowProgressBar = false; + } + + if (mShouldShowProgressBar) + { + Baker.DrawProgressBar(); + } + + Repaint(); + + if (tgt.GetNumProbes() > 0) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Probe Statistics", EditorStyles.boldLabel); + EditorGUILayout.LabelField("Probes", tgt.GetNumProbes().ToString()); + EditorGUILayout.LabelField("Data Size", Common.HumanReadableDataSize(tgt.probeDataSize)); + + if (tgt.GetNumLayers() > 0) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Detailed Statistics", EditorStyles.boldLabel); + for (var i = 0; i < tgt.GetNumLayers(); ++i) + { + var layerInfo = tgt.GetInfoForLayer(i); + + var name = ""; + if (layerInfo.identifier.type == BakedDataType.Pathing) + { + name = "Pathing"; + } + else if (layerInfo.identifier.variation == BakedDataVariation.Reverb) + { + name = "Reverb"; + } + else + { + name = layerInfo.gameObject.name; + } + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField(name, Common.HumanReadableDataSize(layerInfo.dataSize)); + if (GUILayout.Button("Clear")) + { + tgt.DeleteBakedDataForIdentifier(layerInfo.identifier); + EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); + } + EditorGUILayout.EndHorizontal(); + } + } + } + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioProbeBatchInspector.cs.meta b/Scripts/Editor/SteamAudioProbeBatchInspector.cs.meta new file mode 100755 index 0000000..cae7e8a --- /dev/null +++ b/Scripts/Editor/SteamAudioProbeBatchInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: db54b1d0b8cefcf4486eccd5e7c185f7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioReverbGUI.cs b/Scripts/Editor/SteamAudioReverbGUI.cs new file mode 100755 index 0000000..06a358f --- /dev/null +++ b/Scripts/Editor/SteamAudioReverbGUI.cs @@ -0,0 +1,74 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + public class SteamAudioReverbGUI : IAudioEffectPluginGUI + { + public override string Name + { + get + { + return "Steam Audio Reverb"; + } + } + + public override string Vendor + { + get + { + return "Valve Corporation"; + } + } + + public override string Description + { + get + { + return "Listener-centric reverb using Steam Audio."; + } + } + + public override bool OnGUI(IAudioEffectPlugin plugin) + { + if (SteamAudioSettings.Singleton.audioEngine != AudioEngineType.Unity) + { + EditorGUILayout.HelpBox( + "This Audio Mixer effect requires the audio engine to be set to Unity. Click" + + "Steam Audio > Settings to change this.", MessageType.Warning); + + return false; + } + + var binauralValue = 0.0f; + + plugin.GetFloatParameter("Binaural", out binauralValue); + + var binaural = (binauralValue == 1.0f); + + binaural = EditorGUILayout.Toggle("Apply HRTF", binaural); + + binauralValue = (binaural) ? 1.0f : 0.0f; + + plugin.SetFloatParameter("Binaural", binauralValue); + + return false; + } + } +} diff --git a/Scripts/Editor/SteamAudioReverbGUI.cs.meta b/Scripts/Editor/SteamAudioReverbGUI.cs.meta new file mode 100755 index 0000000..efbdeb3 --- /dev/null +++ b/Scripts/Editor/SteamAudioReverbGUI.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6f194df3638411045b8624f4e62e44fd +timeCreated: 1499886452 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioSettingsInspector.cs b/Scripts/Editor/SteamAudioSettingsInspector.cs new file mode 100755 index 0000000..bbd176c --- /dev/null +++ b/Scripts/Editor/SteamAudioSettingsInspector.cs @@ -0,0 +1,233 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioSettings))] + [CanEditMultipleObjects] + public class SteamAudioSettingsInspector : Editor + { + SerializedProperty mAudioEngine; + SerializedProperty mPerspectiveCorrection; + SerializedProperty mPerspectiveCorrectionFactor; + SerializedProperty mHRTFVolumeNormalizationType; + SerializedProperty mHRTFVolumeGainDB; + SerializedProperty mSOFAFiles; + SerializedProperty mDefaultMaterial; + SerializedProperty mSceneType; + SerializedProperty mLayerMask; + SerializedProperty mMaxOcclusionSamples; + SerializedProperty mRealTimeRays; + SerializedProperty mRealTimeBounces; + SerializedProperty mRealTimeDuration; + SerializedProperty mRealTimeAmbisonicOrder; + SerializedProperty mRealTimeMaxSources; + SerializedProperty mRealTimeCPUCoresPercentage; + SerializedProperty mRealTimeIrradianceMinDistance; + SerializedProperty mBakeConvolution; + SerializedProperty mBakeParametric; + SerializedProperty mBakingRays; + SerializedProperty mBakingBounces; + SerializedProperty mBakingDuration; + SerializedProperty mBakingAmbisonicOrder; + SerializedProperty mBakingCPUCoresPercentage; + SerializedProperty mBakingIrradianceMinDistance; + SerializedProperty mBakingVisibilitySamples; + SerializedProperty mBakingVisibilityRadius; + SerializedProperty mBakingVisibilityThreshold; + SerializedProperty mBakingVisibilityRange; + SerializedProperty mBakingPathRange; + SerializedProperty mBakedPathingCPUCoresPercentage; + SerializedProperty mSimulationUpdateInterval; + SerializedProperty mReflectionEffectType; + SerializedProperty mHybridReverbTransitionTime; + SerializedProperty mHybridReverbOverlapPercent; + SerializedProperty mDeviceType; + SerializedProperty mMaxReservedCUs; + SerializedProperty mFractionCUsForIRUpdate; + SerializedProperty mBakingBatchSize; + SerializedProperty mTANDuration; + SerializedProperty mTANAmbisonicOrder; + SerializedProperty mTANMaxSources; + SerializedProperty mEnableValidation; + +#if !UNITY_2019_2_OR_NEWER + static string[] sSceneTypes = new string[] { "Phonon", "Embree", "Radeon Rays", "Unity" }; +#endif + +#if !UNITY_2019_2_OR_NEWER + static string[] sReflectionEffectTypes = new string[] { "Convolution", "Parametric", "Hybrid", "TrueAudio Next" }; +#endif + + private void OnEnable() + { + mAudioEngine = serializedObject.FindProperty("audioEngine"); + mPerspectiveCorrection = serializedObject.FindProperty("perspectiveCorrection"); + mPerspectiveCorrectionFactor = serializedObject.FindProperty("perspectiveCorrectionFactor"); + mHRTFVolumeGainDB = serializedObject.FindProperty("hrtfVolumeGainDB"); + mHRTFVolumeNormalizationType = serializedObject.FindProperty("hrtfNormalizationType"); + mSOFAFiles = serializedObject.FindProperty("SOFAFiles"); + mDefaultMaterial = serializedObject.FindProperty("defaultMaterial"); + mSceneType = serializedObject.FindProperty("sceneType"); + mLayerMask = serializedObject.FindProperty("layerMask"); + mMaxOcclusionSamples = serializedObject.FindProperty("maxOcclusionSamples"); + mRealTimeRays = serializedObject.FindProperty("realTimeRays"); + mRealTimeBounces = serializedObject.FindProperty("realTimeBounces"); + mRealTimeDuration = serializedObject.FindProperty("realTimeDuration"); + mRealTimeAmbisonicOrder = serializedObject.FindProperty("realTimeAmbisonicOrder"); + mRealTimeMaxSources = serializedObject.FindProperty("realTimeMaxSources"); + mRealTimeCPUCoresPercentage = serializedObject.FindProperty("realTimeCPUCoresPercentage"); + mRealTimeIrradianceMinDistance = serializedObject.FindProperty("realTimeIrradianceMinDistance"); + mBakeConvolution = serializedObject.FindProperty("bakeConvolution"); + mBakeParametric = serializedObject.FindProperty("bakeParametric"); + mBakingRays = serializedObject.FindProperty("bakingRays"); + mBakingBounces = serializedObject.FindProperty("bakingBounces"); + mBakingDuration = serializedObject.FindProperty("bakingDuration"); + mBakingAmbisonicOrder = serializedObject.FindProperty("bakingAmbisonicOrder"); + mBakingCPUCoresPercentage = serializedObject.FindProperty("bakingCPUCoresPercentage"); + mBakingIrradianceMinDistance = serializedObject.FindProperty("bakingIrradianceMinDistance"); + mBakingVisibilitySamples = serializedObject.FindProperty("bakingVisibilitySamples"); + mBakingVisibilityRadius = serializedObject.FindProperty("bakingVisibilityRadius"); + mBakingVisibilityThreshold = serializedObject.FindProperty("bakingVisibilityThreshold"); + mBakingVisibilityRange = serializedObject.FindProperty("bakingVisibilityRange"); + mBakingPathRange = serializedObject.FindProperty("bakingPathRange"); + mBakedPathingCPUCoresPercentage = serializedObject.FindProperty("bakedPathingCPUCoresPercentage"); + mSimulationUpdateInterval = serializedObject.FindProperty("simulationUpdateInterval"); + mReflectionEffectType = serializedObject.FindProperty("reflectionEffectType"); + mHybridReverbTransitionTime = serializedObject.FindProperty("hybridReverbTransitionTime"); + mHybridReverbOverlapPercent = serializedObject.FindProperty("hybridReverbOverlapPercent"); + mDeviceType = serializedObject.FindProperty("deviceType"); + mMaxReservedCUs = serializedObject.FindProperty("maxReservedComputeUnits"); + mFractionCUsForIRUpdate = serializedObject.FindProperty("fractionComputeUnitsForIRUpdate"); + mBakingBatchSize = serializedObject.FindProperty("bakingBatchSize"); + mTANDuration = serializedObject.FindProperty("TANDuration"); + mTANAmbisonicOrder = serializedObject.FindProperty("TANAmbisonicOrder"); + mTANMaxSources = serializedObject.FindProperty("TANMaxSources"); + mEnableValidation = serializedObject.FindProperty("EnableValidation"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(mAudioEngine); + EditorGUILayout.PropertyField(mPerspectiveCorrection, new UnityEngine.GUIContent("Enable Perspective Correction")); + + if (mPerspectiveCorrection.boolValue) + EditorGUILayout.PropertyField(mPerspectiveCorrectionFactor); + + EditorGUILayout.PropertyField(mHRTFVolumeGainDB, new UnityEngine.GUIContent("HRTF Volume Gain (dB)")); + EditorGUILayout.PropertyField(mHRTFVolumeNormalizationType, new UnityEngine.GUIContent("HRTF Normalization Type")); + + EditorGUILayout.PropertyField(mSOFAFiles, true); + EditorGUILayout.PropertyField(mDefaultMaterial); +#if UNITY_2019_2_OR_NEWER + EditorGUILayout.PropertyField(mSceneType); +#else + SceneTypeField(); +#endif + + if (((SceneType) mSceneType.enumValueIndex) == SceneType.Custom) + { + EditorGUILayout.PropertyField(mLayerMask); + } + + EditorGUILayout.PropertyField(mMaxOcclusionSamples); + + EditorGUILayout.PropertyField(mRealTimeRays); + EditorGUILayout.PropertyField(mRealTimeBounces); + EditorGUILayout.PropertyField(mRealTimeDuration); + EditorGUILayout.PropertyField(mRealTimeAmbisonicOrder); + EditorGUILayout.PropertyField(mRealTimeMaxSources); + EditorGUILayout.PropertyField(mRealTimeCPUCoresPercentage); + EditorGUILayout.PropertyField(mRealTimeIrradianceMinDistance); + + EditorGUILayout.PropertyField(mBakeConvolution); + EditorGUILayout.PropertyField(mBakeParametric); + EditorGUILayout.PropertyField(mBakingRays); + EditorGUILayout.PropertyField(mBakingBounces); + EditorGUILayout.PropertyField(mBakingDuration); + EditorGUILayout.PropertyField(mBakingAmbisonicOrder); + EditorGUILayout.PropertyField(mBakingCPUCoresPercentage); + EditorGUILayout.PropertyField(mBakingIrradianceMinDistance); + + EditorGUILayout.PropertyField(mBakingVisibilitySamples); + EditorGUILayout.PropertyField(mBakingVisibilityRadius); + EditorGUILayout.PropertyField(mBakingVisibilityThreshold); + EditorGUILayout.PropertyField(mBakingVisibilityRange); + EditorGUILayout.PropertyField(mBakingPathRange); + EditorGUILayout.PropertyField(mBakedPathingCPUCoresPercentage); + + EditorGUILayout.PropertyField(mSimulationUpdateInterval); + +#if UNITY_2019_2_OR_NEWER + EditorGUILayout.PropertyField(mReflectionEffectType); +#else + ReflectionEffectTypeField(); +#endif + + if (((ReflectionEffectType) mReflectionEffectType.enumValueIndex) == ReflectionEffectType.Hybrid) + { + EditorGUILayout.PropertyField(mHybridReverbTransitionTime); + EditorGUILayout.PropertyField(mHybridReverbOverlapPercent); + } + + if (((SceneType) mSceneType.enumValueIndex) == SceneType.RadeonRays || + ((ReflectionEffectType) mReflectionEffectType.enumValueIndex) == ReflectionEffectType.TrueAudioNext) + { + EditorGUILayout.PropertyField(mDeviceType); + EditorGUILayout.PropertyField(mMaxReservedCUs); + EditorGUILayout.PropertyField(mFractionCUsForIRUpdate); + + if (((SceneType) mSceneType.enumValueIndex) == SceneType.RadeonRays) + { + EditorGUILayout.PropertyField(mBakingBatchSize); + } + + if (((ReflectionEffectType) mReflectionEffectType.enumValueIndex) == ReflectionEffectType.TrueAudioNext) + { + EditorGUILayout.PropertyField(mTANDuration); + EditorGUILayout.PropertyField(mTANAmbisonicOrder); + EditorGUILayout.PropertyField(mTANMaxSources); + } + } + + EditorGUILayout.PropertyField(mEnableValidation); + + serializedObject.ApplyModifiedProperties(); + } + +#if !UNITY_2019_2_OR_NEWER + void SceneTypeField() + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Ray Tracer Settings", EditorStyles.boldLabel); + mSceneType.enumValueIndex = EditorGUILayout.Popup(mSceneType.displayName, mSceneType.enumValueIndex, sSceneTypes); + } +#endif + +#if !UNITY_2019_2_OR_NEWER + void ReflectionEffectTypeField() + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Reflection Effect Settings", EditorStyles.boldLabel); + mReflectionEffectType.enumValueIndex = EditorGUILayout.Popup(mReflectionEffectType.displayName, mReflectionEffectType.enumValueIndex, sReflectionEffectTypes); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioSettingsInspector.cs.meta b/Scripts/Editor/SteamAudioSettingsInspector.cs.meta new file mode 100755 index 0000000..d24e3f5 --- /dev/null +++ b/Scripts/Editor/SteamAudioSettingsInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4874c09ead1502c4b966e1bb4e7ad3da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioSourceInspector.cs b/Scripts/Editor/SteamAudioSourceInspector.cs new file mode 100755 index 0000000..687153b --- /dev/null +++ b/Scripts/Editor/SteamAudioSourceInspector.cs @@ -0,0 +1,346 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioSource))] + public class SteamAudioSourceInspector : Editor + { + SerializedProperty mDirectBinaural; + SerializedProperty mInterpolation; + SerializedProperty mPerspectiveCorrection; + SerializedProperty mDistanceAttenuation; + SerializedProperty mDistanceAttenuationInput; + SerializedProperty mAirAbsorption; + SerializedProperty mAirAbsorptionInput; + SerializedProperty mAirAbsorptionLow; + SerializedProperty mAirAbsorptionMid; + SerializedProperty mAirAbsorptionHigh; + SerializedProperty mDirectivity; + SerializedProperty mDirectivityInput; + SerializedProperty mDipoleWeight; + SerializedProperty mDipolePower; + SerializedProperty mDirectivityValue; + SerializedProperty mOcclusion; + SerializedProperty mOcclusionInput; + SerializedProperty mOcclusionType; + SerializedProperty mOcclusionRadius; + SerializedProperty mOcclusionSamples; + SerializedProperty mOcclusionValue; + SerializedProperty mTransmission; + SerializedProperty mTransmissionType; + SerializedProperty mTransmissionInput; + SerializedProperty mTransmissionLow; + SerializedProperty mTransmissionMid; + SerializedProperty mTransmissionHigh; + SerializedProperty mTransmissionRays; + SerializedProperty mDirectMixLevel; + SerializedProperty mReflections; + SerializedProperty mReflectionsType; + SerializedProperty mUseDistanceCurveForReflections; + SerializedProperty mCurrentBakedSource; + SerializedProperty mApplyHRTFToReflections; + SerializedProperty mReflectionsMixLevel; + SerializedProperty mPathing; + SerializedProperty mPathingProbeBatch; + SerializedProperty mPathValidation; + SerializedProperty mFindAlternatePaths; + SerializedProperty mApplyHRTFToPathing; + SerializedProperty mPathingMixLevel; + + Texture2D mDirectivityPreview = null; + float[] mDirectivitySamples = null; + Vector2[] mDirectivityPositions = null; + + private void OnEnable() + { + mDirectBinaural = serializedObject.FindProperty("directBinaural"); + mInterpolation = serializedObject.FindProperty("interpolation"); + mPerspectiveCorrection = serializedObject.FindProperty("perspectiveCorrection"); + mDistanceAttenuation = serializedObject.FindProperty("distanceAttenuation"); + mDistanceAttenuationInput = serializedObject.FindProperty("distanceAttenuationInput"); + mAirAbsorption = serializedObject.FindProperty("airAbsorption"); + mAirAbsorptionInput = serializedObject.FindProperty("airAbsorptionInput"); + mAirAbsorptionLow = serializedObject.FindProperty("airAbsorptionLow"); + mAirAbsorptionMid = serializedObject.FindProperty("airAbsorptionMid"); + mAirAbsorptionHigh = serializedObject.FindProperty("airAbsorptionHigh"); + mDirectivity = serializedObject.FindProperty("directivity"); + mDirectivityInput = serializedObject.FindProperty("directivityInput"); + mDipoleWeight = serializedObject.FindProperty("dipoleWeight"); + mDipolePower = serializedObject.FindProperty("dipolePower"); + mDirectivityValue = serializedObject.FindProperty("directivityValue"); + mOcclusion = serializedObject.FindProperty("occlusion"); + mOcclusionInput = serializedObject.FindProperty("occlusionInput"); + mOcclusionType = serializedObject.FindProperty("occlusionType"); + mOcclusionRadius = serializedObject.FindProperty("occlusionRadius"); + mOcclusionSamples = serializedObject.FindProperty("occlusionSamples"); + mOcclusionValue = serializedObject.FindProperty("occlusionValue"); + mTransmission = serializedObject.FindProperty("transmission"); + mTransmissionType = serializedObject.FindProperty("transmissionType"); + mTransmissionInput = serializedObject.FindProperty("transmissionInput"); + mTransmissionLow = serializedObject.FindProperty("transmissionLow"); + mTransmissionMid = serializedObject.FindProperty("transmissionMid"); + mTransmissionHigh = serializedObject.FindProperty("transmissionHigh"); + mTransmissionRays = serializedObject.FindProperty("maxTransmissionSurfaces"); + mDirectMixLevel = serializedObject.FindProperty("directMixLevel"); + mReflections = serializedObject.FindProperty("reflections"); + mReflectionsType = serializedObject.FindProperty("reflectionsType"); + mUseDistanceCurveForReflections = serializedObject.FindProperty("useDistanceCurveForReflections"); + mCurrentBakedSource = serializedObject.FindProperty("currentBakedSource"); + mApplyHRTFToReflections = serializedObject.FindProperty("applyHRTFToReflections"); + mReflectionsMixLevel = serializedObject.FindProperty("reflectionsMixLevel"); + mPathing = serializedObject.FindProperty("pathing"); + mPathingProbeBatch = serializedObject.FindProperty("pathingProbeBatch"); + mPathValidation = serializedObject.FindProperty("pathValidation"); + mFindAlternatePaths = serializedObject.FindProperty("findAlternatePaths"); + mApplyHRTFToPathing = serializedObject.FindProperty("applyHRTFToPathing"); + mPathingMixLevel = serializedObject.FindProperty("pathingMixLevel"); + } + + public override void OnInspectorGUI() + { + var audioEngineIsUnity = (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity); + + serializedObject.Update(); + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mDirectBinaural); + EditorGUILayout.PropertyField(mInterpolation); + } + + if (audioEngineIsUnity && SteamAudioSettings.Singleton.perspectiveCorrection) + { + EditorGUILayout.PropertyField(mPerspectiveCorrection); + } + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mDistanceAttenuation); + if (mDistanceAttenuation.boolValue) + { + EditorGUILayout.PropertyField(mDistanceAttenuationInput); + } + } + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mAirAbsorption); + if (mAirAbsorption.boolValue) + { + EditorGUILayout.PropertyField(mAirAbsorptionInput); + if ((AirAbsorptionInput)mAirAbsorptionInput.enumValueIndex == AirAbsorptionInput.UserDefined) + { + EditorGUILayout.PropertyField(mAirAbsorptionLow); + EditorGUILayout.PropertyField(mAirAbsorptionMid); + EditorGUILayout.PropertyField(mAirAbsorptionHigh); + } + } + } + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mDirectivity); + if (mDirectivity.boolValue) + { + EditorGUILayout.PropertyField(mDirectivityInput); + + if ((DirectivityInput) mDirectivityInput.enumValueIndex == DirectivityInput.SimulationDefined) + { + EditorGUILayout.PropertyField(mDipoleWeight); + EditorGUILayout.PropertyField(mDipolePower); + DrawDirectivity(mDipoleWeight.floatValue, mDipolePower.floatValue); + } + else if ((DirectivityInput) mDirectivityInput.enumValueIndex == DirectivityInput.UserDefined) + { + EditorGUILayout.PropertyField(mDirectivityValue); + } + } + } + + EditorGUILayout.PropertyField(mOcclusion); + if (mOcclusion.boolValue) + { + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mOcclusionInput); + } + + if (!audioEngineIsUnity || + (OcclusionInput) mOcclusionInput.enumValueIndex == OcclusionInput.SimulationDefined) + { + EditorGUILayout.PropertyField(mOcclusionType); + if ((OcclusionType) mOcclusionType.enumValueIndex == OcclusionType.Volumetric) + { + EditorGUILayout.PropertyField(mOcclusionRadius); + EditorGUILayout.PropertyField(mOcclusionSamples); + } + } + else if ((OcclusionInput) mOcclusionInput.enumValueIndex == OcclusionInput.UserDefined) + { + EditorGUILayout.PropertyField(mOcclusionValue); + } + + EditorGUILayout.PropertyField(mTransmission); + if (audioEngineIsUnity) + { + if (mTransmission.boolValue) + { + EditorGUILayout.PropertyField(mTransmissionType); + EditorGUILayout.PropertyField(mTransmissionInput); + if ((TransmissionInput)mTransmissionInput.enumValueIndex == TransmissionInput.UserDefined) + { + if (mTransmissionType.enumValueIndex == (int)TransmissionType.FrequencyDependent) + { + EditorGUILayout.PropertyField(mTransmissionLow); + EditorGUILayout.PropertyField(mTransmissionMid); + EditorGUILayout.PropertyField(mTransmissionHigh); + } + else + { + EditorGUILayout.PropertyField(mTransmissionMid); + } + } + else if ((TransmissionInput) mTransmissionInput.enumValueIndex == TransmissionInput.SimulationDefined) + { + EditorGUILayout.PropertyField(mTransmissionRays); + } + } + } + } + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mDirectMixLevel); + } + + EditorGUILayout.PropertyField(mReflections); + if (mReflections.boolValue) + { + EditorGUILayout.PropertyField(mReflectionsType); + + if (audioEngineIsUnity && + mDistanceAttenuation.boolValue && + (DistanceAttenuationInput) mDistanceAttenuationInput.enumValueIndex == DistanceAttenuationInput.CurveDriven) + { + EditorGUILayout.PropertyField(mUseDistanceCurveForReflections); + } + + if ((ReflectionsType) mReflectionsType.enumValueIndex == ReflectionsType.BakedStaticSource) + { + EditorGUILayout.PropertyField(mCurrentBakedSource); + } + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mApplyHRTFToReflections); + EditorGUILayout.PropertyField(mReflectionsMixLevel); + } + } + + EditorGUILayout.PropertyField(mPathing); + if (mPathing.boolValue) + { + EditorGUILayout.PropertyField(mPathingProbeBatch); + EditorGUILayout.PropertyField(mPathValidation); + EditorGUILayout.PropertyField(mFindAlternatePaths); + + if (audioEngineIsUnity) + { + EditorGUILayout.PropertyField(mApplyHRTFToPathing); + EditorGUILayout.PropertyField(mPathingMixLevel); + } + } + + serializedObject.ApplyModifiedProperties(); + } + + void DrawDirectivity(float dipoleWeight, float dipolePower) + { + if (mDirectivityPreview == null) + { + mDirectivityPreview = new Texture2D(65, 65); + } + + if (mDirectivitySamples == null) + { + mDirectivitySamples = new float[360]; + mDirectivityPositions = new Vector2[360]; + } + + for (var i = 0; i < mDirectivitySamples.Length; ++i) + { + var theta = (i / 360.0f) * (2.0f * Mathf.PI); + mDirectivitySamples[i] = Mathf.Pow(Mathf.Abs((1.0f - dipoleWeight) + dipoleWeight * Mathf.Cos(theta)), dipolePower); + + var r = 31 * Mathf.Abs(mDirectivitySamples[i]); + var x = r * Mathf.Cos(theta) + 32; + var y = r * Mathf.Sin(theta) + 32; + mDirectivityPositions[i] = new Vector2(-y, x); + } + + for (var v = 0; v < mDirectivityPreview.height; ++v) + { + for (var u = 0; u < mDirectivityPreview.width; ++u) + { + mDirectivityPreview.SetPixel(u, v, Color.gray); + } + } + + for (var u = 0; u < mDirectivityPreview.width; ++u) + { + mDirectivityPreview.SetPixel(u, 32, Color.black); + } + + for (var v = 0; v < mDirectivityPreview.height; ++v) + { + mDirectivityPreview.SetPixel(32, v, Color.black); + } + + for (var i = 0; i < mDirectivitySamples.Length; ++i) + { + var color = (mDirectivitySamples[i] > 0.0f) ? Color.red : Color.blue; + mDirectivityPreview.SetPixel((int) mDirectivityPositions[i].x, (int) mDirectivityPositions[i].y, color); + } + + mDirectivityPreview.Apply(); + + EditorGUILayout.PrefixLabel("Preview"); + EditorGUILayout.Space(); + var rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()); + var center = rect.center; + center.x += 4; + rect.center = center; + rect.width = 65; + rect.height = 65; + + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + EditorGUILayout.Space(); + + EditorGUI.DrawPreviewTexture(rect, mDirectivityPreview); + } + } +} diff --git a/Scripts/Editor/SteamAudioSourceInspector.cs.meta b/Scripts/Editor/SteamAudioSourceInspector.cs.meta new file mode 100755 index 0000000..07ccf9c --- /dev/null +++ b/Scripts/Editor/SteamAudioSourceInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0a0b6df87f513414b805186eba677e7e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioStaticMeshInspector.cs b/Scripts/Editor/SteamAudioStaticMeshInspector.cs new file mode 100755 index 0000000..e337003 --- /dev/null +++ b/Scripts/Editor/SteamAudioStaticMeshInspector.cs @@ -0,0 +1,75 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +using UnityEditor; + +namespace SteamAudio +{ + [CustomEditor(typeof(SteamAudioStaticMesh))] + public class SteamAudioStaticMeshInspector : Editor + { +#if STEAMAUDIO_ENABLED + SerializedProperty mAsset; + SerializedProperty mSceneNameWhenExported; + + void OnEnable() + { + mAsset = serializedObject.FindProperty("asset"); + mSceneNameWhenExported = serializedObject.FindProperty("sceneNameWhenExported"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(mAsset); + + var scene = (target as SteamAudioStaticMesh).gameObject.scene; + + if (mAsset.objectReferenceValue == null) + { + EditorGUILayout.HelpBox( + "This scene has not been exported. Click Steam Audio > Export Active Scene to export.", + MessageType.Warning); + } + else if (mSceneNameWhenExported.stringValue != scene.name) + { + EditorGUILayout.HelpBox( + string.Format("This geometry was last exported for the scene {0}. If this is not what you " + + "intended, click Export As New Asset below.", mSceneNameWhenExported.stringValue), + MessageType.Warning); + + if (GUILayout.Button("Export As New Asset")) + { + mAsset.objectReferenceValue = SerializedData.PromptForNewAsset(scene.name); + mSceneNameWhenExported.stringValue = scene.name; + serializedObject.ApplyModifiedProperties(); + + SteamAudioManager.ExportScene(scene, false); + } + } + + serializedObject.ApplyModifiedProperties(); + } +#else + public override void OnInspectorGUI() + { + EditorGUILayout.HelpBox("Steam Audio is not supported for the target platform or STEAMAUDIO_ENABLED define symbol is missing.", MessageType.Warning); + } +#endif + } +} diff --git a/Scripts/Editor/SteamAudioStaticMeshInspector.cs.meta b/Scripts/Editor/SteamAudioStaticMeshInspector.cs.meta new file mode 100755 index 0000000..396d38b --- /dev/null +++ b/Scripts/Editor/SteamAudioStaticMeshInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d6929999ad3f3e54196cfa59c3181b95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/SteamAudioUnityEditor.asmdef b/Scripts/Editor/SteamAudioUnityEditor.asmdef new file mode 100755 index 0000000..511d057 --- /dev/null +++ b/Scripts/Editor/SteamAudioUnityEditor.asmdef @@ -0,0 +1,17 @@ +{ + "name": "SteamAudioUnityEditor", + "references": [ + "SteamAudioUnity" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Scripts/Editor/SteamAudioUnityEditor.asmdef.meta b/Scripts/Editor/SteamAudioUnityEditor.asmdef.meta new file mode 100755 index 0000000..9250e3c --- /dev/null +++ b/Scripts/Editor/SteamAudioUnityEditor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 32059f5c68d213f49892e59f10b1a065 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime.meta b/Scripts/Runtime.meta new file mode 100755 index 0000000..8fd9e69 --- /dev/null +++ b/Scripts/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 07db90b46cddd3245b0baf1c24d8548e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/AudioEngineAmbisonicSource.cs b/Scripts/Runtime/AudioEngineAmbisonicSource.cs new file mode 100755 index 0000000..6f69edf --- /dev/null +++ b/Scripts/Runtime/AudioEngineAmbisonicSource.cs @@ -0,0 +1,46 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; + +namespace SteamAudio +{ + public abstract class AudioEngineAmbisonicSource + { + public virtual void Initialize(GameObject gameObject) + { } + + public virtual void Destroy() + { } + + public virtual void UpdateParameters(SteamAudioAmbisonicSource ambisonicSource) + { } + + public virtual void GetParameters(SteamAudioAmbisonicSource ambisonicSource) + { } + + public static AudioEngineAmbisonicSource Create(AudioEngineType type) + { + switch (type) + { + case AudioEngineType.Unity: + return new UnityAudioEngineAmbisonicSource(); + default: + return null; + } + } + } +} diff --git a/Scripts/Runtime/AudioEngineAmbisonicSource.cs.meta b/Scripts/Runtime/AudioEngineAmbisonicSource.cs.meta new file mode 100755 index 0000000..907707a --- /dev/null +++ b/Scripts/Runtime/AudioEngineAmbisonicSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf3a8878920e660448a9f5dd6ff8589f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/AudioEngineSource.cs b/Scripts/Runtime/AudioEngineSource.cs new file mode 100755 index 0000000..f60aaf4 --- /dev/null +++ b/Scripts/Runtime/AudioEngineSource.cs @@ -0,0 +1,59 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using System.Reflection; +using UnityEngine; + +namespace SteamAudio +{ + public abstract class AudioEngineSource + { + public virtual void Initialize(GameObject gameObject) + { } + + public virtual void Destroy() + { } + + public virtual void UpdateParameters(SteamAudioSource source) + { } + + public virtual void GetParameters(SteamAudioSource source) + { } + + public static AudioEngineSource Create(AudioEngineType type) + { + switch (type) + { + case AudioEngineType.Unity: + return new UnityAudioEngineSource(); + case AudioEngineType.FMODStudio: + return CreateFMODStudioAudioEngineSource(); + default: + return null; + } + } + + private static AudioEngineSource CreateFMODStudioAudioEngineSource() + { + var type = Type.GetType("SteamAudio.FMODStudioAudioEngineSource,SteamAudioUnity"); + return (type != null) ? (AudioEngineSource) Activator.CreateInstance(type) : null; + } + } +} + +#endif diff --git a/Scripts/Runtime/AudioEngineSource.cs.meta b/Scripts/Runtime/AudioEngineSource.cs.meta new file mode 100755 index 0000000..c3a3fe5 --- /dev/null +++ b/Scripts/Runtime/AudioEngineSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf1484b65484cc846b06a489d54195a2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/AudioEngineState.cs b/Scripts/Runtime/AudioEngineState.cs new file mode 100755 index 0000000..e9a47aa --- /dev/null +++ b/Scripts/Runtime/AudioEngineState.cs @@ -0,0 +1,89 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using System.Reflection; +using UnityEngine; +using SteamAudio; + +namespace SteamAudio +{ + public abstract class AudioEngineState + { + public virtual void Initialize(IntPtr context, IntPtr defaultHRTF, SimulationSettings simulationSettings, PerspectiveCorrection correction) + { } + + public virtual void Destroy() + { } + + public virtual void SetHRTF(IntPtr hrtf) + { } + + public virtual void SetPerspectiveCorrection(PerspectiveCorrection correction) + { } + + public virtual void SetReverbSource(Source reverbSource) + { } + + public static AudioEngineState Create(AudioEngineType type) + { + switch (type) + { + case AudioEngineType.Unity: + return new UnityAudioEngineState(); + case AudioEngineType.FMODStudio: + return CreateFMODStudioAudioEngineState(); + default: + return null; + } + } + + private static AudioEngineState CreateFMODStudioAudioEngineState() + { + var type = Type.GetType("SteamAudio.FMODStudioAudioEngineState,SteamAudioUnity"); + return (type != null) ? (AudioEngineState) Activator.CreateInstance(type) : null; + } + } + + public abstract class AudioEngineStateHelpers + { + public abstract Transform GetListenerTransform(); + + public abstract SteamAudio.AudioSettings GetAudioSettings(); + + public static AudioEngineStateHelpers Create(AudioEngineType type) + { + switch (type) + { + case AudioEngineType.Unity: + return new UnityAudioEngineStateHelpers(); + case AudioEngineType.FMODStudio: + return CreateFMODStudioAudioEngineStateHelpers(); + default: + return null; + } + } + + private static AudioEngineStateHelpers CreateFMODStudioAudioEngineStateHelpers() + { + var type = Type.GetType("SteamAudio.FMODStudioAudioEngineStateHelpers,SteamAudioUnity"); + return (type != null) ? (AudioEngineStateHelpers) Activator.CreateInstance(type) : null; + } + } +} + +#endif diff --git a/Scripts/Runtime/AudioEngineState.cs.meta b/Scripts/Runtime/AudioEngineState.cs.meta new file mode 100755 index 0000000..6e04db0 --- /dev/null +++ b/Scripts/Runtime/AudioEngineState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 82bc9a6ff2f97254787d9f40d71ae2e0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/Baker.cs b/Scripts/Runtime/Baker.cs new file mode 100755 index 0000000..6753c9b --- /dev/null +++ b/Scripts/Runtime/Baker.cs @@ -0,0 +1,349 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using AOT; +using System; +using System.Runtime.InteropServices; +using System.Threading; +using UnityEngine; +using UnityEngine.SceneManagement; +#if UNITY_EDITOR +using UnityEditor; +using UnityEditor.SceneManagement; +#endif + +namespace SteamAudio +{ + public enum BakeStatus + { + Ready, + InProgress, + Complete + } + + public struct BakedDataTask + { + public GameObject gameObject; + public MonoBehaviour component; + public string name; + public BakedDataIdentifier identifier; + public SteamAudioProbeBatch[] probeBatches; + public string[] probeBatchNames; + public SerializedData[] probeBatchAssets; + } + + public static class Baker + { + static BakeStatus sStatus = BakeStatus.Ready; +#if UNITY_EDITOR + static float sProgress = 0.0f; +#endif + static ProgressCallback sProgressCallback = null; + static IntPtr sProgressCallbackPointer = IntPtr.Zero; + static GCHandle sProgressCallbackHandle; + static Thread sThread; + static int sCurrentObjectIndex = 0; + static int sTotalObjects = 0; + static string sCurrentObjectName = null; + static int sCurrentProbeBatchIndex = 0; + static int sTotalProbeBatches = 0; + static bool sCancel = false; + static BakedDataTask[] sTasks = null; + + public static void BeginBake(BakedDataTask[] tasks) + { + SteamAudioManager.Initialize(ManagerInitReason.Baking); + + if (SteamAudioManager.GetSceneType() == SceneType.Custom) + { + Debug.LogError("Baking is not supported when using Unity's built-in ray tracer. Click Steam Audio > Settings and switch to a different ray tracer."); + return; + } + + SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false); + + SteamAudioStaticMesh staticMeshComponent = null; + var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects(); + foreach (var rootObject in rootObjects) + { + staticMeshComponent = rootObject.GetComponentInChildren(); + if (staticMeshComponent) + break; + } + + if (staticMeshComponent == null || staticMeshComponent.asset == null) + { + Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name)); + return; + } + + var staticMesh = new StaticMesh(SteamAudioManager.Context, SteamAudioManager.CurrentScene, staticMeshComponent.asset); + staticMesh.AddToScene(SteamAudioManager.CurrentScene); + + SteamAudioManager.CurrentScene.Commit(); + + staticMesh.Release(); + + sTasks = tasks; + sStatus = BakeStatus.InProgress; + + sProgressCallback = new ProgressCallback(AdvanceProgress); + +#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) + sProgressCallbackPointer = Marshal.GetFunctionPointerForDelegate(sProgressCallback); + sProgressCallbackHandle = GCHandle.Alloc(sProgressCallbackPointer); + GC.Collect(); +#endif + +#if UNITY_EDITOR + EditorApplication.update += InEditorUpdate; +#endif + + sThread = new Thread(BakeThread); + sThread.Start(); + } + + public static void EndBake() + { + if (sThread != null) + { + sThread.Join(); + } + + SerializedObject.FlushAllWrites(); + +#if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) + if (sProgressCallbackHandle.IsAllocated) + { + sProgressCallbackHandle.Free(); + } +#endif + + SteamAudioManager.ShutDown(); + UnityEngine.Object.DestroyImmediate(SteamAudioManager.Singleton.gameObject); + +#if UNITY_EDITOR + sProgress = 0.0f; +#endif + sCurrentObjectIndex = 0; + sTotalObjects = 0; + sCurrentObjectName = null; + sCurrentProbeBatchIndex = 0; + sTotalProbeBatches = 0; + + sStatus = BakeStatus.Ready; + +#if UNITY_EDITOR + EditorApplication.update -= InEditorUpdate; +#endif + } + + public static bool IsBakeActive() + { + return (sStatus != BakeStatus.Ready); + } + + public static bool DrawProgressBar() + { +#if UNITY_EDITOR + if (sStatus != BakeStatus.InProgress) + return false; + + var progress = sProgress + .01f; // Adding an offset because progress bar when it is exact 0 has some non-zero progress. + var progressPercent = Mathf.FloorToInt(Mathf.Min(progress * 100.0f, 100.0f)); + var progressString = string.Format("Object {0} / {1} [{2}]: Baking {3} / {4} Probe Batch ({5}% complete)", + sCurrentObjectIndex + 1, sTotalObjects, sCurrentObjectName, sCurrentProbeBatchIndex + 1, sTotalProbeBatches, progressPercent); + + EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(), progress, progressString); + + if (GUILayout.Button("Cancel")) + { + CancelBake(); + return false; + } +#endif + return true; + } + + public static void CancelBake() + { + // Ensures partial baked data is not serialized and that bake is properly canceled for multiple + // probe boxes. + sCancel = true; + API.iplReflectionsBakerCancelBake(SteamAudioManager.Context.Get()); + EndBake(); + sCancel = false; + } + + [MonoPInvokeCallback(typeof(ProgressCallback))] + static void AdvanceProgress(float progress, IntPtr userData) + { +#if UNITY_EDITOR + sProgress = progress; +#endif + } + + static void InEditorUpdate() + { +#if UNITY_EDITOR + if (sStatus == BakeStatus.Complete) + { + EndBake(); + EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); + } +#endif + } + + static void BakeThread() + { + sTotalObjects = sTasks.Length; + + for (var i = 0; i < sTotalObjects; ++i) + { + sCurrentObjectIndex = i; + + if (sTasks[i].identifier.type == BakedDataType.Pathing) + { + sCurrentObjectName = "pathing"; + } + else if (sTasks[i].identifier.variation == BakedDataVariation.Reverb) + { + sCurrentObjectName = "reverb"; + } + else + { + sCurrentObjectName = sTasks[i].name; + } + + Debug.Log(string.Format("START: Baking effect for {0}.", sCurrentObjectName)); + + var probeBatches = sTasks[i].probeBatches; + sTotalProbeBatches = probeBatches.Length; + + for (var j = 0; j < sTotalProbeBatches; ++j) + { + sCurrentProbeBatchIndex = j; + + if (sCancel) + return; + + if (probeBatches[j] == null) + { + Debug.LogWarning(string.Format("{0}: Probe Batch at index {1} is null.", sCurrentObjectName, j)); + continue; + } + + if (probeBatches[j].GetNumProbes() == 0) + { + Debug.LogWarning(string.Format("{0}: Probe Batch {1} has no probes, skipping.", sCurrentObjectName, sTasks[i].probeBatchNames[j])); + continue; + } + + var probeBatch = new ProbeBatch(SteamAudioManager.Context, sTasks[i].probeBatchAssets[j]); + + var simulationSettings = SteamAudioManager.GetSimulationSettings(true); + + if (sTasks[i].identifier.type == BakedDataType.Reflections) + { + var bakeParams = new ReflectionsBakeParams { }; + bakeParams.scene = SteamAudioManager.CurrentScene.Get(); + bakeParams.probeBatch = probeBatch.Get(); + bakeParams.sceneType = simulationSettings.sceneType; + bakeParams.identifier = sTasks[i].identifier; + bakeParams.flags = 0; + bakeParams.numRays = simulationSettings.maxNumRays; + bakeParams.numDiffuseSamples = simulationSettings.numDiffuseSamples; + bakeParams.numBounces = SteamAudioSettings.Singleton.bakingBounces; + bakeParams.simulatedDuration = simulationSettings.maxDuration; + bakeParams.savedDuration = simulationSettings.maxDuration; + bakeParams.order = simulationSettings.maxOrder; + bakeParams.numThreads = simulationSettings.numThreads; + bakeParams.rayBatchSize = simulationSettings.rayBatchSize; + bakeParams.irradianceMinDistance = SteamAudioSettings.Singleton.bakingIrradianceMinDistance; + bakeParams.bakeBatchSize = 1; + + if (SteamAudioSettings.Singleton.bakeConvolution) + bakeParams.flags = bakeParams.flags | ReflectionsBakeFlags.BakeConvolution; + + if (SteamAudioSettings.Singleton.bakeParametric) + bakeParams.flags = bakeParams.flags | ReflectionsBakeFlags.BakeParametric; + + if (simulationSettings.sceneType == SceneType.RadeonRays) + { + bakeParams.openCLDevice = SteamAudioManager.OpenCLDevice; + bakeParams.radeonRaysDevice = SteamAudioManager.RadeonRaysDevice; + bakeParams.bakeBatchSize = SteamAudioSettings.Singleton.bakingBatchSize; + } + + API.iplReflectionsBakerBake(SteamAudioManager.Context.Get(), ref bakeParams, sProgressCallback, IntPtr.Zero); + } + else + { + var bakeParams = new PathBakeParams { }; + bakeParams.scene = SteamAudioManager.CurrentScene.Get(); + bakeParams.probeBatch = probeBatch.Get(); + bakeParams.identifier = sTasks[i].identifier; + bakeParams.numSamples = SteamAudioSettings.Singleton.bakingVisibilitySamples; + bakeParams.radius = SteamAudioSettings.Singleton.bakingVisibilityRadius; + bakeParams.threshold = SteamAudioSettings.Singleton.bakingVisibilityThreshold; + bakeParams.visRange = SteamAudioSettings.Singleton.bakingVisibilityRange; + bakeParams.pathRange = SteamAudioSettings.Singleton.bakingPathRange; + bakeParams.numThreads = SteamAudioManager.Singleton.NumThreadsForCPUCorePercentage(SteamAudioSettings.Singleton.bakedPathingCPUCoresPercentage); + + API.iplPathBakerBake(SteamAudioManager.Context.Get(), ref bakeParams, sProgressCallback, IntPtr.Zero); + } + + if (sCancel) + { + Debug.Log("CANCELLED: Baking."); + return; + } + + // Don't flush the writes to disk just yet, because we can only do it from the main thread. + probeBatches[j].probeDataSize = probeBatch.Save(sTasks[i].probeBatchAssets[j], false); + + var dataSize = (int) probeBatch.GetDataSize(sTasks[i].identifier); + probeBatches[j].AddOrUpdateLayer(sTasks[i].gameObject, sTasks[i].identifier, dataSize); + + if (sTasks[i].identifier.type == BakedDataType.Reflections) + { + switch (sTasks[i].identifier.variation) + { + case BakedDataVariation.Reverb: + (sTasks[i].component as SteamAudioListener).UpdateBakedDataStatistics(); + break; + + case BakedDataVariation.StaticSource: + (sTasks[i].component as SteamAudioBakedSource).UpdateBakedDataStatistics(); + break; + + case BakedDataVariation.StaticListener: + (sTasks[i].component as SteamAudioBakedListener).UpdateBakedDataStatistics(); + break; + } + } + } + + Debug.Log(string.Format("COMPLETED: Baking effect for {0}.", sCurrentObjectName)); + } + + sStatus = BakeStatus.Complete; + } + } +} + +#endif diff --git a/Scripts/Runtime/Baker.cs.meta b/Scripts/Runtime/Baker.cs.meta new file mode 100755 index 0000000..7e9c0e8 --- /dev/null +++ b/Scripts/Runtime/Baker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 73a54b25ac58b5f499dae7062adb0e1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/Common.cs b/Scripts/Runtime/Common.cs new file mode 100755 index 0000000..8eff72d --- /dev/null +++ b/Scripts/Runtime/Common.cs @@ -0,0 +1,188 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.IO; +using System.Text; +using UnityEngine; + +namespace SteamAudio +{ + public static class Common + { + public static Vector3 ConvertVector(UnityEngine.Vector3 point) + { + Vector3 convertedPoint; + convertedPoint.x = point.x; + convertedPoint.y = point.y; + convertedPoint.z = -point.z; + + return convertedPoint; + } + + public static UnityEngine.Vector3 ConvertVector(Vector3 point) + { + UnityEngine.Vector3 convertedPoint; + convertedPoint.x = point.x; + convertedPoint.y = point.y; + convertedPoint.z = -point.z; + + return convertedPoint; + } + + public static Matrix4x4 ConvertTransform(Transform transform) + { + UnityEngine.Matrix4x4 flipZ = UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(1, 1, -1)); + UnityEngine.Matrix4x4 flippedMatrix = flipZ * transform.localToWorldMatrix * flipZ; + + var matrix = new Matrix4x4(); + matrix.m00 = flippedMatrix.m00; + matrix.m01 = flippedMatrix.m01; + matrix.m02 = flippedMatrix.m02; + matrix.m03 = flippedMatrix.m03; + matrix.m10 = flippedMatrix.m10; + matrix.m11 = flippedMatrix.m11; + matrix.m12 = flippedMatrix.m12; + matrix.m13 = flippedMatrix.m13; + matrix.m20 = flippedMatrix.m20; + matrix.m21 = flippedMatrix.m21; + matrix.m22 = flippedMatrix.m22; + matrix.m23 = flippedMatrix.m23; + matrix.m30 = flippedMatrix.m30; + matrix.m31 = flippedMatrix.m31; + matrix.m32 = flippedMatrix.m32; + matrix.m33 = flippedMatrix.m33; + + return matrix; + } + + public static Matrix4x4 TransposeMatrix(Matrix4x4 inMatrix) + { + var outMatrix = new Matrix4x4(); + + outMatrix.m00 = inMatrix.m00; + outMatrix.m01 = inMatrix.m10; + outMatrix.m02 = inMatrix.m20; + outMatrix.m03 = inMatrix.m30; + outMatrix.m10 = inMatrix.m01; + outMatrix.m11 = inMatrix.m11; + outMatrix.m12 = inMatrix.m21; + outMatrix.m13 = inMatrix.m31; + outMatrix.m20 = inMatrix.m02; + outMatrix.m21 = inMatrix.m12; + outMatrix.m22 = inMatrix.m22; + outMatrix.m23 = inMatrix.m32; + outMatrix.m30 = inMatrix.m03; + outMatrix.m31 = inMatrix.m13; + outMatrix.m32 = inMatrix.m23; + outMatrix.m33 = inMatrix.m33; + + return outMatrix; + } + + public static Matrix4x4 TransformMatrix(UnityEngine.Matrix4x4 inMatrix) + { + var outMatrix = new Matrix4x4(); + + outMatrix.m00 = inMatrix.m00; + outMatrix.m01 = inMatrix.m01; + outMatrix.m02 = inMatrix.m02; + outMatrix.m03 = inMatrix.m03; + outMatrix.m10 = inMatrix.m10; + outMatrix.m11 = inMatrix.m11; + outMatrix.m12 = inMatrix.m12; + outMatrix.m13 = inMatrix.m13; + outMatrix.m20 = inMatrix.m20; + outMatrix.m21 = inMatrix.m21; + outMatrix.m22 = inMatrix.m22; + outMatrix.m23 = inMatrix.m23; + outMatrix.m30 = inMatrix.m30; + outMatrix.m31 = inMatrix.m31; + outMatrix.m32 = inMatrix.m32; + outMatrix.m33 = inMatrix.m33; + + return outMatrix; + } + + public static byte[] ConvertString(string s) + { + return Encoding.UTF8.GetBytes(s + Char.MinValue); + } + + public static string GetStreamingAssetsFileName(string fileName) + { + var streamingAssetsFileName = Path.Combine(Application.streamingAssetsPath, fileName); + +#if UNITY_ANDROID && !UNITY_EDITOR + var tempFileName = Path.Combine(Application.temporaryCachePath, fileName); + + if (File.Exists(tempFileName)) + { + File.Delete(tempFileName); + } + + try + { + var streamingAssetLoader = new WWW(streamingAssetsFileName); + while (!streamingAssetLoader.isDone) + { + } + + if (string.IsNullOrEmpty(streamingAssetLoader.error)) + { + using (var dataWriter = new BinaryWriter(new FileStream(tempFileName, FileMode.Create))) + { + dataWriter.Write(streamingAssetLoader.bytes); + dataWriter.Close(); + } + } + else + { + Debug.LogError(streamingAssetLoader.error); + } + } + catch (Exception exception) + { + Debug.LogError(exception.ToString()); + } + + return tempFileName; +#else + return streamingAssetsFileName; +#endif + } + + public static string HumanReadableDataSize(int dataSize) + { + if (dataSize < 1e3) + { + return dataSize.ToString() + " bytes"; + } + else if (dataSize < 1e6) + { + return (dataSize / 1e3f).ToString("0.0") + " kB"; + } + else if (dataSize < 1e9) + { + return (dataSize / 1e6f).ToString("0.0") + " MB"; + } + else + { + return (dataSize / 1e9f).ToString("0.0") + " GB"; + } + } + } +} diff --git a/Scripts/Runtime/Common.cs.meta b/Scripts/Runtime/Common.cs.meta new file mode 100755 index 0000000..bd78e19 --- /dev/null +++ b/Scripts/Runtime/Common.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7797e245e8512a547ab441d68268cc01 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/Context.cs b/Scripts/Runtime/Context.cs new file mode 100755 index 0000000..0fa072f --- /dev/null +++ b/Scripts/Runtime/Context.cs @@ -0,0 +1,84 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using AOT; +using System; +using UnityEngine; + +namespace SteamAudio +{ + public class Context + { + IntPtr mContext = IntPtr.Zero; + + public Context() + { + var contextSettings = new ContextSettings { }; + contextSettings.version = Constants.kVersion; + contextSettings.logCallback = LogMessage; + contextSettings.simdLevel = SIMDLevel.AVX2; + + if (SteamAudioSettings.Singleton.EnableValidation) + { + contextSettings.flags = contextSettings.flags | ContextFlags.Validation; + } + + var status = API.iplContextCreate(ref contextSettings, out mContext); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create context. [{0}]", status)); + } + + public Context(Context context) + { + mContext = API.iplContextRetain(context.Get()); + } + + ~Context() + { + Release(); + } + + public void Release() + { + API.iplContextRelease(ref mContext); + } + + public IntPtr Get() + { + return mContext; + } + + [MonoPInvokeCallback(typeof(LogCallback))] + public static void LogMessage(LogLevel level, string message) + { + switch (level) + { + case LogLevel.Info: + case LogLevel.Debug: + Debug.Log(message); + break; + case LogLevel.Warning: + Debug.LogWarning(message); + break; + case LogLevel.Error: + Debug.LogError(message); + break; + default: + break; + } + } + } +} \ No newline at end of file diff --git a/Scripts/Runtime/Context.cs.meta b/Scripts/Runtime/Context.cs.meta new file mode 100755 index 0000000..2cfc63e --- /dev/null +++ b/Scripts/Runtime/Context.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 19c99b97347775a4d901f873fee55e3d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/EmbreeDevice.cs b/Scripts/Runtime/EmbreeDevice.cs new file mode 100755 index 0000000..6beb0d4 --- /dev/null +++ b/Scripts/Runtime/EmbreeDevice.cs @@ -0,0 +1,54 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; + +namespace SteamAudio +{ + public class EmbreeDevice + { + IntPtr mEmbreeDevice = IntPtr.Zero; + + public EmbreeDevice(Context context) + { + var embreeDeviceSettings = new EmbreeDeviceSettings { }; + + var status = API.iplEmbreeDeviceCreate(context.Get(), ref embreeDeviceSettings, out mEmbreeDevice); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create Embree device. [{0}]", status)); + } + + public EmbreeDevice(EmbreeDevice embreeDevice) + { + mEmbreeDevice = API.iplEmbreeDeviceRetain(embreeDevice.mEmbreeDevice); + } + + ~EmbreeDevice() + { + Release(); + } + + public void Release() + { + API.iplEmbreeDeviceRelease(ref mEmbreeDevice); + } + + public IntPtr Get() + { + return mEmbreeDevice; + } + } +} diff --git a/Scripts/Runtime/EmbreeDevice.cs.meta b/Scripts/Runtime/EmbreeDevice.cs.meta new file mode 100755 index 0000000..6d10b2a --- /dev/null +++ b/Scripts/Runtime/EmbreeDevice.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b63c80d20765d8f49be4ad645532115f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/FMODStudioAudioEngineSource.cs b/Scripts/Runtime/FMODStudioAudioEngineSource.cs new file mode 100755 index 0000000..f07af02 --- /dev/null +++ b/Scripts/Runtime/FMODStudioAudioEngineSource.cs @@ -0,0 +1,186 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using System.Reflection; +using UnityEngine; + +namespace SteamAudio +{ + public sealed class FMODStudioAudioEngineSource : AudioEngineSource + { + bool mFoundDSP = false; + object mEventEmitter = null; + object mEventInstance = null; + object mDSP = null; + SteamAudioSource mSteamAudioSource = null; + int mHandle = -1; + + static Type FMOD_DSP; + static Type FMOD_ChannelGroup; + static Type FMOD_Studio_EventInstance; + static Type FMODUnity_StudioEventEmitter; + static PropertyInfo FMODUnity_StudioEventEmitter_EventInstance; + static MethodInfo FMOD_Studio_EventInstance_getChannelGroup; + static MethodInfo FMOD_Studio_EventInstance_isValid; + static MethodInfo FMOD_ChannelGroup_getNumDSPs; + static MethodInfo FMOD_ChannelGroup_getDSP; + static MethodInfo FMOD_DSP_getInfo; + static MethodInfo FMOD_DSP_setParameterInt; + static bool mBoundToPlugin = false; + + const int kSimulationOutputsParamIndex = 33; + + public override void Initialize(GameObject gameObject) + { + FindDSP(gameObject); + + mSteamAudioSource = gameObject.GetComponent(); + if (mSteamAudioSource) + { + mHandle = FMODStudioAPI.iplFMODAddSource(mSteamAudioSource.GetSource().Get()); + } + } + + public override void Destroy() + { + mFoundDSP = false; + + if (mSteamAudioSource) + { + FMODStudioAPI.iplFMODRemoveSource(mHandle); + } + } + + public override void UpdateParameters(SteamAudioSource source) + { + CheckForChangedEventInstance(); + + FindDSP(source.gameObject); + if (!mFoundDSP) + return; + + var index = kSimulationOutputsParamIndex; + FMOD_DSP_setParameterInt.Invoke(mDSP, new object[] { index++, mHandle }); + } + + void CheckForChangedEventInstance() + { + if (mEventEmitter != null) + { + var eventInstance = FMODUnity_StudioEventEmitter_EventInstance.GetValue(mEventEmitter, null); + if (eventInstance != mEventInstance) + { + // The event instance is different from the one we last used, which most likely means the + // event-related objects were destroyed and re-created. Make sure we look for the DSP instance + // when FindDSP is called next. + mFoundDSP = false; + } + } + else + { + // We haven't yet seen a valid event emitter component, so make sure we look for one when + // FindDSP is called. + mFoundDSP = false; + } + } + + void FindDSP(GameObject gameObject) + { + if (mFoundDSP) + return; + + BindToFMODStudioPlugin(); + + mEventEmitter = gameObject.GetComponent(FMODUnity_StudioEventEmitter) as object; + if (mEventEmitter == null) + return; + + mEventInstance = FMODUnity_StudioEventEmitter_EventInstance.GetValue(mEventEmitter, null); + if (!((bool)FMOD_Studio_EventInstance_isValid.Invoke(mEventInstance, null))) + return; + + var channelGroup = Activator.CreateInstance(FMOD_ChannelGroup); + + var getChannelGroupArgs = new object[] { channelGroup }; + FMOD_Studio_EventInstance_getChannelGroup.Invoke(mEventInstance, getChannelGroupArgs); + channelGroup = getChannelGroupArgs[0]; + + var getNumDSPsArgs = new object[] { 0 }; + FMOD_ChannelGroup_getNumDSPs.Invoke(channelGroup, getNumDSPsArgs); + int numDSPs = (int)getNumDSPsArgs[0]; + + for (var i = 0; i < numDSPs; ++i) + { + var getDSPArgs = new object[] { i, mDSP }; + FMOD_ChannelGroup_getDSP.Invoke(channelGroup, getDSPArgs); + mDSP = getDSPArgs[1]; + + var dspName = ""; + var dspVersion = 0u; + var dspNumChannels = 0; + var dspConfigWidth = 0; + var dspConfigHeight = 0; + + var getInfoArgs = new object[] { dspName, dspVersion, dspNumChannels, dspConfigWidth, dspConfigHeight }; + FMOD_DSP_getInfo.Invoke(mDSP, getInfoArgs); + dspName = (string)getInfoArgs[0]; + + if (dspName == "Steam Audio Spatializer") + { + mFoundDSP = true; + return; + } + } + } + + static void BindToFMODStudioPlugin() + { + if (mBoundToPlugin) + return; + + var assemblySuffix = ",FMODUnity"; + + FMOD_DSP = Type.GetType("FMOD.DSP" + assemblySuffix); + FMOD_ChannelGroup = Type.GetType("FMOD.ChannelGroup" + assemblySuffix); + FMOD_Studio_EventInstance = Type.GetType("FMOD.Studio.EventInstance" + assemblySuffix); + FMODUnity_StudioEventEmitter = Type.GetType("FMODUnity.StudioEventEmitter" + assemblySuffix); + + FMODUnity_StudioEventEmitter_EventInstance = FMODUnity_StudioEventEmitter.GetProperty("EventInstance"); + + FMOD_Studio_EventInstance_getChannelGroup = FMOD_Studio_EventInstance.GetMethod("getChannelGroup"); + FMOD_Studio_EventInstance_isValid = FMOD_Studio_EventInstance.GetMethod("isValid"); + FMOD_ChannelGroup_getNumDSPs = FMOD_ChannelGroup.GetMethod("getNumDSPs"); + FMOD_ChannelGroup_getDSP = FMOD_ChannelGroup.GetMethod("getDSP"); + FMOD_DSP_setParameterInt = FMOD_DSP.GetMethod("setParameterInt"); + + var candidates = FMOD_DSP.GetMethods(); + foreach (var candidate in candidates) + { + if (candidate.Name == "getInfo" && candidate.GetParameters().Length == 5) + { + FMOD_DSP_getInfo = candidate; + break; + } + } + + mBoundToPlugin = true; + } + } +} + +#endif diff --git a/Scripts/Runtime/FMODStudioAudioEngineSource.cs.meta b/Scripts/Runtime/FMODStudioAudioEngineSource.cs.meta new file mode 100755 index 0000000..d54e96f --- /dev/null +++ b/Scripts/Runtime/FMODStudioAudioEngineSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c36706fa5b924b94c8895e3051bdee14 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/FMODStudioAudioEngineState.cs b/Scripts/Runtime/FMODStudioAudioEngineState.cs new file mode 100755 index 0000000..f162de6 --- /dev/null +++ b/Scripts/Runtime/FMODStudioAudioEngineState.cs @@ -0,0 +1,109 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using System.Reflection; +using UnityEngine; + +namespace SteamAudio +{ + public sealed class FMODStudioAudioEngineState : AudioEngineState + { + public override void Initialize(IntPtr context, IntPtr defaultHRTF, SimulationSettings simulationSettings, PerspectiveCorrection correction) + { + FMODStudioAPI.iplFMODInitialize(context); + FMODStudioAPI.iplFMODSetHRTF(defaultHRTF); + FMODStudioAPI.iplFMODSetSimulationSettings(simulationSettings); + } + + public override void Destroy() + { + FMODStudioAPI.iplFMODTerminate(); + } + + public override void SetHRTF(IntPtr hrtf) + { + FMODStudioAPI.iplFMODSetHRTF(hrtf); + } + + public override void SetReverbSource(Source reverbSource) + { + FMODStudioAPI.iplFMODSetReverbSource(reverbSource.Get()); + } + } + + public sealed class FMODStudioAudioEngineStateHelpers : AudioEngineStateHelpers + { + static bool mBoundToPlugin = false; + + static Type FMOD_SPEAKERMODE; + static Type FMOD_System; + static Type FMODUnity_StudioListener; + static Type FMODUnity_RuntimeManager; + static PropertyInfo FMODUnity_RuntimeManager_CoreSystem; + static MethodInfo FMOD_System_getSoftwareFormat; + static MethodInfo FMOD_System_getDSPBufferSize; + + public override Transform GetListenerTransform() + { + BindToFMODStudioPlugin(); + + var fmodStudioListener = (MonoBehaviour) GameObject.FindObjectOfType(FMODUnity_StudioListener); + return (fmodStudioListener != null) ? fmodStudioListener.transform : null; + } + + public override AudioSettings GetAudioSettings() + { + BindToFMODStudioPlugin(); + + var audioSettings = new AudioSettings { }; + + var fmodSystem = FMODUnity_RuntimeManager_CoreSystem.GetValue(null, null); + + var speakerMode = Activator.CreateInstance(FMOD_SPEAKERMODE); + var getSoftwareFormatArgs = new object[] { 0, speakerMode, 0 }; + FMOD_System_getSoftwareFormat.Invoke(fmodSystem, getSoftwareFormatArgs); + audioSettings.samplingRate = (int) getSoftwareFormatArgs[0]; + + var getDSPBufferSizeArgs = new object[] { 0u, 0 }; + FMOD_System_getDSPBufferSize.Invoke(fmodSystem, getDSPBufferSizeArgs); + audioSettings.frameSize = (int) ((uint) getDSPBufferSizeArgs[0]); + + return audioSettings; + } + + static void BindToFMODStudioPlugin() + { + if (mBoundToPlugin) + return; + + var assemblySuffix = ",FMODUnity"; + + FMOD_SPEAKERMODE = Type.GetType("FMOD.SPEAKERMODE" + assemblySuffix); + FMOD_System = Type.GetType("FMOD.System" + assemblySuffix); + FMODUnity_StudioListener = Type.GetType("FMODUnity.StudioListener" + assemblySuffix); + FMODUnity_RuntimeManager = Type.GetType("FMODUnity.RuntimeManager" + assemblySuffix); + + FMODUnity_RuntimeManager_CoreSystem = FMODUnity_RuntimeManager.GetProperty("CoreSystem"); + + FMOD_System_getSoftwareFormat = FMOD_System.GetMethod("getSoftwareFormat"); + FMOD_System_getDSPBufferSize = FMOD_System.GetMethod("getDSPBufferSize"); + } + } +} + +#endif \ No newline at end of file diff --git a/Scripts/Runtime/FMODStudioAudioEngineState.cs.meta b/Scripts/Runtime/FMODStudioAudioEngineState.cs.meta new file mode 100755 index 0000000..4c51d9f --- /dev/null +++ b/Scripts/Runtime/FMODStudioAudioEngineState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f8e2075eab110ad4b88d26e434723035 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/HRTF.cs b/Scripts/Runtime/HRTF.cs new file mode 100755 index 0000000..f0366b4 --- /dev/null +++ b/Scripts/Runtime/HRTF.cs @@ -0,0 +1,102 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Runtime.InteropServices; +using UnityEngine; + +namespace SteamAudio +{ + public class HRTF + { + IntPtr mHRTF = IntPtr.Zero; + + public HRTF(Context context, AudioSettings audioSettings, string sofaFileName, byte[] sofaFileData, float gaindB, HRTFNormType normType) + { + IntPtr sofaData = IntPtr.Zero; + + var hrtfSettings = new HRTFSettings { }; + if (sofaFileData != null && sofaFileData.Length > 0) + { + hrtfSettings.type = HRTFType.SOFA; + + sofaData = Marshal.AllocHGlobal(sofaFileData.Length); + Marshal.Copy(sofaFileData, 0, sofaData, sofaFileData.Length); + + hrtfSettings.sofaFileData = sofaData; + hrtfSettings.sofaFileDataSize = sofaFileData.Length; + } + else if (sofaFileName != null) + { + hrtfSettings.type = HRTFType.SOFA; + hrtfSettings.sofaFileName = sofaFileName; + } + else + { + hrtfSettings.type = HRTFType.Default; + } + + hrtfSettings.volume = dBToGain(gaindB); + hrtfSettings.normType = normType; + + var status = API.iplHRTFCreate(context.Get(), ref audioSettings, ref hrtfSettings, out mHRTF); + if (status != Error.Success) + { + Debug.LogError(string.Format("Unable to load HRTF: {0}. [{1}]", (sofaFileName != null) ? sofaFileName : "default", status)); + mHRTF = IntPtr.Zero; + } + else + { + Debug.Log(string.Format("Loaded HRTF: {0}.", (sofaFileName != null) ? sofaFileName : "default")); + } + + if (sofaData != IntPtr.Zero) + { + Marshal.FreeHGlobal(sofaData); + } + } + + public HRTF(HRTF hrtf) + { + mHRTF = API.iplHRTFRetain(hrtf.Get()); + } + + ~HRTF() + { + Release(); + } + + public void Release() + { + API.iplHRTFRelease(ref mHRTF); + } + + public IntPtr Get() + { + return mHRTF; + } + + private float dBToGain(float gaindB) + { + const float kMinDBLevel = -90.0f; + + if (gaindB <= kMinDBLevel) + return 0.0f; + + return (float) Math.Pow(10.0, (double) gaindB * (1.0 / 20.0)); + } + } +} diff --git a/Scripts/Runtime/HRTF.cs.meta b/Scripts/Runtime/HRTF.cs.meta new file mode 100755 index 0000000..2c1dd96 --- /dev/null +++ b/Scripts/Runtime/HRTF.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2676d545429ad5547a1ea3389903271e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/InstancedMesh.cs b/Scripts/Runtime/InstancedMesh.cs new file mode 100755 index 0000000..4dd66b8 --- /dev/null +++ b/Scripts/Runtime/InstancedMesh.cs @@ -0,0 +1,77 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public class InstancedMesh + { + IntPtr mInstancedMesh = IntPtr.Zero; + + public InstancedMesh(Scene scene, Scene subScene, Transform transform) + { + var instancedMeshSettings = new InstancedMeshSettings { }; + instancedMeshSettings.subScene = subScene.Get(); + instancedMeshSettings.transform = Common.ConvertTransform(transform); + + var status = API.iplInstancedMeshCreate(scene.Get(), ref instancedMeshSettings, out mInstancedMesh); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create instanced mesh ({0}). [{1}]", transform.gameObject.name, status)); + } + + public InstancedMesh(InstancedMesh instancedMesh) + { + mInstancedMesh = API.iplInstancedMeshRetain(instancedMesh.mInstancedMesh); + } + + ~InstancedMesh() + { + Release(); + } + + public void Release() + { + API.iplInstancedMeshRelease(ref mInstancedMesh); + } + + public IntPtr Get() + { + return mInstancedMesh; + } + + public void AddToScene(Scene scene) + { + API.iplInstancedMeshAdd(mInstancedMesh, scene.Get()); + scene.NotifyAddObject(); + } + + public void RemoveFromScene(Scene scene) + { + API.iplInstancedMeshRemove(mInstancedMesh, scene.Get()); + scene.NotifyRemoveObject(); + } + + public void UpdateTransform(Scene scene, Transform transform) + { + API.iplInstancedMeshUpdateTransform(mInstancedMesh, scene.Get(), Common.ConvertTransform(transform)); + } + } +} + +#endif diff --git a/Scripts/Runtime/InstancedMesh.cs.meta b/Scripts/Runtime/InstancedMesh.cs.meta new file mode 100755 index 0000000..7612f26 --- /dev/null +++ b/Scripts/Runtime/InstancedMesh.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e9b254356f848f34d976c386541ec68b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/OpenCLDevice.cs b/Scripts/Runtime/OpenCLDevice.cs new file mode 100755 index 0000000..b0f8d56 --- /dev/null +++ b/Scripts/Runtime/OpenCLDevice.cs @@ -0,0 +1,94 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public class OpenCLDevice + { + IntPtr mOpenCLDevice = IntPtr.Zero; + + public OpenCLDevice(Context context, OpenCLDeviceType deviceType, int numCUsToReserve, float fractionCUsForIRUpdate, + bool requiresTAN) + { + var deviceSettings = new OpenCLDeviceSettings { }; + deviceSettings.type = deviceType; + deviceSettings.numCUsToReserve = numCUsToReserve; + deviceSettings.fractionCUsForIRUpdate = fractionCUsForIRUpdate; + deviceSettings.requiresTAN = requiresTAN ? Bool.True : Bool.False; + + var deviceList = IntPtr.Zero; + var status = API.iplOpenCLDeviceListCreate(context.Get(), ref deviceSettings, out deviceList); + if (status != Error.Success) + throw new Exception(string.Format("Unable to enumerate OpenCL devices. [{0}]", status)); + + var numDevices = API.iplOpenCLDeviceListGetNumDevices(deviceList); + if (numDevices <= 0) + { + API.iplOpenCLDeviceListRelease(ref deviceList); + + // If we explicitly requested a device that supports TAN, or if we didn't ask for CU + // reservation, but still didn't find any devices, stop. + if (requiresTAN || numCUsToReserve == 0) + throw new Exception(string.Format("No OpenCL devices found.")); + + Debug.LogWarning("No OpenCL devices found that match the provided parameters, attempting to " + + "initialize without CU reservation."); + + deviceSettings.numCUsToReserve = 0; + deviceSettings.fractionCUsForIRUpdate = 0.0f; + status = API.iplOpenCLDeviceListCreate(context.Get(), ref deviceSettings, out deviceList); + if (status != Error.Success) + throw new Exception(string.Format("Unable to enumerate OpenCL devices. [{0}]", status)); + + numDevices = API.iplOpenCLDeviceListGetNumDevices(deviceList); + if (numDevices <= 0) + throw new Exception(string.Format("No OpenCL devices found.")); + } + + status = API.iplOpenCLDeviceCreate(context.Get(), deviceList, 0, out mOpenCLDevice); + if (status != Error.Success) + { + API.iplOpenCLDeviceListRelease(ref deviceList); + throw new Exception(string.Format("Unable to create OpenCL device. [{0}]", status)); + } + + API.iplOpenCLDeviceListRelease(ref deviceList); + } + + public OpenCLDevice(OpenCLDevice device) + { + mOpenCLDevice = API.iplOpenCLDeviceRetain(device.mOpenCLDevice); + } + + ~OpenCLDevice() + { + Release(); + } + + public void Release() + { + API.iplOpenCLDeviceRelease(ref mOpenCLDevice); + } + + public IntPtr Get() + { + return mOpenCLDevice; + } + } +} diff --git a/Scripts/Runtime/OpenCLDevice.cs.meta b/Scripts/Runtime/OpenCLDevice.cs.meta new file mode 100755 index 0000000..3dca07f --- /dev/null +++ b/Scripts/Runtime/OpenCLDevice.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 980da0934e6939d439f50baac22a5286 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/ProbeBatch.cs b/Scripts/Runtime/ProbeBatch.cs new file mode 100755 index 0000000..cd208cf --- /dev/null +++ b/Scripts/Runtime/ProbeBatch.cs @@ -0,0 +1,151 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public class ProbeArray + { + IntPtr mProbeArray = IntPtr.Zero; + + public ProbeArray(Context context) + { + API.iplProbeArrayCreate(context.Get(), out mProbeArray); + } + + public ProbeArray(ProbeArray probeArray) + { + mProbeArray = API.iplProbeArrayRetain(probeArray.mProbeArray); + } + + ~ProbeArray() + { + Release(); + } + + public void Release() + { + API.iplProbeArrayRelease(ref mProbeArray); + } + + public IntPtr Get() + { + return mProbeArray; + } + + public void GenerateProbes(Scene scene, ProbeGenerationParams probeGenerationParams) + { + API.iplProbeArrayGenerateProbes(mProbeArray, scene.Get(), ref probeGenerationParams); + } + + public int GetNumProbes() + { + return API.iplProbeArrayGetNumProbes(mProbeArray); + } + + public Sphere GetProbe(int index) + { + return API.iplProbeArrayGetProbe(mProbeArray, index); + } + } + + public class ProbeBatch + { + Context mContext = null; + IntPtr mProbeBatch = IntPtr.Zero; + + public ProbeBatch(Context context) + { + mContext = context; + + API.iplProbeBatchCreate(context.Get(), out mProbeBatch); + } + + public ProbeBatch(Context context, SerializedData dataAsset) + { + mContext = context; + + var serializedObject = new SerializedObject(context, dataAsset); + + var status = API.iplProbeBatchLoad(context.Get(), serializedObject.Get(), out mProbeBatch); + if (status != Error.Success) + { + Debug.LogError(string.Format("Unable to load Probe Batch from {0}.", dataAsset.name)); + mProbeBatch = IntPtr.Zero; + } + + serializedObject.Release(); + } + + public ProbeBatch(ProbeBatch probeBatch) + { + mContext = probeBatch.mContext; + + mProbeBatch = API.iplProbeBatchRetain(probeBatch.mProbeBatch); + } + + ~ProbeBatch() + { + Release(); + } + + public void Release() + { + API.iplProbeBatchRelease(ref mProbeBatch); + + mContext = null; + } + + public IntPtr Get() + { + return mProbeBatch; + } + + public int Save(SerializedData dataAsset, bool flush = true) + { + var serializedObject = new SerializedObject(mContext); + API.iplProbeBatchSave(mProbeBatch, serializedObject.Get()); + var size = (int) serializedObject.GetSize(); + serializedObject.WriteToFile(dataAsset, flush); + serializedObject.Release(); + return size; + } + + public void AddProbeArray(ProbeArray probeArray) + { + API.iplProbeBatchAddProbeArray(mProbeBatch, probeArray.Get()); + } + + public void Commit() + { + API.iplProbeBatchCommit(mProbeBatch); + } + + public void RemoveData(BakedDataIdentifier identifier) + { + API.iplProbeBatchRemoveData(mProbeBatch, ref identifier); + } + + public UIntPtr GetDataSize(BakedDataIdentifier identifier) + { + return API.iplProbeBatchGetDataSize(mProbeBatch, ref identifier); + } + } +} +#endif diff --git a/Scripts/Runtime/ProbeBatch.cs.meta b/Scripts/Runtime/ProbeBatch.cs.meta new file mode 100755 index 0000000..ee5e345 --- /dev/null +++ b/Scripts/Runtime/ProbeBatch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63ee2a9f8d2a86043bb79036d010ee2a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/RadeonRaysDevice.cs b/Scripts/Runtime/RadeonRaysDevice.cs new file mode 100755 index 0000000..5aa770f --- /dev/null +++ b/Scripts/Runtime/RadeonRaysDevice.cs @@ -0,0 +1,54 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; + +namespace SteamAudio +{ + public class RadeonRaysDevice + { + IntPtr mRadeonRaysDevice = IntPtr.Zero; + + public RadeonRaysDevice(OpenCLDevice openCLDevice) + { + var deviceSettings = new RadeonRaysDeviceSettings { }; + + var status = API.iplRadeonRaysDeviceCreate(openCLDevice.Get(), ref deviceSettings, out mRadeonRaysDevice); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create Radeon Rays device. [{0}]", status)); + } + + public RadeonRaysDevice(RadeonRaysDevice device) + { + mRadeonRaysDevice = API.iplRadeonRaysDeviceRetain(device.mRadeonRaysDevice); + } + + ~RadeonRaysDevice() + { + Release(); + } + + public void Release() + { + API.iplRadeonRaysDeviceRelease(ref mRadeonRaysDevice); + } + + public IntPtr Get() + { + return mRadeonRaysDevice; + } + } +} diff --git a/Scripts/Runtime/RadeonRaysDevice.cs.meta b/Scripts/Runtime/RadeonRaysDevice.cs.meta new file mode 100755 index 0000000..a2a3aba --- /dev/null +++ b/Scripts/Runtime/RadeonRaysDevice.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ab45c0e4ff6a2c445843d2133d90ce2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SOFAFile.cs b/Scripts/Runtime/SOFAFile.cs new file mode 100755 index 0000000..d768889 --- /dev/null +++ b/Scripts/Runtime/SOFAFile.cs @@ -0,0 +1,38 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; + +namespace SteamAudio +{ + /* + * Represents a serializable object that is created when importing a .sofa file as an asset. + */ + public class SOFAFile : ScriptableObject + { + // The name of the sofa file that was imported. + public string sofaName = ""; + + // The imported data. + public byte[] data = null; + + // The volume correction factor in dB. + public float volume = 0.0f; + + // Volume normalization type. + public HRTFNormType normType = HRTFNormType.None; + } +} diff --git a/Scripts/Runtime/SOFAFile.cs.meta b/Scripts/Runtime/SOFAFile.cs.meta new file mode 100755 index 0000000..ecd60dd --- /dev/null +++ b/Scripts/Runtime/SOFAFile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c07f8c30ab6b2bb4380f1a4429dd557a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/Scene.cs b/Scripts/Runtime/Scene.cs new file mode 100755 index 0000000..ecf4697 --- /dev/null +++ b/Scripts/Runtime/Scene.cs @@ -0,0 +1,114 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; + +namespace SteamAudio +{ + public class Scene + { + Context mContext = null; + IntPtr mScene = IntPtr.Zero; + int mNumObjects = 0; + + public Scene(Context context, SceneType type, EmbreeDevice embreeDevice, RadeonRaysDevice radeonRaysDevice, ClosestHitCallback closestHitCallback, AnyHitCallback anyHitCallback) + { + mContext = context; + + var sceneSettings = new SceneSettings { }; + sceneSettings.type = type; + sceneSettings.embreeDevice = (embreeDevice != null) ? embreeDevice.Get() : IntPtr.Zero; + sceneSettings.radeonRaysDevice = (radeonRaysDevice != null) ? radeonRaysDevice.Get() : IntPtr.Zero; + sceneSettings.closestHitCallback = closestHitCallback; + sceneSettings.anyHitCallback = anyHitCallback; + + var status = API.iplSceneCreate(context.Get(), ref sceneSettings, out mScene); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create scene [{0}]", status.ToString())); + } + + public Scene(Context context, SceneSettings sceneSettings, SerializedData dataAsset) + { + mContext = context; + + var serializedObject = new SerializedObject(context, dataAsset); + var status = API.iplSceneLoad(context.Get(), ref sceneSettings, serializedObject.Get(), null, IntPtr.Zero, out mScene); + if (status != Error.Success) + throw new Exception(string.Format("Unable to load scene [{0}]", status.ToString())); + + serializedObject.Release(); + } + + public Scene(Scene scene) + { + mContext = scene.mContext; + + mScene = API.iplSceneRetain(scene.mScene); + } + + ~Scene() + { + Release(); + } + + public void Release() + { + API.iplSceneRelease(ref mScene); + + mContext = null; + } + + public IntPtr Get() + { + return mScene; + } + + public void Save(SerializedData dataAsset) + { + var serializedObject = new SerializedObject(mContext); + API.iplSceneSave(mScene, serializedObject.Get()); + serializedObject.WriteToFile(dataAsset); + serializedObject.Release(); + } + + public void SaveOBJ(string fileBaseName) + { + API.iplSceneSaveOBJ(mScene, fileBaseName); + } + + public void NotifyAddObject() + { + ++mNumObjects; + } + + public void NotifyRemoveObject() + { + --mNumObjects; + } + + public int GetNumObjects() + { + return mNumObjects; + } + + public void Commit() + { + API.iplSceneCommit(mScene); + } + } +} +#endif diff --git a/Scripts/Runtime/Scene.cs.meta b/Scripts/Runtime/Scene.cs.meta new file mode 100755 index 0000000..52f3111 --- /dev/null +++ b/Scripts/Runtime/Scene.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f36118f1552c924438a563f1eba9832d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SerializedData.cs b/Scripts/Runtime/SerializedData.cs new file mode 100755 index 0000000..87e737f --- /dev/null +++ b/Scripts/Runtime/SerializedData.cs @@ -0,0 +1,45 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace SteamAudio +{ + public class SerializedData : ScriptableObject + { + [SerializeField] + public byte[] data; + + public static SerializedData PromptForNewAsset(string defaultFileName) + { +#if UNITY_EDITOR + var fileName = EditorUtility.SaveFilePanelInProject("Export", defaultFileName, "asset", + "Select a file to export data to."); + + if (fileName != null && fileName.Length > 0) + { + var dataAsset = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(dataAsset, fileName); + return dataAsset; + } +#endif + return null; + } + } +} diff --git a/Scripts/Runtime/SerializedData.cs.meta b/Scripts/Runtime/SerializedData.cs.meta new file mode 100755 index 0000000..b2aa98c --- /dev/null +++ b/Scripts/Runtime/SerializedData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3a82078fb50fbcb46a7e4402721b1a31 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SerializedObject.cs b/Scripts/Runtime/SerializedObject.cs new file mode 100755 index 0000000..ca58a7a --- /dev/null +++ b/Scripts/Runtime/SerializedObject.cs @@ -0,0 +1,141 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace SteamAudio +{ + public class SerializedObject + { + IntPtr mSerializedObject = IntPtr.Zero; + IntPtr mDataBuffer = IntPtr.Zero; + + static List sAssetsToFlush = null; + + public SerializedObject(Context context) + { + var serializedObjectSettings = new SerializedObjectSettings { }; + + API.iplSerializedObjectCreate(context.Get(), ref serializedObjectSettings, out mSerializedObject); + } + + public SerializedObject(Context context, SerializedData dataAsset) + { + var data = dataAsset.data; + mDataBuffer = Marshal.AllocHGlobal(data.Length); + + Marshal.Copy(data, 0, mDataBuffer, data.Length); + + var serializedObjectSettings = new SerializedObjectSettings { }; + serializedObjectSettings.data = mDataBuffer; + serializedObjectSettings.size = (UIntPtr) data.Length; + + API.iplSerializedObjectCreate(context.Get(), ref serializedObjectSettings, out mSerializedObject); + } + + public SerializedObject(SerializedObject serializedObject) + { + mSerializedObject = API.iplSerializedObjectRetain(serializedObject.Get()); + } + + ~SerializedObject() + { + Release(); + } + + public void Release() + { + if (mDataBuffer != IntPtr.Zero) + { + Marshal.FreeHGlobal(mDataBuffer); + mDataBuffer = IntPtr.Zero; + } + + API.iplSerializedObjectRelease(ref mSerializedObject); + } + + public IntPtr Get() + { + return mSerializedObject; + } + + public UIntPtr GetSize() + { + return API.iplSerializedObjectGetSize(mSerializedObject); + } + + public IntPtr GetData() + { + return API.iplSerializedObjectGetData(mSerializedObject); + } + + public void WriteToFile(SerializedData dataAsset, bool flush = true) + { + var dataSize = GetSize(); + var dataBuffer = GetData(); + + dataAsset.data = new byte[(int) dataSize]; + Marshal.Copy(dataBuffer, dataAsset.data, 0, (int) dataSize); + + if (flush) + { + FlushWrite(dataAsset); + } + else + { + if (sAssetsToFlush == null) + { + sAssetsToFlush = new List(); + } + + sAssetsToFlush.Add(dataAsset); + } + } + + public static void FlushWrite(SerializedData dataAsset) + { +#if UNITY_EDITOR + var assetPaths = new string[1]; + assetPaths[0] = AssetDatabase.GetAssetPath(dataAsset); + + // TODO: Deprecate older versions of Unity. +#if UNITY_2017_3_OR_NEWER + AssetDatabase.ForceReserializeAssets(assetPaths); +#endif +#endif + } + + public static void FlushAllWrites() + { + if (sAssetsToFlush == null) + return; + + foreach (var dataAsset in sAssetsToFlush) + { + FlushWrite(dataAsset); + } + + sAssetsToFlush.Clear(); + } + } +} +#endif diff --git a/Scripts/Runtime/SerializedObject.cs.meta b/Scripts/Runtime/SerializedObject.cs.meta new file mode 100755 index 0000000..2dd5d41 --- /dev/null +++ b/Scripts/Runtime/SerializedObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7e71666981c49a64e98ee2cbd2726952 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/Simulator.cs b/Scripts/Runtime/Simulator.cs new file mode 100755 index 0000000..ec5e641 --- /dev/null +++ b/Scripts/Runtime/Simulator.cs @@ -0,0 +1,152 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public class Simulator + { + IntPtr mSimulator = IntPtr.Zero; + + public Simulator(Context context, SimulationSettings simulationSettings) + { + var status = API.iplSimulatorCreate(context.Get(), ref simulationSettings, out mSimulator); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create simulator. [{0}]", status)); + } + + public Simulator(Simulator simulator) + { + mSimulator = API.iplSimulatorRetain(simulator.mSimulator); + } + + ~Simulator() + { + Release(); + } + + public void Release() + { + API.iplSimulatorRelease(ref mSimulator); + } + + public IntPtr Get() + { + return mSimulator; + } + + public void SetScene(Scene scene) + { + API.iplSimulatorSetScene(mSimulator, scene.Get()); + } + + public void AddProbeBatch(ProbeBatch probeBatch) + { + API.iplSimulatorAddProbeBatch(mSimulator, probeBatch.Get()); + } + + public void RemoveProbeBatch(ProbeBatch probeBatch) + { + API.iplSimulatorRemoveProbeBatch(mSimulator, probeBatch.Get()); + } + + public void SetSharedInputs(SimulationFlags flags, SimulationSharedInputs sharedInputs) + { + API.iplSimulatorSetSharedInputs(mSimulator, flags, ref sharedInputs); + } + + public void Commit() + { + API.iplSimulatorCommit(mSimulator); + } + + public void RunDirect() + { + API.iplSimulatorRunDirect(mSimulator); + } + + public void RunReflections() + { + API.iplSimulatorRunReflections(mSimulator); + } + + public void RunPathing() + { + API.iplSimulatorRunPathing(mSimulator); + } + } + + public class Source + { + IntPtr mSource = IntPtr.Zero; + + public Source(Simulator simulator, SimulationSettings simulationSettings) + { + var sourceSettings = new SourceSettings { }; + sourceSettings.flags = simulationSettings.flags; + + var status = API.iplSourceCreate(simulator.Get(), ref sourceSettings, out mSource); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create source for simulation. [{0}]", status)); + } + + public Source(Source source) + { + mSource = API.iplSourceRetain(source.mSource); + } + + ~Source() + { + Release(); + } + + public void Release() + { + API.iplSourceRelease(ref mSource); + } + + public IntPtr Get() + { + return mSource; + } + + public void AddToSimulator(Simulator simulator) + { + API.iplSourceAdd(mSource, simulator.Get()); + } + + public void RemoveFromSimulator(Simulator simulator) + { + API.iplSourceRemove(mSource, simulator.Get()); + } + + public void SetInputs(SimulationFlags flags, SimulationInputs inputs) + { + API.iplSourceSetInputs(mSource, flags, ref inputs); + } + + public SimulationOutputs GetOutputs(SimulationFlags flags) + { + var outputs = new SimulationOutputs { }; + API.iplSourceGetOutputs(mSource, flags, ref outputs); + return outputs; + } + } +} +#endif diff --git a/Scripts/Runtime/Simulator.cs.meta b/Scripts/Runtime/Simulator.cs.meta new file mode 100755 index 0000000..a6ab91f --- /dev/null +++ b/Scripts/Runtime/Simulator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59c8ab9b6583fd541bae96e7d56ad808 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/StaticMesh.cs b/Scripts/Runtime/StaticMesh.cs new file mode 100755 index 0000000..2e2e269 --- /dev/null +++ b/Scripts/Runtime/StaticMesh.cs @@ -0,0 +1,136 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using System.Runtime.InteropServices; + +namespace SteamAudio +{ + public class StaticMesh + { + Context mContext = null; + IntPtr mStaticMesh = IntPtr.Zero; + + public StaticMesh(Context context, Scene scene, Vector3[] vertices, Triangle[] triangles, int[] materialIndices, Material[] materials) + { + mContext = context; + + var verticesBuffer = Marshal.AllocHGlobal(vertices.Length * Marshal.SizeOf(typeof(Vector3))); + var trianglesBuffer = Marshal.AllocHGlobal(triangles.Length * Marshal.SizeOf(typeof(Triangle))); + var materialIndicesBuffer = Marshal.AllocHGlobal(materialIndices.Length * Marshal.SizeOf(typeof(int))); + var materialsBuffer = Marshal.AllocHGlobal(materials.Length * Marshal.SizeOf(typeof(Material))); + + for (var i = 0; i < vertices.Length; ++i) + { + Marshal.StructureToPtr(vertices[i], new IntPtr(verticesBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Vector3))), false); + } + + for (var i = 0; i < triangles.Length; ++i) + { + Marshal.StructureToPtr(triangles[i], new IntPtr(trianglesBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Triangle))), false); + } + + Marshal.Copy(materialIndices, 0, materialIndicesBuffer, triangles.Length); + + for (var i = 0; i < materials.Length; ++i) + { + Marshal.StructureToPtr(materials[i], new IntPtr(materialsBuffer.ToInt64() + i * Marshal.SizeOf(typeof(Material))), false); + } + + var staticMeshSettings = new StaticMeshSettings { }; + staticMeshSettings.numVertices = vertices.Length; + staticMeshSettings.numTriangles = triangles.Length; + staticMeshSettings.numMaterials = materials.Length; + staticMeshSettings.vertices = verticesBuffer; + staticMeshSettings.triangles = trianglesBuffer; + staticMeshSettings.materialIndices = materialIndicesBuffer; + staticMeshSettings.materials = materialsBuffer; + + var status = API.iplStaticMeshCreate(scene.Get(), ref staticMeshSettings, out mStaticMesh); + if (status != Error.Success) + { + throw new Exception(string.Format("Unable to create static mesh for export ({0} vertices, {1} triangles, {2} materials): [{3}]", + staticMeshSettings.numVertices.ToString(), staticMeshSettings.numTriangles.ToString(), staticMeshSettings.numMaterials.ToString(), + status.ToString())); + } + + Marshal.FreeHGlobal(verticesBuffer); + Marshal.FreeHGlobal(trianglesBuffer); + Marshal.FreeHGlobal(materialIndicesBuffer); + Marshal.FreeHGlobal(materialsBuffer); + } + + public StaticMesh(Context context, Scene scene, SerializedData dataAsset) + { + mContext = context; + + var serializedObject = new SerializedObject(context, dataAsset); + + var status = API.iplStaticMeshLoad(scene.Get(), serializedObject.Get(), null, IntPtr.Zero, out mStaticMesh); + if (status != Error.Success) + throw new Exception(string.Format("Unable to load static mesh ({0}). [{1}]", dataAsset.name, status)); + + serializedObject.Release(); + } + + public StaticMesh(StaticMesh staticMesh) + { + mContext = staticMesh.mContext; + + mStaticMesh = API.iplStaticMeshRetain(staticMesh.mStaticMesh); + } + + ~StaticMesh() + { + Release(); + } + + public void Release() + { + API.iplStaticMeshRelease(ref mStaticMesh); + + mContext = null; + } + + public IntPtr Get() + { + return mStaticMesh; + } + + public void Save(SerializedData dataAsset) + { + var serializedObject = new SerializedObject(mContext); + API.iplStaticMeshSave(mStaticMesh, serializedObject.Get()); + serializedObject.WriteToFile(dataAsset); + serializedObject.Release(); + } + + public void AddToScene(Scene scene) + { + API.iplStaticMeshAdd(mStaticMesh, scene.Get()); + scene.NotifyAddObject(); + } + + public void RemoveFromScene(Scene scene) + { + API.iplStaticMeshRemove(mStaticMesh, scene.Get()); + scene.NotifyRemoveObject(); + } + } +} + +#endif diff --git a/Scripts/Runtime/StaticMesh.cs.meta b/Scripts/Runtime/StaticMesh.cs.meta new file mode 100755 index 0000000..e1177e1 --- /dev/null +++ b/Scripts/Runtime/StaticMesh.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 426a41fdb5d8b904fb4b688ed1b1db02 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudio.cs b/Scripts/Runtime/SteamAudio.cs new file mode 100755 index 0000000..2cedafa --- /dev/null +++ b/Scripts/Runtime/SteamAudio.cs @@ -0,0 +1,1372 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Runtime.InteropServices; +using UnityEngine; + +namespace SteamAudio +{ + // CONSTANTS + + public static class Constants + { + public const uint kVersionMajor = 4; + public const uint kVersionMinor = 5; + public const uint kVersionPatch = 1; + public const uint kVersion = (kVersionMajor << 16) | (kVersionMinor << 8) | kVersionPatch; + } + + // ENUMERATIONS + + public enum Bool + { + False, + True + } + + public enum Error + { + Success, + Failure, + OutOfMemory, + Initialization + } + + public enum LogLevel + { + Info, + Warning, + Error, + Debug + } + + public enum SIMDLevel + { + SSE2, + SSE4, + AVX, + AVX2, + AVX512, + NEON = SSE2 + } + + [Flags] + public enum ContextFlags + { + Validation = 1 << 0, + Force32Bit = 0x7fffffff + } + + public enum OpenCLDeviceType + { + Any, + CPU, + GPU + } + + public enum SceneType + { + Default, + Embree, + RadeonRays, +#if UNITY_2019_2_OR_NEWER + [InspectorName("Unity")] +#endif + Custom + } + + public enum HRTFType + { + Default, + SOFA + } + + public enum HRTFNormType + { + None, + RMS + } + + public enum ProbeGenerationType + { + Centroid, + UniformFloor + } + + public enum BakedDataVariation + { + Reverb, + StaticSource, + StaticListener, + Dynamic + } + + public enum BakedDataType + { + Reflections, + Pathing + } + + [Flags] + public enum SimulationFlags + { + Direct = 1 << 0, + Reflections = 1 << 1, + Pathing = 1 << 2 + } + + [Flags] + public enum DirectSimulationFlags + { + DistanceAttenuation = 1 << 0, + AirAbsorption = 1 << 1, + Directivity = 1 << 2, + Occlusion = 1 << 3, + Transmission = 1 << 4 + } + + public enum HRTFInterpolation + { + Nearest, + Bilinear + } + + public enum DistanceAttenuationModelType + { + Default, + InverseDistance, + Callback + } + + public enum AirAbsorptionModelType + { + Default, + Exponential, + Callback + } + + public enum OcclusionType + { + Raycast, + Volumetric + } + + [Flags] + public enum DirectEffectFlags + { + ApplyDistanceAttenuation = 1 << 0, + ApplyAirAbsorption = 1 << 1, + ApplyDirectivity = 1 << 2, + ApplyOcclusion = 1 << 3, + ApplyTransmission = 1 << 4 + } + + public enum TransmissionType + { + FrequencyIndependent, + FrequencyDependent + } + + public enum ReflectionEffectType + { + Convolution, + Parametric, + Hybrid, +#if UNITY_2019_2_OR_NEWER + [InspectorName("TrueAudio Next")] +#endif + TrueAudioNext + } + + [Flags] + public enum ReflectionsBakeFlags + { + BakeConvolution = 1 << 0, + BakeParametric = 1 << 1 + } + + // CALLBACKS + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void ProgressCallback(float progress, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void LogCallback(LogLevel level, string message); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate IntPtr AllocateCallback(UIntPtr size, UIntPtr alignment); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void FreeCallback(IntPtr memoryBlock); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void ClosestHitCallback(ref Ray ray, float minDistance, float maxDistance, out Hit hit, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void AnyHitCallback(ref Ray ray, float minDistance, float maxDistance, out byte occluded, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void BatchedClosestHitCallback(int numRays, Ray[] rays, float[] minDistances, float[] maxDistances, [Out] Hit[] hits, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void BatchedAnyHitCallback(int numRays, Ray[] rays, float[] minDistances, float[] maxDistances, [Out] byte[] occluded, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate float DistanceAttenuationCallback(float distance, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate float AirAbsorptionCallback(float distance, int band, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate float DirectivityCallback(Vector3 direction, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + public delegate void PathingVisualizationCallback(Vector3 from, Vector3 to, Bool occluded, IntPtr userData); + + // STRUCTURES + + [StructLayout(LayoutKind.Sequential)] + public struct ContextSettings + { + public uint version; + public LogCallback logCallback; + public AllocateCallback allocateCallback; + public FreeCallback freeCallback; + public SIMDLevel simdLevel; + public ContextFlags flags; + } + + [Serializable] + [StructLayout(LayoutKind.Sequential)] + public struct Vector3 + { + public float x; + public float y; + public float z; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Matrix4x4 + { + public float m00; + public float m01; + public float m02; + public float m03; + public float m10; + public float m11; + public float m12; + public float m13; + public float m20; + public float m21; + public float m22; + public float m23; + public float m30; + public float m31; + public float m32; + public float m33; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Box + { + public Vector3 minCoordinates; + public Vector3 maxCoordinates; + } + + [Serializable] + [StructLayout(LayoutKind.Sequential)] + public struct Sphere + { + public Vector3 center; + public float radius; + } + + [StructLayout(LayoutKind.Sequential)] + public struct CoordinateSpace3 + { + public Vector3 right; + public Vector3 up; + public Vector3 ahead; + public Vector3 origin; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SerializedObjectSettings + { + public IntPtr data; + public UIntPtr size; + } + + [StructLayout(LayoutKind.Sequential)] + public struct EmbreeDeviceSettings { } + + [StructLayout(LayoutKind.Sequential)] + public struct OpenCLDeviceSettings + { + public OpenCLDeviceType type; + public int numCUsToReserve; + public float fractionCUsForIRUpdate; + public Bool requiresTAN; + } + + [StructLayout(LayoutKind.Sequential)] + public struct OpenCLDeviceDesc + { + public IntPtr platform; + public string platformName; + public string platformVendor; + public string platformVersion; + public IntPtr device; + public string deviceName; + public string deviceVendor; + public string deviceVersion; + public OpenCLDeviceType type; + public int numConvolutionCUs; + public int numIRUpdateCUs; + public int granularity; + public float perfScore; + } + + [StructLayout(LayoutKind.Sequential)] + public struct RadeonRaysDeviceSettings { } + + [StructLayout(LayoutKind.Sequential)] + public struct TrueAudioNextDeviceSettings + { + public int frameSize; + public int irSize; + public int order; + public int maxSources; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Triangle + { + public int index0; + public int index1; + public int index2; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Material + { + public float absorptionLow; + public float absorptionMid; + public float absorptionHigh; + public float scattering; + public float transmissionLow; + public float transmissionMid; + public float transmissionHigh; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Ray + { + public Vector3 origin; + public Vector3 direction; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Hit + { + public float distance; + public int triangleIndex; + public int objectIndex; + public int materialIndex; + public Vector3 normal; + public IntPtr material; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SceneSettings + { + public SceneType type; + public ClosestHitCallback closestHitCallback; + public AnyHitCallback anyHitCallback; + public BatchedClosestHitCallback batchedClosestHitCallback; + public BatchedAnyHitCallback batchedAnyHitCallback; + public IntPtr userData; + public IntPtr embreeDevice; + public IntPtr radeonRaysDevice; + } + + [StructLayout(LayoutKind.Sequential)] + public struct StaticMeshSettings + { + public int numVertices; + public int numTriangles; + public int numMaterials; + public IntPtr vertices; + public IntPtr triangles; + public IntPtr materialIndices; + public IntPtr materials; + } + + [StructLayout(LayoutKind.Sequential)] + public struct InstancedMeshSettings + { + public IntPtr subScene; + public Matrix4x4 transform; + } + + [StructLayout(LayoutKind.Sequential)] + public struct AudioSettings + { + public int samplingRate; + public int frameSize; + } + + [StructLayout(LayoutKind.Sequential)] + public struct HRTFSettings + { + public HRTFType type; + public string sofaFileName; + public IntPtr sofaFileData; + public int sofaFileDataSize; + public float volume; + public HRTFNormType normType; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ProbeGenerationParams + { + public ProbeGenerationType type; + public float spacing; + public float height; + public Matrix4x4 transform; + } + + [StructLayout(LayoutKind.Sequential)] + [Serializable] + public struct BakedDataIdentifier + { + public BakedDataType type; + public BakedDataVariation variation; + public Sphere endpointInfluence; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ReflectionsBakeParams + { + public IntPtr scene; + public IntPtr probeBatch; + public SceneType sceneType; + public BakedDataIdentifier identifier; + public ReflectionsBakeFlags flags; + public int numRays; + public int numDiffuseSamples; + public int numBounces; + public float simulatedDuration; + public float savedDuration; + public int order; + public int numThreads; + public int rayBatchSize; + public float irradianceMinDistance; + public int bakeBatchSize; + public IntPtr openCLDevice; + public IntPtr radeonRaysDevice; + } + + [StructLayout(LayoutKind.Sequential)] + public struct PathBakeParams + { + public IntPtr scene; + public IntPtr probeBatch; + public BakedDataIdentifier identifier; + public int numSamples; + public float radius; + public float threshold; + public float visRange; + public float pathRange; + public int numThreads; + } + + [StructLayout(LayoutKind.Sequential)] + public struct DistanceAttenuationModel + { + public DistanceAttenuationModelType type; + public float minDistance; + public DistanceAttenuationCallback callback; + public IntPtr userData; + public Bool dirty; + } + + [StructLayout(LayoutKind.Sequential)] + public struct AirAbsorptionModel + { + public AirAbsorptionModelType type; + public float coefficientsLow; + public float coefficientsMid; + public float coefficientsHigh; + public AirAbsorptionCallback callback; + public IntPtr userData; + public Bool dirty; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Directivity + { + public float dipoleWeight; + public float dipolePower; + public DirectivityCallback callback; + public IntPtr userData; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SimulationSettings + { + public SimulationFlags flags; + public SceneType sceneType; + public ReflectionEffectType reflectionType; + public int maxNumOcclusionSamples; + public int maxNumRays; + public int numDiffuseSamples; + public float maxDuration; + public int maxOrder; + public int maxNumSources; + public int numThreads; + public int rayBatchSize; + public int numVisSamples; + public int samplingRate; + public int frameSize; + public IntPtr openCLDevice; + public IntPtr radeonRaysDevice; + public IntPtr tanDevice; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SourceSettings + { + public SimulationFlags flags; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SimulationInputs + { + public SimulationFlags flags; + public DirectSimulationFlags directFlags; + public CoordinateSpace3 source; + public DistanceAttenuationModel distanceAttenuationModel; + public AirAbsorptionModel airAbsorptionModel; + public Directivity directivity; + public OcclusionType occlusionType; + public float occlusionRadius; + public int numOcclusionSamples; + public float reverbScaleLow; + public float reverbScaleMid; + public float reverbScaleHigh; + public float hybridReverbTransitionTime; + public float hybridReverbOverlapPercent; + public Bool baked; + public BakedDataIdentifier bakedDataIdentifier; + public IntPtr pathingProbes; + public float visRadius; + public float visThreshold; + public float visRange; + public int pathingOrder; + public Bool enableValidation; + public Bool findAlternatePaths; + public int numTransmissionRays; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SimulationSharedInputs + { + public CoordinateSpace3 listener; + public int numRays; + public int numBounces; + public float duration; + public int order; + public float irradianceMinDistance; + public PathingVisualizationCallback pathingVisualizationCallback; + public IntPtr pathingUserData; + } + + [StructLayout(LayoutKind.Sequential)] + public struct DirectEffectParams + { + public DirectEffectFlags flags; + public TransmissionType transmissionType; + public float distanceAttenuation; + public float airAbsorptionLow; + public float airAbsorptionMid; + public float airAbsorptionHigh; + public float directivity; + public float occlusion; + public float transmissionLow; + public float transmissionMid; + public float transmissionHigh; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ReflectionEffectParams + { + public ReflectionEffectType type; + public IntPtr ir; + public float reverbTimesLow; + public float reverbTimesMid; + public float reverbTimesHigh; + public float eqLow; + public float eqMid; + public float eqHigh; + public int delay; + public int numChannels; + public int irSize; + public IntPtr tanDevice; + public int tanSlot; + } + + [StructLayout(LayoutKind.Sequential)] + public struct PathEffectParams + { + public float eqCoeffsLow; + public float eqCoeffsMid; + public float eqCoeffsHigh; + public IntPtr shCoeffs; + public int order; + public Bool binaural; + public IntPtr hrtf; + public CoordinateSpace3 listener; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SimulationOutputs + { + public DirectEffectParams direct; + public ReflectionEffectParams reflections; + public PathEffectParams pathing; + } + + [StructLayout(LayoutKind.Sequential)] + public struct PerspectiveCorrection + { + public Bool enabled; + public float xfactor; + public float yfactor; + public Matrix4x4 transform; + } + + // FUNCTIONS + + public static class API + { + // Context + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplContextCreate(ref ContextSettings settings, out IntPtr context); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplContextRetain(IntPtr context); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplContextRelease(ref IntPtr context); + + // Geometry + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Vector3 iplCalculateRelativeDirection(IntPtr context, Vector3 sourcePosition, Vector3 listenerPosition, Vector3 listenerAhead, Vector3 listenerUp); + + // Serialization + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplSerializedObjectCreate(IntPtr context, ref SerializedObjectSettings settings, out IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplSerializedObjectRetain(IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSerializedObjectRelease(ref IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern UIntPtr iplSerializedObjectGetSize(IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplSerializedObjectGetData(IntPtr serializedObject); + + // Embree + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplEmbreeDeviceCreate(IntPtr context, ref EmbreeDeviceSettings settings, out IntPtr device); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplEmbreeDeviceRetain(IntPtr device); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplEmbreeDeviceRelease(ref IntPtr device); + + // OpenCL + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplOpenCLDeviceListCreate(IntPtr context, ref OpenCLDeviceSettings settings, out IntPtr deviceList); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplOpenCLDeviceListRetain(IntPtr deviceList); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplOpenCLDeviceListRelease(ref IntPtr deviceList); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern int iplOpenCLDeviceListGetNumDevices(IntPtr deviceList); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplOpenCLDeviceListGetDeviceDesc(IntPtr deviceList, int index, out OpenCLDeviceDesc deviceDesc); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplOpenCLDeviceCreate(IntPtr context, IntPtr deviceList, int index, out IntPtr device); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplOpenCLDeviceRetain(IntPtr device); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplOpenCLDeviceRelease(ref IntPtr device); + + // Radeon Rays + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplRadeonRaysDeviceCreate(IntPtr openCLDevice, ref RadeonRaysDeviceSettings settings, out IntPtr rrDevice); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplRadeonRaysDeviceRetain(IntPtr device); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplRadeonRaysDeviceRelease(ref IntPtr device); + + // TrueAudio Next + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplTrueAudioNextDeviceCreate(IntPtr openCLDevice, ref TrueAudioNextDeviceSettings settings, out IntPtr tanDevice); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplTrueAudioNextDeviceRetain(IntPtr device); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplTrueAudioNextDeviceRelease(ref IntPtr device); + + // Scene + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplSceneCreate(IntPtr context, ref SceneSettings settings, out IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplSceneRetain(IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSceneRelease(ref IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplSceneLoad(IntPtr context, ref SceneSettings settings, IntPtr serializedObject, ProgressCallback progressCallback, IntPtr progressCallbackUserData, out IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSceneSave(IntPtr scene, IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSceneSaveOBJ(IntPtr scene, string fileBaseName); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSceneCommit(IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplStaticMeshCreate(IntPtr scene, ref StaticMeshSettings settings, out IntPtr staticMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplStaticMeshRetain(IntPtr staticMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplStaticMeshRelease(ref IntPtr staticMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplStaticMeshLoad(IntPtr scene, IntPtr serializedObject, ProgressCallback progressCallback, IntPtr progressCallbackUserData, out IntPtr staticMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplStaticMeshSave(IntPtr staticMesh, IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplStaticMeshAdd(IntPtr staticMesh, IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplStaticMeshRemove(IntPtr staticMesh, IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplInstancedMeshCreate(IntPtr scene, ref InstancedMeshSettings settings, out IntPtr instancedMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplInstancedMeshRetain(IntPtr instancedMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplInstancedMeshRelease(ref IntPtr instancedMesh); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplInstancedMeshAdd(IntPtr instancedMesh, IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplInstancedMeshRemove(IntPtr instancedMesh, IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplInstancedMeshUpdateTransform(IntPtr instancedMesh, IntPtr scene, Matrix4x4 transform); + + // HRTF + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplHRTFCreate(IntPtr context, ref AudioSettings audioSettings, ref HRTFSettings hrtfSettings, out IntPtr hrtf); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplHRTFRetain(IntPtr hrtf); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplHRTFRelease(ref IntPtr hrtf); + + // Probes + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplProbeArrayCreate(IntPtr context, out IntPtr probeArray); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplProbeArrayRetain(IntPtr probeArray); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeArrayRelease(ref IntPtr probeArray); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeArrayGenerateProbes(IntPtr probeArray, IntPtr scene, ref ProbeGenerationParams generationParams); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern int iplProbeArrayGetNumProbes(IntPtr probeArray); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Sphere iplProbeArrayGetProbe(IntPtr probeArray, int index); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplProbeBatchCreate(IntPtr context, out IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplProbeBatchRetain(IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchRelease(ref IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplProbeBatchLoad(IntPtr context, IntPtr serializedObject, out IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchSave(IntPtr probeBatch, IntPtr serializedObject); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern int iplProbeBatchGetNumProbes(IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchAddProbe(IntPtr probeBatch, Sphere probe); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchAddProbeArray(IntPtr probeBatch, IntPtr probeArray); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchRemoveProbe(IntPtr probeBatch, int index); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchCommit(IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplProbeBatchRemoveData(IntPtr probeBatch, ref BakedDataIdentifier identifier); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern UIntPtr iplProbeBatchGetDataSize(IntPtr probeBatch, ref BakedDataIdentifier identifier); + + // Baking + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplReflectionsBakerBake(IntPtr context, ref ReflectionsBakeParams bakeParams, ProgressCallback progressCallback, IntPtr userData); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplReflectionsBakerCancelBake(IntPtr context); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplPathBakerBake(IntPtr context, ref PathBakeParams bakeParams, ProgressCallback progressCallback, IntPtr userData); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplPathBakerCancelBake(IntPtr context); + + // Run-Time Simulation + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplSimulatorCreate(IntPtr context, ref SimulationSettings settings, out IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplSimulatorRetain(IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorRelease(ref IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorSetScene(IntPtr simulator, IntPtr scene); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorAddProbeBatch(IntPtr simulator, IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorRemoveProbeBatch(IntPtr simulator, IntPtr probeBatch); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorSetSharedInputs(IntPtr simulator, SimulationFlags flags, ref SimulationSharedInputs sharedInputs); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorCommit(IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorRunDirect(IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorRunReflections(IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSimulatorRunPathing(IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern Error iplSourceCreate(IntPtr simulator, ref SourceSettings settings, out IntPtr source); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern IntPtr iplSourceRetain(IntPtr source); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSourceRelease(ref IntPtr source); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSourceAdd(IntPtr source, IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSourceRemove(IntPtr source, IntPtr simulator); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSourceSetInputs(IntPtr source, SimulationFlags flags, ref SimulationInputs inputs); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon")] +#endif + public static extern void iplSourceGetOutputs(IntPtr source, SimulationFlags flags, ref SimulationOutputs outputs); + + // UNITY PLUGIN + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnityInitialize(IntPtr context); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnitySetPerspectiveCorrection(PerspectiveCorrection correction); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnitySetHRTF(IntPtr hrtf); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnitySetSimulationSettings(SimulationSettings simulationSettings); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnitySetReverbSource(IntPtr reverbSource); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern int iplUnityAddSource(IntPtr source); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnityRemoveSource(int handle); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("audioplugin_phonon")] +#endif + public static extern void iplUnityTerminate(); + } +} diff --git a/Scripts/Runtime/SteamAudio.cs.meta b/Scripts/Runtime/SteamAudio.cs.meta new file mode 100755 index 0000000..658044f --- /dev/null +++ b/Scripts/Runtime/SteamAudio.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: faab0996f33b3304faccb7f9f8c48dc9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioAmbisonicSource.cs b/Scripts/Runtime/SteamAudioAmbisonicSource.cs new file mode 100755 index 0000000..f3018b3 --- /dev/null +++ b/Scripts/Runtime/SteamAudioAmbisonicSource.cs @@ -0,0 +1,74 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + [AddComponentMenu("Steam Audio/Steam Audio Ambisonic Source")] + [RequireComponent(typeof(AudioSource))] + public class SteamAudioAmbisonicSource : MonoBehaviour + { + [Header("HRTF Settings")] + public bool applyHRTF = true; + + AudioEngineAmbisonicSource mAudioEngineAmbisonicSource = null; + + private void Awake() + { + mAudioEngineAmbisonicSource = AudioEngineAmbisonicSource.Create(SteamAudioSettings.Singleton.audioEngine); + if (mAudioEngineAmbisonicSource != null) + { + mAudioEngineAmbisonicSource.Initialize(gameObject); + mAudioEngineAmbisonicSource.UpdateParameters(this); + } + } + + private void Start() + { + if (mAudioEngineAmbisonicSource != null) + { + mAudioEngineAmbisonicSource.UpdateParameters(this); + } + } + + private void OnDestroy() + { + if (mAudioEngineAmbisonicSource != null) + { + mAudioEngineAmbisonicSource.Destroy(); + } + } + + private void OnEnable() + { + if (mAudioEngineAmbisonicSource != null) + { + mAudioEngineAmbisonicSource.UpdateParameters(this); + } + } + + private void Update() + { + if (mAudioEngineAmbisonicSource != null) + { + mAudioEngineAmbisonicSource.UpdateParameters(this); + } + } + + } +} diff --git a/Scripts/Runtime/SteamAudioAmbisonicSource.cs.meta b/Scripts/Runtime/SteamAudioAmbisonicSource.cs.meta new file mode 100755 index 0000000..dfbdb1d --- /dev/null +++ b/Scripts/Runtime/SteamAudioAmbisonicSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fe05866fd4e732246be6461a576ebcb0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioBakedListener.cs b/Scripts/Runtime/SteamAudioBakedListener.cs new file mode 100755 index 0000000..dd797c0 --- /dev/null +++ b/Scripts/Runtime/SteamAudioBakedListener.cs @@ -0,0 +1,150 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + [AddComponentMenu("Steam Audio/Steam Audio Baked Listener")] + public class SteamAudioBakedListener : MonoBehaviour + { + [Header("Baked Static Listener Settings")] + [Range(0.0f, 1000.0f)] + public float influenceRadius = 1000.0f; + public bool useAllProbeBatches = false; + public SteamAudioProbeBatch[] probeBatches = null; + + [SerializeField] + int mTotalDataSize = 0; + [SerializeField] + int[] mProbeDataSizes = null; + [SerializeField] + BakedDataIdentifier mIdentifier = new BakedDataIdentifier { }; + [SerializeField] + SteamAudioProbeBatch[] mProbeBatchesUsed = null; + +#if STEAMAUDIO_ENABLED + public int GetTotalDataSize() + { + return mTotalDataSize; + } + + public int[] GetProbeDataSizes() + { + return mProbeDataSizes; + } + + public int GetSizeForProbeBatch(int index) + { + return mProbeDataSizes[index]; + } + + public SteamAudioProbeBatch[] GetProbeBatchesUsed() + { + if (mProbeBatchesUsed == null) + { + CacheProbeBatchesUsed(); + } + + return mProbeBatchesUsed; + } + + public BakedDataIdentifier GetBakedDataIdentifier() + { + var identifier = new BakedDataIdentifier { }; + identifier.type = BakedDataType.Reflections; + identifier.variation = BakedDataVariation.StaticListener; + identifier.endpointInfluence.center = Common.ConvertVector(transform.position); + identifier.endpointInfluence.radius = influenceRadius; + return identifier; + } + + private void OnDrawGizmosSelected() + { + var oldColor = Gizmos.color; + var oldMatrix = Gizmos.matrix; + + Gizmos.color = Color.yellow; + Gizmos.DrawWireSphere(transform.position, influenceRadius); + + Gizmos.color = Color.magenta; + + if (mProbeBatchesUsed != null) + { + foreach (var probeBatch in mProbeBatchesUsed) + { + if (probeBatch == null) + continue; + + Gizmos.matrix = probeBatch.transform.localToWorldMatrix; + Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1)); + } + } + + Gizmos.matrix = oldMatrix; + Gizmos.color = oldColor; + } + + public void UpdateBakedDataStatistics() + { + if (mProbeBatchesUsed == null) + return; + + mProbeDataSizes = new int[mProbeBatchesUsed.Length]; + mTotalDataSize = 0; + + for (var i = 0; i < mProbeBatchesUsed.Length; ++i) + { + mProbeDataSizes[i] = mProbeBatchesUsed[i].GetSizeForLayer(mIdentifier); + mTotalDataSize += mProbeDataSizes[i]; + } + } + + public void BeginBake() + { + CacheIdentifier(); + CacheProbeBatchesUsed(); + + var tasks = new BakedDataTask[1]; + tasks[0].gameObject = gameObject; + tasks[0].component = this; + tasks[0].name = gameObject.name; + tasks[0].identifier = mIdentifier; + tasks[0].probeBatches = (useAllProbeBatches) ? FindObjectsOfType() : probeBatches; + tasks[0].probeBatchNames = new string[tasks[0].probeBatches.Length]; + tasks[0].probeBatchAssets = new SerializedData[tasks[0].probeBatches.Length]; + for (var i = 0; i < tasks[0].probeBatchNames.Length; ++i) + { + tasks[0].probeBatchNames[i] = tasks[0].probeBatches[i].gameObject.name; + tasks[0].probeBatchAssets[i] = tasks[0].probeBatches[i].GetAsset(); + } + + Baker.BeginBake(tasks); + } + + void CacheIdentifier() + { + mIdentifier = GetBakedDataIdentifier(); + } + + void CacheProbeBatchesUsed() + { + mProbeBatchesUsed = (useAllProbeBatches) ? FindObjectsOfType() : probeBatches; + } +#endif + } +} \ No newline at end of file diff --git a/Scripts/Runtime/SteamAudioBakedListener.cs.meta b/Scripts/Runtime/SteamAudioBakedListener.cs.meta new file mode 100755 index 0000000..b6e68fb --- /dev/null +++ b/Scripts/Runtime/SteamAudioBakedListener.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d1a2bdfdee8e5b48a9949c674b73640 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioBakedSource.cs b/Scripts/Runtime/SteamAudioBakedSource.cs new file mode 100755 index 0000000..8b0f38a --- /dev/null +++ b/Scripts/Runtime/SteamAudioBakedSource.cs @@ -0,0 +1,150 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + [AddComponentMenu("Steam Audio/Steam Audio Baked Source")] + public class SteamAudioBakedSource : MonoBehaviour + { + [Header("Baked Static Source Settings")] + [Range(0.0f, 1000.0f)] + public float influenceRadius = 1000.0f; + public bool useAllProbeBatches = false; + public SteamAudioProbeBatch[] probeBatches = null; + + [SerializeField] + int mTotalDataSize = 0; + [SerializeField] + int[] mProbeDataSizes = null; + [SerializeField] + BakedDataIdentifier mIdentifier = new BakedDataIdentifier { }; + [SerializeField] + SteamAudioProbeBatch[] mProbeBatchesUsed = null; + +#if STEAMAUDIO_ENABLED + public int GetTotalDataSize() + { + return mTotalDataSize; + } + + public int[] GetProbeDataSizes() + { + return mProbeDataSizes; + } + + public int GetSizeForProbeBatch(int index) + { + return mProbeDataSizes[index]; + } + + public SteamAudioProbeBatch[] GetProbeBatchesUsed() + { + if (mProbeBatchesUsed == null) + { + CacheProbeBatchesUsed(); + } + + return mProbeBatchesUsed; + } + + public BakedDataIdentifier GetBakedDataIdentifier() + { + var identifier = new BakedDataIdentifier { }; + identifier.type = BakedDataType.Reflections; + identifier.variation = BakedDataVariation.StaticSource; + identifier.endpointInfluence.center = Common.ConvertVector(transform.position); + identifier.endpointInfluence.radius = influenceRadius; + return identifier; + } + + private void OnDrawGizmosSelected() + { + var oldColor = Gizmos.color; + var oldMatrix = Gizmos.matrix; + + Gizmos.color = Color.yellow; + Gizmos.DrawWireSphere(transform.position, influenceRadius); + + Gizmos.color = Color.magenta; + + if (mProbeBatchesUsed != null) + { + foreach (var probeBatch in mProbeBatchesUsed) + { + if (probeBatch == null) + continue; + + Gizmos.matrix = probeBatch.transform.localToWorldMatrix; + Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1)); + } + } + + Gizmos.matrix = oldMatrix; + Gizmos.color = oldColor; + } + + public void UpdateBakedDataStatistics() + { + if (mProbeBatchesUsed == null) + return; + + mProbeDataSizes = new int[mProbeBatchesUsed.Length]; + mTotalDataSize = 0; + + for (var i = 0; i < mProbeBatchesUsed.Length; ++i) + { + mProbeDataSizes[i] = mProbeBatchesUsed[i].GetSizeForLayer(mIdentifier); + mTotalDataSize += mProbeDataSizes[i]; + } + } + + public void BeginBake() + { + CacheIdentifier(); + CacheProbeBatchesUsed(); + + var tasks = new BakedDataTask[1]; + tasks[0].gameObject = gameObject; + tasks[0].component = this; + tasks[0].name = gameObject.name; + tasks[0].identifier = mIdentifier; + tasks[0].probeBatches = (useAllProbeBatches) ? FindObjectsOfType() : probeBatches; + tasks[0].probeBatchNames = new string[tasks[0].probeBatches.Length]; + tasks[0].probeBatchAssets = new SerializedData[tasks[0].probeBatches.Length]; + for (var i = 0; i < tasks[0].probeBatchNames.Length; ++i) + { + tasks[0].probeBatchNames[i] = tasks[0].probeBatches[i].gameObject.name; + tasks[0].probeBatchAssets[i] = tasks[0].probeBatches[i].GetAsset(); + } + + Baker.BeginBake(tasks); + } + + void CacheIdentifier() + { + mIdentifier = GetBakedDataIdentifier(); + } + + void CacheProbeBatchesUsed() + { + mProbeBatchesUsed = (useAllProbeBatches) ? FindObjectsOfType() : probeBatches; + } +#endif + } +} \ No newline at end of file diff --git a/Scripts/Runtime/SteamAudioBakedSource.cs.meta b/Scripts/Runtime/SteamAudioBakedSource.cs.meta new file mode 100755 index 0000000..4ceb9e4 --- /dev/null +++ b/Scripts/Runtime/SteamAudioBakedSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8ea378497d2d9e847898c57b9eb3fb94 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioDynamicObject.cs b/Scripts/Runtime/SteamAudioDynamicObject.cs new file mode 100755 index 0000000..b4cd741 --- /dev/null +++ b/Scripts/Runtime/SteamAudioDynamicObject.cs @@ -0,0 +1,82 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + [AddComponentMenu("Steam Audio/Steam Audio Dynamic Object")] + public class SteamAudioDynamicObject : MonoBehaviour + { + [Header("Export Settings")] + public SerializedData asset = null; + +#if STEAMAUDIO_ENABLED + InstancedMesh mInstancedMesh = null; + + private void OnDestroy() + { + SteamAudioManager.UnloadDynamicObject(this); + + if (mInstancedMesh != null) + { + mInstancedMesh.Release(); + } + } + + private void OnEnable() + { + if (mInstancedMesh != null) + { + mInstancedMesh.AddToScene(SteamAudioManager.CurrentScene); + SteamAudioManager.ScheduleCommitScene(); + } + } + + private void OnDisable() + { + if (mInstancedMesh != null && SteamAudioManager.CurrentScene != null) + { + mInstancedMesh.RemoveFromScene(SteamAudioManager.CurrentScene); + SteamAudioManager.ScheduleCommitScene(); + } + } + + private void Update() + { + if (mInstancedMesh == null && asset != null) + { + mInstancedMesh = SteamAudioManager.LoadDynamicObject(this, SteamAudioManager.CurrentScene, SteamAudioManager.Context); + + if (enabled) + { + mInstancedMesh.AddToScene(SteamAudioManager.CurrentScene); + SteamAudioManager.ScheduleCommitScene(); + } + } + + // Only update the dynamic object if it has actually move this frame + if (transform.hasChanged) + { + mInstancedMesh.UpdateTransform(SteamAudioManager.CurrentScene, transform); + SteamAudioManager.ScheduleCommitScene(); + transform.hasChanged = false; + } + } +#endif + } +} diff --git a/Scripts/Runtime/SteamAudioDynamicObject.cs.meta b/Scripts/Runtime/SteamAudioDynamicObject.cs.meta new file mode 100755 index 0000000..0c5efd8 --- /dev/null +++ b/Scripts/Runtime/SteamAudioDynamicObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2fb43d10a308b2f46ad4561774f97e52 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioFMODStudio.cs b/Scripts/Runtime/SteamAudioFMODStudio.cs new file mode 100755 index 0000000..573876f --- /dev/null +++ b/Scripts/Runtime/SteamAudioFMODStudio.cs @@ -0,0 +1,76 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Runtime.InteropServices; +using UnityEngine; + +namespace SteamAudio +{ + public static class FMODStudioAPI + { + // FMOD STUDIO PLUGIN + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODInitialize(IntPtr context); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODSetHRTF(IntPtr hrtf); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODSetSimulationSettings(SimulationSettings simulationSettings); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODSetReverbSource(IntPtr reverbSource); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODTerminate(); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern int iplFMODAddSource(IntPtr source); + +#if UNITY_IOS && !UNITY_EDITOR + [DllImport("__Internal")] +#else + [DllImport("phonon_fmod")] +#endif + public static extern void iplFMODRemoveSource(int handle); + } +} diff --git a/Scripts/Runtime/SteamAudioFMODStudio.cs.meta b/Scripts/Runtime/SteamAudioFMODStudio.cs.meta new file mode 100755 index 0000000..36cb887 --- /dev/null +++ b/Scripts/Runtime/SteamAudioFMODStudio.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 910b4010d4f5f4c388938e56f9715f37 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioGeometry.cs b/Scripts/Runtime/SteamAudioGeometry.cs new file mode 100755 index 0000000..9fe63c0 --- /dev/null +++ b/Scripts/Runtime/SteamAudioGeometry.cs @@ -0,0 +1,74 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; + +namespace SteamAudio +{ + [AddComponentMenu("Steam Audio/Steam Audio Geometry")] + public class SteamAudioGeometry : MonoBehaviour + { + [Header("Material Settings")] + public SteamAudioMaterial material = null; + [Header("Export Settings")] + public bool exportAllChildren = false; + [Header("Terrain Settings")] + [Range(0, 10)] + public int terrainSimplificationLevel = 0; + +#if STEAMAUDIO_ENABLED + public int GetNumVertices() + { + if (exportAllChildren) + { + var objects = SteamAudioManager.GetGameObjectsForExport(gameObject); + + var numVertices = 0; + foreach (var obj in objects) + { + numVertices += SteamAudioManager.GetNumVertices(obj); + } + + return numVertices; + } + else + { + return SteamAudioManager.GetNumVertices(gameObject); + } + } + + public int GetNumTriangles() + { + if (exportAllChildren) + { + var objects = SteamAudioManager.GetGameObjectsForExport(gameObject); + + var numTriangles = 0; + foreach (var obj in objects) + { + numTriangles += SteamAudioManager.GetNumTriangles(obj); + } + + return numTriangles; + } + else + { + return SteamAudioManager.GetNumTriangles(gameObject); + } + } +#endif + } +} diff --git a/Scripts/Runtime/SteamAudioGeometry.cs.meta b/Scripts/Runtime/SteamAudioGeometry.cs.meta new file mode 100755 index 0000000..f54a806 --- /dev/null +++ b/Scripts/Runtime/SteamAudioGeometry.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e829c87dc2a2ed2419c5f67848317fe4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - material: {fileID: 11400000, guid: a086f686223eed942816c70be67841b0, type: 2} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioListener.cs b/Scripts/Runtime/SteamAudioListener.cs new file mode 100755 index 0000000..a63d8b3 --- /dev/null +++ b/Scripts/Runtime/SteamAudioListener.cs @@ -0,0 +1,247 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public enum ReverbType + { + Realtime, + Baked + } + + [AddComponentMenu("Steam Audio/Steam Audio Listener")] + public class SteamAudioListener : MonoBehaviour + { + [Header("Baked Static Listener Settings")] + public SteamAudioBakedListener currentBakedListener = null; + + [Header("Reverb Settings")] + public bool applyReverb = false; + public ReverbType reverbType = ReverbType.Realtime; + + [Header("Baked Reverb Settings")] + public bool useAllProbeBatches = false; + public SteamAudioProbeBatch[] probeBatches = null; + + [SerializeField] + int mTotalDataSize = 0; + [SerializeField] + int[] mProbeDataSizes = null; + [SerializeField] + BakedDataIdentifier mIdentifier = new BakedDataIdentifier { }; + [SerializeField] + SteamAudioProbeBatch[] mProbeBatchesUsed = null; + +#if STEAMAUDIO_ENABLED + Simulator mSimulator = null; + Source mSource = null; + + public int GetTotalDataSize() + { + return mTotalDataSize; + } + + public int[] GetProbeDataSizes() + { + return mProbeDataSizes; + } + + public int GetSizeForProbeBatch(int index) + { + return mProbeDataSizes[index]; + } + + public SteamAudioProbeBatch[] GetProbeBatchesUsed() + { + if (mProbeBatchesUsed == null) + { + CacheProbeBatchesUsed(); + } + + return mProbeBatchesUsed; + } + + private void Awake() + { + Reinitialize(); + } + + public void Reinitialize() + { + mSimulator = SteamAudioManager.Simulator; + + var settings = SteamAudioManager.GetSimulationSettings(false); + mSource = new Source(SteamAudioManager.Simulator, settings); + + SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); + } + + private void OnDestroy() + { + if (mSource != null) + { + mSource.Release(); + } + } + + private void Start() + { + SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); + } + + private void OnEnable() + { + if (applyReverb) + { + mSource.AddToSimulator(mSimulator); + SteamAudioManager.AddListener(this); + SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); + } + } + + private void OnDisable() + { + if (applyReverb) + { + SteamAudioManager.RemoveListener(this); + mSource.RemoveFromSimulator(mSimulator); + SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); + } + } + + private void Update() + { + SteamAudioManager.GetAudioEngineState().SetReverbSource(mSource); + } + + public BakedDataIdentifier GetBakedDataIdentifier() + { + var identifier = new BakedDataIdentifier { }; + identifier.type = BakedDataType.Reflections; + identifier.variation = BakedDataVariation.Reverb; + return identifier; + } + + public void SetInputs(SimulationFlags flags) + { + var inputs = new SimulationInputs { }; + inputs.source.origin = Common.ConvertVector(transform.position); + inputs.source.ahead = Common.ConvertVector(transform.forward); + inputs.source.up = Common.ConvertVector(transform.up); + inputs.source.right = Common.ConvertVector(transform.right); + inputs.distanceAttenuationModel.type = DistanceAttenuationModelType.Default; + inputs.airAbsorptionModel.type = AirAbsorptionModelType.Default; + inputs.reverbScaleLow = 1.0f; + inputs.reverbScaleMid = 1.0f; + inputs.reverbScaleHigh = 1.0f; + inputs.hybridReverbTransitionTime = SteamAudioSettings.Singleton.hybridReverbTransitionTime; + inputs.hybridReverbOverlapPercent = SteamAudioSettings.Singleton.hybridReverbOverlapPercent / 100.0f; + inputs.baked = (reverbType != ReverbType.Realtime) ? Bool.True : Bool.False; + if (reverbType == ReverbType.Baked) + { + inputs.bakedDataIdentifier = GetBakedDataIdentifier(); + } + + inputs.flags = 0; + if (applyReverb) + { + inputs.flags = inputs.flags | SimulationFlags.Reflections; + } + + inputs.directFlags = 0; + + mSource.SetInputs(flags, inputs); + } + + public void UpdateOutputs(SimulationFlags flags) + {} + + private void OnDrawGizmosSelected() + { + var oldColor = Gizmos.color; + var oldMatrix = Gizmos.matrix; + + Gizmos.color = Color.magenta; + + if (mProbeBatchesUsed != null) + { + foreach (var probeBatch in mProbeBatchesUsed) + { + if (probeBatch == null) + continue; + + Gizmos.matrix = probeBatch.transform.localToWorldMatrix; + Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1)); + } + } + + Gizmos.matrix = oldMatrix; + Gizmos.color = oldColor; + } + + public void UpdateBakedDataStatistics() + { + if (mProbeBatchesUsed == null) + return; + + mProbeDataSizes = new int[mProbeBatchesUsed.Length]; + mTotalDataSize = 0; + + for (var i = 0; i < mProbeBatchesUsed.Length; ++i) + { + mProbeDataSizes[i] = mProbeBatchesUsed[i].GetSizeForLayer(mIdentifier); + mTotalDataSize += mProbeDataSizes[i]; + } + } + + public void BeginBake() + { + CacheIdentifier(); + CacheProbeBatchesUsed(); + + var tasks = new BakedDataTask[1]; + tasks[0].gameObject = gameObject; + tasks[0].component = this; + tasks[0].name = "Reverb"; + tasks[0].identifier = mIdentifier; + tasks[0].probeBatches = (useAllProbeBatches) ? FindObjectsOfType() : probeBatches; + tasks[0].probeBatchNames = new string[tasks[0].probeBatches.Length]; + tasks[0].probeBatchAssets = new SerializedData[tasks[0].probeBatches.Length]; + for (var i = 0; i < tasks[0].probeBatchNames.Length; ++i) + { + tasks[0].probeBatchNames[i] = tasks[0].probeBatches[i].gameObject.name; + tasks[0].probeBatchAssets[i] = tasks[0].probeBatches[i].GetAsset(); + } + + Baker.BeginBake(tasks); + } + + void CacheIdentifier() + { + mIdentifier.type = BakedDataType.Reflections; + mIdentifier.variation = BakedDataVariation.Reverb; + } + + void CacheProbeBatchesUsed() + { + mProbeBatchesUsed = (useAllProbeBatches) ? FindObjectsOfType() : probeBatches; + } +#endif + } +} \ No newline at end of file diff --git a/Scripts/Runtime/SteamAudioListener.cs.meta b/Scripts/Runtime/SteamAudioListener.cs.meta new file mode 100755 index 0000000..317db5c --- /dev/null +++ b/Scripts/Runtime/SteamAudioListener.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6fd9ebf1401392e4bbd47fea32f47642 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioManager.cs b/Scripts/Runtime/SteamAudioManager.cs new file mode 100755 index 0000000..f684fb7 --- /dev/null +++ b/Scripts/Runtime/SteamAudioManager.cs @@ -0,0 +1,2059 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Threading; +using AOT; +using UnityEngine; +using UnityEngine.SceneManagement; +#if UNITY_EDITOR +using UnityEditor; +using UnityEditor.SceneManagement; +using System.IO; +#if UNITY_2019_2_OR_NEWER +using UnityEditor.PackageManager; +#endif +#endif + +namespace SteamAudio +{ + public enum ManagerInitReason + { + ExportingScene, + GeneratingProbes, + EditingProbes, + Baking, + Playing + } + + public class SteamAudioManager : MonoBehaviour + { + [Header("HRTF Settings")] + public int currentHRTF = 0; + +#if STEAMAUDIO_ENABLED + public string[] hrtfNames = null; + + int mNumCPUCores = 0; + AudioSettings mAudioSettings; + Context mContext = null; + HRTF[] mHRTFs = null; + EmbreeDevice mEmbreeDevice = null; + bool mEmbreeInitFailed = false; + OpenCLDevice mOpenCLDevice = null; + bool mOpenCLInitFailed = false; + RadeonRaysDevice mRadeonRaysDevice = null; + bool mRadeonRaysInitFailed = false; + TrueAudioNextDevice mTrueAudioNextDevice = null; + bool mTrueAudioNextInitFailed = false; + Scene mCurrentScene = null; + Dictionary mDynamicObjectRefCounts = new Dictionary(); + Dictionary mDynamicObjects = new Dictionary(); + Simulator mSimulator = null; + AudioEngineState mAudioEngineState = null; + Transform mListener = null; + SteamAudioListener mListenerComponent = null; + HashSet mSources = new HashSet(); + HashSet mListeners = new HashSet(); + RaycastHit[] mRayHits = new RaycastHit[1]; + IntPtr mMaterialBuffer = IntPtr.Zero; + Thread mSimulationThread = null; + EventWaitHandle mSimulationThreadWaitHandle = null; + bool mStopSimulationThread = false; + bool mSimulationCompleted = false; + float mSimulationUpdateTimeElapsed = 0.0f; + bool mSceneCommitRequired = false; + Camera mMainCamera; + + static SteamAudioManager sSingleton = null; + + public static SteamAudioManager Singleton + { + get + { + return sSingleton; + } + } + + public static Context Context + { + get + { + return sSingleton.mContext; + } + } + + public static HRTF CurrentHRTF + { + get + { + return sSingleton.mHRTFs[sSingleton.currentHRTF]; + } + } + + public static IntPtr EmbreeDevice + { + get + { + return sSingleton.mEmbreeDevice.Get(); + } + } + + public static IntPtr OpenCLDevice + { + get + { + return sSingleton.mOpenCLDevice.Get(); + } + } + + public static IntPtr RadeonRaysDevice + { + get + { + return sSingleton.mRadeonRaysDevice.Get(); + } + } + + public static IntPtr TrueAudioNextDevice + { + get + { + return sSingleton.mTrueAudioNextDevice.Get(); + } + } + + public static Scene CurrentScene + { + get + { + return sSingleton.mCurrentScene; + } + } + + public static Simulator Simulator + { + get + { + return sSingleton.mSimulator; + } + } + + public static AudioSettings AudioSettings + { + get + { + return sSingleton.mAudioSettings; + } + } + + public static AudioEngineState GetAudioEngineState() + { + return sSingleton.mAudioEngineState; + } + + public static SteamAudioListener GetSteamAudioListener() + { + if (sSingleton.mListenerComponent == null) + return null; + + return sSingleton.mListenerComponent; + } + + public int NumThreadsForCPUCorePercentage(int percentage) + { + return (int)Mathf.Max(1, (percentage * mNumCPUCores) / 100.0f); + } + + public static SceneType GetSceneType() + { + var sceneType = SteamAudioSettings.Singleton.sceneType; + + if ((sceneType == SceneType.Embree && sSingleton.mEmbreeInitFailed) || + (sceneType == SceneType.RadeonRays && (sSingleton.mOpenCLInitFailed || sSingleton.mRadeonRaysInitFailed))) + { + sceneType = SceneType.Default; + } + + return sceneType; + } + + public static ReflectionEffectType GetReflectionEffectType() + { + var reflectionEffectType = SteamAudioSettings.Singleton.reflectionEffectType; + + if ((reflectionEffectType == ReflectionEffectType.TrueAudioNext && (sSingleton.mOpenCLInitFailed || sSingleton.mTrueAudioNextInitFailed))) + { + reflectionEffectType = ReflectionEffectType.Convolution; + } + + return reflectionEffectType; + } + + public static PerspectiveCorrection GetPerspectiveCorrection() + { + if (!SteamAudioSettings.Singleton.perspectiveCorrection) + return default; + + var mainCamera = Singleton.GetMainCamera(); + PerspectiveCorrection correction = default; + if (mainCamera != null && mainCamera.aspect > .0f) + { + correction.enabled = SteamAudioSettings.Singleton.perspectiveCorrection ? Bool.True : Bool.False; + correction.xfactor = 1.0f * SteamAudioSettings.Singleton.perspectiveCorrectionFactor; + correction.yfactor = correction.xfactor / mainCamera.aspect; + + // Camera space matches OpenGL convention. No need to transform matrix to ConvertTransform. + correction.transform = Common.TransformMatrix(mainCamera.projectionMatrix * mainCamera.worldToCameraMatrix); + } + + return correction; + } + + public Camera GetMainCamera() + { + return mMainCamera; + } + + public static SimulationSettings GetSimulationSettings(bool baking) + { + var simulationSettings = new SimulationSettings { }; + simulationSettings.sceneType = GetSceneType(); + simulationSettings.reflectionType = GetReflectionEffectType(); + + if (baking) + { + simulationSettings.flags = SimulationFlags.Reflections | SimulationFlags.Pathing; + simulationSettings.maxNumRays = SteamAudioSettings.Singleton.bakingRays; + simulationSettings.numDiffuseSamples = 1024; + simulationSettings.maxDuration = SteamAudioSettings.Singleton.bakingDuration; + simulationSettings.maxOrder = SteamAudioSettings.Singleton.bakingAmbisonicOrder; + simulationSettings.numThreads = sSingleton.NumThreadsForCPUCorePercentage(SteamAudioSettings.Singleton.bakingCPUCoresPercentage); + simulationSettings.rayBatchSize = 16; + } + else + { + simulationSettings.flags = SimulationFlags.Direct | SimulationFlags.Reflections | SimulationFlags.Pathing; + simulationSettings.maxNumOcclusionSamples = SteamAudioSettings.Singleton.maxOcclusionSamples; + simulationSettings.maxNumRays = SteamAudioSettings.Singleton.realTimeRays; + simulationSettings.numDiffuseSamples = 1024; + simulationSettings.maxDuration = (simulationSettings.reflectionType == ReflectionEffectType.TrueAudioNext) ? SteamAudioSettings.Singleton.TANDuration : SteamAudioSettings.Singleton.realTimeDuration; + simulationSettings.maxOrder = (simulationSettings.reflectionType == ReflectionEffectType.TrueAudioNext) ? SteamAudioSettings.Singleton.TANAmbisonicOrder : SteamAudioSettings.Singleton.realTimeAmbisonicOrder; + simulationSettings.maxNumSources = (simulationSettings.reflectionType == ReflectionEffectType.TrueAudioNext) ? SteamAudioSettings.Singleton.TANMaxSources : SteamAudioSettings.Singleton.realTimeMaxSources; + simulationSettings.numThreads = sSingleton.NumThreadsForCPUCorePercentage(SteamAudioSettings.Singleton.realTimeCPUCoresPercentage); + simulationSettings.rayBatchSize = 16; + simulationSettings.numVisSamples = SteamAudioSettings.Singleton.bakingVisibilitySamples; + simulationSettings.samplingRate = AudioSettings.samplingRate; + simulationSettings.frameSize = AudioSettings.frameSize; + } + + if (simulationSettings.sceneType == SceneType.RadeonRays) + { + simulationSettings.openCLDevice = sSingleton.mOpenCLDevice.Get(); + simulationSettings.radeonRaysDevice = sSingleton.mRadeonRaysDevice.Get(); + } + + if (!baking && simulationSettings.reflectionType == ReflectionEffectType.TrueAudioNext) + { + simulationSettings.openCLDevice = sSingleton.mOpenCLDevice.Get(); + simulationSettings.tanDevice = sSingleton.mTrueAudioNextDevice.Get(); + } + + return simulationSettings; + } + + // This method is called at app startup (see above). + void OnApplicationStart(ManagerInitReason reason) + { + if (reason == ManagerInitReason.Playing) + { + SceneManager.sceneLoaded += OnSceneLoaded; + SceneManager.sceneUnloaded += OnSceneUnloaded; + } + + mNumCPUCores = SystemInfo.processorCount; + + mContext = new Context(); + + if (reason == ManagerInitReason.Playing) + { + mAudioSettings = AudioEngineStateHelpers.Create(SteamAudioSettings.Singleton.audioEngine).GetAudioSettings(); + + mHRTFs = new HRTF[SteamAudioSettings.Singleton.SOFAFiles.Length + 1]; + + hrtfNames = new string[SteamAudioSettings.Singleton.SOFAFiles.Length + 1]; + hrtfNames[0] = "Default"; + for (var i = 0; i < SteamAudioSettings.Singleton.SOFAFiles.Length; ++i) + { + if (SteamAudioSettings.Singleton.SOFAFiles[i]) + hrtfNames[i + 1] = SteamAudioSettings.Singleton.SOFAFiles[i].sofaName; + else + hrtfNames[i + 1] = null; + } + + mHRTFs[0] = new HRTF(mContext, mAudioSettings, null, null, SteamAudioSettings.Singleton.hrtfVolumeGainDB, SteamAudioSettings.Singleton.hrtfNormalizationType); + + for (var i = 0; i < SteamAudioSettings.Singleton.SOFAFiles.Length; ++i) + { + if (SteamAudioSettings.Singleton.SOFAFiles[i]) + { + mHRTFs[i + 1] = new HRTF(mContext, mAudioSettings, + SteamAudioSettings.Singleton.SOFAFiles[i].sofaName, + SteamAudioSettings.Singleton.SOFAFiles[i].data, + SteamAudioSettings.Singleton.SOFAFiles[i].volume, + SteamAudioSettings.Singleton.SOFAFiles[i].normType); + } + else + { + Debug.LogWarning("SOFA Asset File Missing. Assigning default HRTF."); + mHRTFs[i + 1] = mHRTFs[0]; + } + } + } + + if (reason != ManagerInitReason.EditingProbes) + { + if (SteamAudioSettings.Singleton.sceneType == SceneType.Embree) + { + try + { + mEmbreeInitFailed = false; + + mEmbreeDevice = new EmbreeDevice(mContext); + } + catch (Exception e) + { + mEmbreeInitFailed = true; + + Debug.LogException(e); + Debug.LogWarning("Embree initialization failed, reverting to Phonon for ray tracing."); + } + } + + var requiresTAN = (SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext); + + if (SteamAudioSettings.Singleton.sceneType == SceneType.RadeonRays || + SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext) + { + try + { + mOpenCLInitFailed = false; + + mOpenCLDevice = new OpenCLDevice(mContext, SteamAudioSettings.Singleton.deviceType, + SteamAudioSettings.Singleton.maxReservedComputeUnits, + SteamAudioSettings.Singleton.fractionComputeUnitsForIRUpdate, + requiresTAN); + } + catch (Exception e) + { + mOpenCLInitFailed = true; + + Debug.LogException(e); + + var warningMessage = "OpenCL initialization failed."; + if (SteamAudioSettings.Singleton.sceneType == SceneType.RadeonRays) + warningMessage += " Reverting to Phonon for ray tracing."; + if (SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext) + warningMessage += " Reverting to Convolution for reflection effect processing."; + + Debug.LogWarning(warningMessage); + } + } + + if (SteamAudioSettings.Singleton.sceneType == SceneType.RadeonRays && + !mOpenCLInitFailed) + { + try + { + mRadeonRaysInitFailed = false; + + mRadeonRaysDevice = new RadeonRaysDevice(mOpenCLDevice); + } + catch (Exception e) + { + mRadeonRaysInitFailed = true; + + Debug.LogException(e); + Debug.LogWarning("Radeon Rays initialization failed, reverting to Phonon for ray tracing."); + } + } + + if (SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext && + reason == ManagerInitReason.Playing && + !mOpenCLInitFailed) + { + try + { + mTrueAudioNextInitFailed = false; + + var frameSize = AudioSettings.frameSize; + var irSize = Mathf.CeilToInt(SteamAudioSettings.Singleton.realTimeDuration * AudioSettings.samplingRate); + var order = SteamAudioSettings.Singleton.realTimeAmbisonicOrder; + var maxSources = SteamAudioSettings.Singleton.TANMaxSources; + + mTrueAudioNextDevice = new TrueAudioNextDevice(mOpenCLDevice, frameSize, irSize, + order, maxSources); + } + catch (Exception e) + { + mTrueAudioNextInitFailed = true; + + Debug.LogException(e); + Debug.LogWarning("TrueAudio Next initialization failed, reverting to Convolution for reflection effect processing."); + } + } + } + + if (reason == ManagerInitReason.Playing) + { + var simulationSettings = GetSimulationSettings(false); + var perspectiveCorrection = GetPerspectiveCorrection(); + + mSimulator = new Simulator(mContext, simulationSettings); + + mSimulationThreadWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); + + mSimulationThread = new Thread(RunSimulation); + mSimulationThread.Start(); + + mAudioEngineState = AudioEngineState.Create(SteamAudioSettings.Singleton.audioEngine); + if (mAudioEngineState != null) + { + mAudioEngineState.Initialize(mContext.Get(), mHRTFs[0].Get(), simulationSettings, perspectiveCorrection); + } + +#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER + // If the developer has disabled scene reload, SceneManager.sceneLoaded won't fire during initial load + if ( EditorSettings.enterPlayModeOptionsEnabled && + EditorSettings.enterPlayModeOptions.HasFlag(EnterPlayModeOptions.DisableSceneReload)) + { + OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single); + } +#endif + } + } + + // This method is called at app shutdown. + void OnApplicationQuit() + { + ShutDown(); + } + + // This method is called when a scene is loaded. + void OnSceneLoaded(UnityEngine.SceneManagement.Scene scene, LoadSceneMode loadSceneMode) + { + LoadScene(scene, mContext, additive: (loadSceneMode == LoadSceneMode.Additive)); + + NotifyMainCameraChanged(); + NotifyAudioListenerChanged(); + } + + // This method is called when a scene is unloaded. + void OnSceneUnloaded(UnityEngine.SceneManagement.Scene scene) + { + RemoveAllDynamicObjects(); + } + + // Call this function when you create a new AudioListener component (or its equivalent, if you are using + // third-party audio middleware). Use this function if you want Steam Audio to automatically find the new + // AudioListener. + public static void NotifyAudioListenerChanged() + { + NotifyAudioListenerChangedTo(AudioEngineStateHelpers.Create(SteamAudioSettings.Singleton.audioEngine).GetListenerTransform()); + } + + // Call this function when you want to explicitly specify a new AudioListener component (or its equivalent, if + // you are using third-party audio middleware). + public static void NotifyAudioListenerChangedTo(Transform listenerTransform) + { + sSingleton.mListener = listenerTransform; + if (sSingleton.mListener) + { + sSingleton.mListenerComponent = sSingleton.mListener.GetComponent(); + } + } + + // Call this function when you create or change the main camera. + public static void NotifyMainCameraChanged() + { + sSingleton.mMainCamera = Camera.main; + } + + // Call this function to request that changes to a scene be committed. Call only when changes have happened. + public static void ScheduleCommitScene() + { + sSingleton.mSceneCommitRequired = true; + } + +#if STEAMAUDIO_ENABLED + private void LateUpdate() + { + if (mAudioEngineState == null) + return; + + var perspectiveCorrection = GetPerspectiveCorrection(); + mAudioEngineState.SetPerspectiveCorrection(perspectiveCorrection); + + mAudioEngineState.SetHRTF(CurrentHRTF.Get()); + + if (mCurrentScene == null || mSimulator == null) + return; + + if (mSimulationThread.ThreadState == ThreadState.WaitSleepJoin) + { + if (mSceneCommitRequired) + { + mCurrentScene.Commit(); + mSceneCommitRequired = false; + } + + mSimulator.SetScene(mCurrentScene); + mSimulator.Commit(); + } + + var sharedInputs = new SimulationSharedInputs { }; + + if (mListener != null) + { + sharedInputs.listener.origin = Common.ConvertVector(mListener.position); + sharedInputs.listener.ahead = Common.ConvertVector(mListener.forward); + sharedInputs.listener.up = Common.ConvertVector(mListener.up); + sharedInputs.listener.right = Common.ConvertVector(mListener.right); + } + + sharedInputs.numRays = SteamAudioSettings.Singleton.realTimeRays; + sharedInputs.numBounces = SteamAudioSettings.Singleton.realTimeBounces; + sharedInputs.duration = SteamAudioSettings.Singleton.realTimeDuration; + sharedInputs.order = SteamAudioSettings.Singleton.realTimeAmbisonicOrder; + sharedInputs.irradianceMinDistance = SteamAudioSettings.Singleton.realTimeIrradianceMinDistance; + sharedInputs.pathingVisualizationCallback = null; + sharedInputs.pathingUserData = IntPtr.Zero; + + mSimulator.SetSharedInputs(SimulationFlags.Direct, sharedInputs); + + foreach (var source in mSources) + { + source.SetInputs(SimulationFlags.Direct); + } + + foreach (var listener in mListeners) + { + listener.SetInputs(SimulationFlags.Direct); + } + + mSimulator.RunDirect(); + + foreach (var source in mSources) + { + source.UpdateOutputs(SimulationFlags.Direct); + } + + foreach (var listener in mListeners) + { + listener.UpdateOutputs(SimulationFlags.Direct); + } + + mSimulationUpdateTimeElapsed += Time.deltaTime; + if (mSimulationUpdateTimeElapsed < SteamAudioSettings.Singleton.simulationUpdateInterval) + return; + + mSimulationUpdateTimeElapsed = 0.0f; + + if (mSimulationThread.ThreadState == ThreadState.WaitSleepJoin) + { + if (mSimulationCompleted) + { + mSimulationCompleted = false; + + foreach (var source in mSources) + { + source.UpdateOutputs(SimulationFlags.Reflections | SimulationFlags.Pathing); + } + + foreach (var listener in mListeners) + { + listener.UpdateOutputs(SimulationFlags.Reflections | SimulationFlags.Pathing); + } + } + + mSimulator.SetSharedInputs(SimulationFlags.Reflections | SimulationFlags.Pathing, sharedInputs); + + foreach (var source in mSources) + { + source.SetInputs(SimulationFlags.Reflections | SimulationFlags.Pathing); + } + + foreach (var listener in mListeners) + { + listener.SetInputs(SimulationFlags.Reflections | SimulationFlags.Pathing); + } + + if (SteamAudioSettings.Singleton.sceneType == SceneType.Custom) + { + // The Unity ray tracer must be called from the main thread only, so run the simulation here. + // It's not suitable for heavy workloads anyway, so we assume that the performance hit is + // acceptable. If not, we recommend switching to one of the other ray tracers. + RunSimulationInternal(); + } + else + { + mSimulationThreadWaitHandle.Set(); + } + } + } +#endif + + void RunSimulationInternal() + { + if (mSimulator == null) + return; + + mSimulator.RunReflections(); + mSimulator.RunPathing(); + + mSimulationCompleted = true; + } + + void RunSimulation() + { + while (!mStopSimulationThread) + { + mSimulationThreadWaitHandle.WaitOne(); + + if (mStopSimulationThread) + break; + + RunSimulationInternal(); + } + } + + public static void Initialize(ManagerInitReason reason) + { + var managerObject = new GameObject("Steam Audio Manager"); + var manager = managerObject.AddComponent(); + + if (reason == ManagerInitReason.Playing) + { + DontDestroyOnLoad(managerObject); + } + + sSingleton = manager; + + manager.OnApplicationStart(reason); + } + + public static void ShutDown() + { + if (sSingleton.mSimulationThread != null) + { + sSingleton.mStopSimulationThread = true; + sSingleton.mSimulationThreadWaitHandle.Set(); + sSingleton.mSimulationThread.Join(); + } + + RemoveAllDynamicObjects(force: true); + RemoveAllAdditiveScenes(); + + if (sSingleton.mAudioEngineState != null) + { + sSingleton.mAudioEngineState.Destroy(); + } + + if (sSingleton.mSimulator != null) + { + sSingleton.mSimulator.Release(); + sSingleton.mSimulator = null; + } + + if (sSingleton.mTrueAudioNextDevice != null) + { + sSingleton.mTrueAudioNextDevice.Release(); + sSingleton.mTrueAudioNextDevice = null; + } + + if (sSingleton.mRadeonRaysDevice != null) + { + sSingleton.mRadeonRaysDevice.Release(); + sSingleton.mRadeonRaysDevice = null; + } + + if (sSingleton.mOpenCLDevice != null) + { + sSingleton.mOpenCLDevice.Release(); + sSingleton.mOpenCLDevice = null; + } + + if (sSingleton.mEmbreeDevice != null) + { + sSingleton.mEmbreeDevice.Release(); + sSingleton.mEmbreeDevice = null; + } + + if (sSingleton.mHRTFs != null) + { + for (var i = 0; i < sSingleton.mHRTFs.Length; ++i) + { + sSingleton.mHRTFs[i].Release(); + sSingleton.mHRTFs[i] = null; + } + } + + SceneManager.sceneLoaded -= sSingleton.OnSceneLoaded; + SceneManager.sceneUnloaded -= sSingleton.OnSceneUnloaded; + + sSingleton.mContext.Release(); + sSingleton.mContext = null; + } + + public static void Reinitialize() + { + if (sSingleton.mSimulationThread != null) + { + sSingleton.mStopSimulationThread = true; + sSingleton.mSimulationThreadWaitHandle.Set(); + sSingleton.mSimulationThread.Join(); + } + + RemoveAllDynamicObjects(force: true); + RemoveAllAdditiveScenes(); + + if (sSingleton.mAudioEngineState != null) + { + sSingleton.mAudioEngineState.Destroy(); + } + + sSingleton.mSimulator = null; + + UnityEngine.AudioSettings.Reset(UnityEngine.AudioSettings.GetConfiguration()); + + if ((sSingleton.mEmbreeDevice == null || sSingleton.mEmbreeDevice.Get() == IntPtr.Zero) + && SteamAudioSettings.Singleton.sceneType == SceneType.Embree) + { + try + { + sSingleton.mEmbreeInitFailed = false; + + sSingleton.mEmbreeDevice = new EmbreeDevice(sSingleton.mContext); + } + catch (Exception e) + { + sSingleton.mEmbreeInitFailed = true; + + Debug.LogException(e); + Debug.LogWarning("Embree initialization failed, reverting to Phonon for ray tracing."); + } + } + + var requiresTAN = (SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext); + + if ((sSingleton.mOpenCLDevice == null || sSingleton.mOpenCLDevice.Get() == IntPtr.Zero) && + (SteamAudioSettings.Singleton.sceneType == SceneType.RadeonRays || + SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext)) + { + try + { + sSingleton.mOpenCLInitFailed = false; + + sSingleton.mOpenCLDevice = new OpenCLDevice(sSingleton.mContext, SteamAudioSettings.Singleton.deviceType, + SteamAudioSettings.Singleton.maxReservedComputeUnits, + SteamAudioSettings.Singleton.fractionComputeUnitsForIRUpdate, + requiresTAN); + } + catch (Exception e) + { + sSingleton.mOpenCLInitFailed = true; + + Debug.LogException(e); + + var warningMessage = "OpenCL initialization failed."; + if (SteamAudioSettings.Singleton.sceneType == SceneType.RadeonRays) + warningMessage += " Reverting to Phonon for ray tracing."; + if (SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext) + warningMessage += " Reverting to Convolution for reflection effect processing."; + + Debug.LogWarning(warningMessage); + } + } + + if ((sSingleton.mRadeonRaysDevice == null || sSingleton.mRadeonRaysDevice.Get() == IntPtr.Zero) && + SteamAudioSettings.Singleton.sceneType == SceneType.RadeonRays && + !sSingleton.mOpenCLInitFailed) + { + try + { + sSingleton.mRadeonRaysInitFailed = false; + + sSingleton.mRadeonRaysDevice = new RadeonRaysDevice(sSingleton.mOpenCLDevice); + } + catch (Exception e) + { + sSingleton.mRadeonRaysInitFailed = true; + + Debug.LogException(e); + Debug.LogWarning("Radeon Rays initialization failed, reverting to Phonon for ray tracing."); + } + } + + if ((sSingleton.mTrueAudioNextDevice == null || sSingleton.mTrueAudioNextDevice.Get() == IntPtr.Zero) && + SteamAudioSettings.Singleton.reflectionEffectType == ReflectionEffectType.TrueAudioNext && + !sSingleton.mOpenCLInitFailed) + { + try + { + sSingleton.mTrueAudioNextInitFailed = false; + + var frameSize = AudioSettings.frameSize; + var irSize = Mathf.CeilToInt(SteamAudioSettings.Singleton.realTimeDuration * AudioSettings.samplingRate); + var order = SteamAudioSettings.Singleton.realTimeAmbisonicOrder; + var maxSources = SteamAudioSettings.Singleton.TANMaxSources; + + sSingleton.mTrueAudioNextDevice = new TrueAudioNextDevice(sSingleton.mOpenCLDevice, frameSize, irSize, + order, maxSources); + } + catch (Exception e) + { + sSingleton.mTrueAudioNextInitFailed = true; + + Debug.LogException(e); + Debug.LogWarning("TrueAudio Next initialization failed, reverting to Convolution for reflection effect processing."); + } + } + + var simulationSettings = GetSimulationSettings(false); + var persPectiveCorrection = GetPerspectiveCorrection(); + + sSingleton.mSimulator = new Simulator(sSingleton.mContext, simulationSettings); + + sSingleton.mStopSimulationThread = false; + sSingleton.mSimulationThread = new Thread(sSingleton.RunSimulation); + sSingleton.mSimulationThread.Start(); + + sSingleton.mAudioEngineState = AudioEngineState.Create(SteamAudioSettings.Singleton.audioEngine); + if (sSingleton.mAudioEngineState != null) + { + sSingleton.mAudioEngineState.Initialize(sSingleton.mContext.Get(), sSingleton.mHRTFs[0].Get(), simulationSettings, persPectiveCorrection); + + var listeners = new SteamAudioListener[sSingleton.mListeners.Count]; + sSingleton.mListeners.CopyTo(listeners); + foreach (var listener in listeners) + { + listener.enabled = false; + listener.Reinitialize(); + listener.enabled = true; + } + } + } + + public static void AddSource(SteamAudioSource source) + { + sSingleton.mSources.Add(source); + } + + public static void RemoveSource(SteamAudioSource source) + { + sSingleton.mSources.Remove(source); + } + + public static void AddListener(SteamAudioListener listener) + { + sSingleton.mListeners.Add(listener); + } + + public static void RemoveListener(SteamAudioListener listener) + { + sSingleton.mListeners.Remove(listener); + } + +#if UNITY_EDITOR + [MenuItem("Steam Audio/Settings", false, 1)] + public static void EditSettings() + { + Selection.activeObject = SteamAudioSettings.Singleton; +#if UNITY_2018_2_OR_NEWER + EditorApplication.ExecuteMenuItem("Window/General/Inspector"); +#else + EditorApplication.ExecuteMenuItem("Window/Inspector"); +#endif + } + + [MenuItem("Steam Audio/Export Active Scene", false, 12)] + public static void ExportActiveScene() + { + ExportScene(SceneManager.GetActiveScene(), false); + } + + [MenuItem("Steam Audio/Export All Open Scenes", false, 13)] + public static void ExportAllOpenScenes() + { + for (var i = 0; i < SceneManager.sceneCount; ++i) + { + var scene = SceneManager.GetSceneAt(i); + + EditorUtility.DisplayProgressBar("Steam Audio", string.Format("Exporting scene: {0}", scene.name), (float)i / (float)SceneManager.sceneCount); + + if (!scene.isLoaded) + { + Debug.LogWarning(string.Format("Scene {0} is not loaded in the hierarchy.", scene.name)); + continue; + } + + ExportScene(scene, false); + } + + EditorUtility.DisplayProgressBar("Steam Audio", "", 1.0f); + EditorUtility.ClearProgressBar(); + } + + [MenuItem("Steam Audio/Export All Scenes In Build", false, 14)] + public static void ExportAllScenesInBuild() + { + for (var i = 0; i < SceneManager.sceneCountInBuildSettings; ++i) + { + var scene = SceneManager.GetSceneByBuildIndex(i); + + EditorUtility.DisplayProgressBar("Steam Audio", string.Format("Exporting scene: {0}", scene.name), (float)i / (float)SceneManager.sceneCountInBuildSettings); + + var shouldClose = false; + if (!scene.isLoaded) + { + scene = EditorSceneManager.OpenScene(SceneUtility.GetScenePathByBuildIndex(i), OpenSceneMode.Additive); + shouldClose = true; + } + + ExportScene(scene, false); + + if (shouldClose) + { + EditorSceneManager.CloseScene(scene, true); + } + } + + EditorUtility.DisplayProgressBar("Steam Audio", "", 1.0f); + EditorUtility.ClearProgressBar(); + } + + [MenuItem("Steam Audio/Export Active Scene To OBJ", false, 25)] + public static void ExportActiveSceneToOBJ() + { + ExportScene(SceneManager.GetActiveScene(), true); + } + + [MenuItem("Steam Audio/Export Dynamic Objects In Active Scene", false, 36)] + public static void ExportDynamicObjectsInActiveScene() + { + ExportDynamicObjectsInArray(GetDynamicObjectsInScene(SceneManager.GetActiveScene())); + } + + [MenuItem("Steam Audio/Export Dynamic Objects In All Open Scenes", false, 37)] + public static void ExportDynamicObjectsInAllOpenScenes() + { + for (var i = 0; i < SceneManager.sceneCount; ++i) + { + var scene = SceneManager.GetSceneAt(i); + + EditorUtility.DisplayProgressBar("Steam Audio", string.Format("Exporting dynamic objects in scene: {0}", scene.name), (float)i / (float)SceneManager.sceneCount); + + if (!scene.isLoaded) + { + Debug.LogWarning(string.Format("Scene {0} is not loaded in the hierarchy.", scene.name)); + continue; + } + + ExportDynamicObjectsInArray(GetDynamicObjectsInScene(scene)); + } + + EditorUtility.DisplayProgressBar("Steam Audio", "", 1.0f); + EditorUtility.ClearProgressBar(); + } + + [MenuItem("Steam Audio/Export Dynamic Objects In All Scenes In Build", false, 38)] + public static void ExportDynamicObjectsInBuild() + { + for (var i = 0; i < SceneManager.sceneCountInBuildSettings; ++i) + { + var scene = SceneManager.GetSceneByBuildIndex(i); + + EditorUtility.DisplayProgressBar("Steam Audio", string.Format("Exporting dynamic objects in scene: {0}", scene.name), (float)i / (float)SceneManager.sceneCountInBuildSettings); + + var shouldClose = false; + if (!scene.isLoaded) + { + scene = EditorSceneManager.OpenScene(SceneUtility.GetScenePathByBuildIndex(i), OpenSceneMode.Additive); + shouldClose = true; + } + + ExportDynamicObjectsInArray(GetDynamicObjectsInScene(scene)); + + if (shouldClose) + { + EditorSceneManager.CloseScene(scene, true); + } + } + + EditorUtility.DisplayProgressBar("Steam Audio", "", 1.0f); + EditorUtility.ClearProgressBar(); + } + + [MenuItem("Steam Audio/Export All Dynamic Objects In Project", false, 39)] + public static void ExportDynamicObjectsInProject() + { + var scenes = AssetDatabase.FindAssets("t:Scene"); + var prefabs = AssetDatabase.FindAssets("t:Prefab"); + + var numItems = scenes.Length + prefabs.Length; + + var index = 0; + foreach (var sceneGUID in scenes) + { + var scenePath = AssetDatabase.GUIDToAssetPath(sceneGUID); + + EditorUtility.DisplayProgressBar("Steam Audio", string.Format("Exporting dynamic objects in scene: {0}", scenePath), (float)index / (float)numItems); + + var activeScene = EditorSceneManager.GetActiveScene(); + var isLoadedScene = (scenePath == activeScene.path); + + var scene = activeScene; + if (!isLoadedScene) + { +#if UNITY_2019_2_OR_NEWER + var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(scenePath); + if (!(packageInfo == null || packageInfo.source == PackageSource.Embedded || packageInfo.source == PackageSource.Local)) + { + Debug.LogWarning(string.Format("Scene {0} is part of a read-only package, skipping.", scenePath)); + continue; + } +#endif + + scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive); + } + + ExportDynamicObjectsInArray(GetDynamicObjectsInScene(scene)); + + if (!isLoadedScene) + { + EditorSceneManager.CloseScene(scene, true); + } + + ++index; + } + + foreach (var prefabGUID in prefabs) + { + var prefabPath = AssetDatabase.GUIDToAssetPath(prefabGUID); + + EditorUtility.DisplayProgressBar("Steam Audio", string.Format("Exporting dynamic objects in prefab: {0}", prefabPath), (float)index / (float)numItems); + + var prefab = AssetDatabase.LoadMainAssetAtPath(prefabPath) as GameObject; + var dynamicObjects = prefab.GetComponentsInChildren(); + ExportDynamicObjectsInArray(dynamicObjects); + + ++index; + } + + EditorUtility.DisplayProgressBar("Steam Audio", "", 1.0f); + EditorUtility.ClearProgressBar(); + } + + [MenuItem("Steam Audio/Install FMOD Studio Plugin Files", false, 50)] + public static void InstallFMODStudioPluginFiles() + { + // Make sure the FMOD Studio Unity integration is installed. + var assemblySuffix = ",FMODUnity"; + var FMODUnity_Settings = Type.GetType("FMODUnity.Settings" + assemblySuffix); + if (FMODUnity_Settings == null) + { + EditorUtility.DisplayDialog("Steam Audio", + "The FMOD Studio Unity integration does not seem to be installed to your Unity project. Install " + + "it and try again.", + "OK"); + return; + } + + // Make sure we're using at least FMOD Studio v2.0. + var FMODUnity_Settings_Instance = FMODUnity_Settings.GetProperty("Instance"); + var FMODUnity_Settings_CurrentVersion = FMODUnity_Settings.GetField("CurrentVersion"); + var fmodSettings = FMODUnity_Settings_Instance.GetValue(null, null); + var fmodVersion = (int)FMODUnity_Settings_CurrentVersion.GetValue(fmodSettings); + var fmodVersionMajor = (fmodVersion & 0x00ff0000) >> 16; + var fmodVersionMinor = (fmodVersion & 0x0000ff00) >> 8; + var fmodVersionPatch = (fmodVersion & 0x000000ff); + if (fmodVersionMajor < 2) + { + EditorUtility.DisplayDialog("Steam Audio", + "Steam Audio requires FMOD Studio 2.0 or later.", + "OK"); + return; + } + + var moveRequired = false; + var moveSucceeded = false; + + // Look for the FMOD Studio plugin files. The files are in the right place for FMOD Studio 2.2 + // out of the box, but will need to be copied for 2.1 or earlier. + // 2.0 through 2.1 expect plugin files in Assets/Plugins/FMOD/lib/(platform) + // 2.2 expects plugin files in Assets/Plugins/FMOD/platforms/(platform)/lib + if (AssetExists("Assets/Plugins/FMOD/lib/win/x86_64/phonon_fmod.dll")) + { + // Files are in the location corresponding to 2.1 or earlier. + if (fmodVersionMinor >= 2) + { + // We're using 2.2 or later, so we need to move files. + moveRequired = true; + + var moves = new Dictionary(); + moves.Add("Assets/Plugins/FMOD/lib/win/x86/phonon_fmod.dll", "Assets/Plugins/FMOD/platforms/win/lib/x86/phonon_fmod.dll"); + moves.Add("Assets/Plugins/FMOD/lib/win/x86_64/phonon_fmod.dll", "Assets/Plugins/FMOD/platforms/win/lib/x86_64/phonon_fmod.dll"); + moves.Add("Assets/Plugins/FMOD/lib/linux/x86/libphonon_fmod.so", "Assets/Plugins/FMOD/platforms/linux/lib/x86/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/lib/linux/x86_64/libphonon_fmod.so", "Assets/Plugins/FMOD/platforms/linux/lib/x86_64/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/lib/mac/phonon_fmod.bundle", "Assets/Plugins/FMOD/platforms/mac/lib/phonon_fmod.bundle"); + moves.Add("Assets/Plugins/FMOD/lib/android/armeabi-v7a/libphonon_fmod.so", "Assets/Plugins/FMOD/platforms/android/lib/armeabi-v7a/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/lib/android/arm64-v8a/libphonon_fmod.so", "Assets/Plugins/FMOD/platforms/android/lib/arm64-v8a/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/lib/android/x86/libphonon_fmod.so", "Assets/Plugins/FMOD/platforms/android/lib/x86/libphonon_fmod.so"); + + moveSucceeded = MoveAssets(moves); + } + } + else if (AssetExists("Assets/Plugins/FMOD/platforms/win/lib/x86_64/phonon_fmod.dll")) + { + // Files are in the location corresponding to 2.2 or later. + if (fmodVersionMinor <= 1) + { + // We're using 2.1 or earlier, so we need to move files. + moveRequired = true; + + var moves = new Dictionary(); + moves.Add("Assets/Plugins/FMOD/platforms/win/lib/x86/phonon_fmod.dll", "Assets/Plugins/FMOD/lib/win/x86/phonon_fmod.dll"); + moves.Add("Assets/Plugins/FMOD/platforms/win/lib/x86_64/phonon_fmod.dll", "Assets/Plugins/FMOD/lib/win/x86_64/phonon_fmod.dll"); + moves.Add("Assets/Plugins/FMOD/platforms/linux/lib/x86/libphonon_fmod.so", "Assets/Plugins/FMOD/lib/linux/x86/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/platforms/linux/lib/x86_64/libphonon_fmod.so", "Assets/Plugins/FMOD/lib/linux/x86_64/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/platforms/mac/lib/phonon_fmod.bundle", "Assets/Plugins/FMOD/lib/mac/phonon_fmod.bundle"); + moves.Add("Assets/Plugins/FMOD/platforms/android/lib/armeabi-v7a/libphonon_fmod.so", "Assets/Plugins/FMOD/lib/android/armeabi-v7a/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/platforms/android/lib/arm64-v8a/libphonon_fmod.so", "Assets/Plugins/FMOD/lib/android/arm64-v8a/libphonon_fmod.so"); + moves.Add("Assets/Plugins/FMOD/platforms/android/lib/x86/libphonon_fmod.so", "Assets/Plugins/FMOD/lib/android/x86/libphonon_fmod.so"); + + moveSucceeded = MoveAssets(moves); + } + } + else + { + EditorUtility.DisplayDialog("Steam Audio", + "Unable to find Steam Audio FMOD Studio plugin files. Try reinstalling the Steam Audio Unity " + + "integration.", + "OK"); + return; + } + + if (!moveRequired) + { + EditorUtility.DisplayDialog("Steam Audio", + "Steam Audio FMOD Studio plugin files are already in the correct place.", + "OK"); + } + else if (!moveSucceeded) + { + EditorUtility.DisplayDialog("Steam Audio", + "Failed to copy Steam Audio FMOD Studio plugin files to the correct place. See the console for " + + "details.", + "OK"); + } + else + { + EditorUtility.DisplayDialog("Steam Audio", + "Steam Audio FMOD Studio plugin files moved to the correct place.", + "OK"); + } + } + + [MenuItem("Steam Audio/Install FMOD Studio Plugin Files", true)] + public static bool ValidateInstallFMODStudioPluginFiles() + { + return (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.FMODStudio); + } + + private static bool AssetExists(string assetPath) + { + return !string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(assetPath)) && + (File.Exists(Environment.CurrentDirectory + "/" + assetPath) || Directory.Exists(Environment.CurrentDirectory + "/" + assetPath)); + } + + private static bool EnsureAssetDirectoryExists(string directory) + { + if (AssetDatabase.IsValidFolder(directory)) + return true; + + var parent = Path.GetDirectoryName(directory); + var baseName = Path.GetFileName(directory); + + if (!EnsureAssetDirectoryExists(parent)) + return false; + + var result = AssetDatabase.CreateFolder(parent, baseName); + if (string.IsNullOrEmpty(result)) + { + Debug.LogErrorFormat("Unable to create asset directory {0} in {1}: {2}", baseName, parent, result); + return false; + } + + return true; + } + + private static bool MoveAssets(Dictionary moves) + { + foreach (var source in moves.Keys) + { + if (!AssetExists(source)) + { + Debug.LogErrorFormat("Unable to find plugin file: {0}", source); + return false; + } + + var destination = moves[source]; + var directory = Path.GetDirectoryName(destination); + + if (!EnsureAssetDirectoryExists(directory)) + { + Debug.LogErrorFormat("Unable to create directory: {0}", directory); + return false; + } + + var result = AssetDatabase.MoveAsset(source, destination); + + if (!string.IsNullOrEmpty(result)) + { + Debug.LogErrorFormat("Unable to move {0} to {1}: {2}", source, destination, result); + return false; + } + + Debug.LogFormat("Moved {0} to {1}.", source, destination); + } + + return true; + } +#endif + + // Exports a dynamic object. + public static void ExportDynamicObject(SteamAudioDynamicObject dynamicObject, bool exportOBJ) + { + var objects = GetDynamicGameObjectsForExport(dynamicObject); + + if (objects == null || objects.Length == 0) + { + Debug.LogError(string.Format("Dynamic object {0} has no Steam Audio geometry attached. Skipping export.", dynamicObject.name)); + return; + } + + var dataAsset = (!exportOBJ) ? GetDataAsset(dynamicObject) : null; + var objFileName = (exportOBJ) ? GetOBJFileName(dynamicObject) : ""; + + Export(objects, dynamicObject.name, dataAsset, objFileName, true, exportOBJ); + } + + // Exports all dynamic objects in an array. + static void ExportDynamicObjectsInArray(SteamAudioDynamicObject[] dynamicObjects) + { + foreach (var dynamicObject in dynamicObjects) + { + ExportDynamicObject(dynamicObject, false); + } + } + + // Finds all dynamic objects in a scene. + static SteamAudioDynamicObject[] GetDynamicObjectsInScene(UnityEngine.SceneManagement.Scene scene) + { + var dynamicObjects = new List(); + + var rootObjects = scene.GetRootGameObjects(); + foreach (var rootObject in rootObjects) + { + dynamicObjects.AddRange(rootObject.GetComponentsInChildren()); + } + + return dynamicObjects.ToArray(); + } + + // Loads a static scene. + public static void LoadScene(UnityEngine.SceneManagement.Scene unityScene, Context context, bool additive) + { + if (!additive) + { + sSingleton.mCurrentScene = CreateScene(context); + } + } + + // Loads a dynamic object as an instanced mesh. Multiple dynamic objects loaded from the same file + // will share the underlying geometry and material data (using a reference count). The instanced meshes + // allow each dynamic object to have its own transform. + public static InstancedMesh LoadDynamicObject(SteamAudioDynamicObject dynamicObject, Scene parentScene, Context context) + { + InstancedMesh instancedMesh = null; + + var dataAsset = dynamicObject.asset; + var assetName = dataAsset.name; + if (dataAsset != null) + { + Scene subScene = null; + if (sSingleton.mDynamicObjects.ContainsKey(assetName)) + { + subScene = sSingleton.mDynamicObjects[assetName]; + sSingleton.mDynamicObjectRefCounts[assetName]++; + } + else + { + subScene = CreateScene(context); + var subStaticMesh = Load(dataAsset, context, subScene); + subStaticMesh.AddToScene(subScene); + subStaticMesh.Release(); + + sSingleton.mDynamicObjects.Add(assetName, subScene); + sSingleton.mDynamicObjectRefCounts.Add(assetName, 1); + } + + instancedMesh = new InstancedMesh(parentScene, subScene, dynamicObject.transform); + } + + return instancedMesh; + } + + // Unloads a dynamic object and decrements the reference count of the underlying data. However, + // when the reference count hits zero, we don't get rid of the data, because the dynamic object may + // be instantiated again within a few frames, and we don't want to waste time re-loading it. The data + // will eventually be unloaded at the next scene change. + public static void UnloadDynamicObject(SteamAudioDynamicObject dynamicObject) + { + var assetName = (dynamicObject.asset) ? dynamicObject.asset.name : ""; + + if (sSingleton.mDynamicObjectRefCounts.ContainsKey(assetName)) + { + sSingleton.mDynamicObjectRefCounts[assetName]--; + } + } + + // Gather a list of all GameObjects to export, starting from a given root object. + public static List GetGameObjectsForExport(GameObject root, bool exportingStaticObjects = false) + { + var gameObjects = new List(); + + if (exportingStaticObjects && root.GetComponentInParent() != null) + return new List(); + + var geometries = root.GetComponentsInChildren(); + foreach (var geometry in geometries) + { + if (IsDynamicSubObject(root, geometry.gameObject)) + continue; + + if (geometry.exportAllChildren) + { + var meshes = geometry.GetComponentsInChildren(); + foreach (var mesh in meshes) + { + if (!IsDynamicSubObject(root, mesh.gameObject)) + { + if (IsActiveInHierarchy(mesh.gameObject.transform)) + { + gameObjects.Add(mesh.gameObject); + } + } + } + + var terrains = geometry.GetComponentsInChildren(); + foreach (var terrain in terrains) + { + if (!IsDynamicSubObject(root, terrain.gameObject)) + { + if (IsActiveInHierarchy(terrain.gameObject.transform)) + { + gameObjects.Add(terrain.gameObject); + } + } + } + } + else + { + if (IsActiveInHierarchy(geometry.gameObject.transform)) + { + if (geometry.gameObject.GetComponent() != null || + geometry.gameObject.GetComponent() != null) + { + gameObjects.Add(geometry.gameObject); + } + } + } + } + + var uniqueGameObjects = new HashSet(gameObjects); + + gameObjects.Clear(); + foreach (var uniqueGameObject in uniqueGameObjects) + { + gameObjects.Add(uniqueGameObject); + } + + return gameObjects; + } + + // Returns the number of vertices associated with a GameObject. + public static int GetNumVertices(GameObject gameObject) + { + var mesh = gameObject.GetComponent(); + var terrain = gameObject.GetComponent(); + + if (mesh != null) + { + return mesh.sharedMesh.vertexCount; + } + else if (terrain != null) + { + var terrainSimplificationLevel = GetTerrainSimplificationLevel(terrain); + + var w = terrain.terrainData.heightmapResolution; + var h = terrain.terrainData.heightmapResolution; + var s = Mathf.Min(w - 1, Mathf.Min(h - 1, (int)Mathf.Pow(2.0f, terrainSimplificationLevel))); + + if (s == 0) + { + s = 1; + } + + w = ((w - 1) / s) + 1; + h = ((h - 1) / s) + 1; + + return (w * h); + } + else + { + return 0; + } + } + + // Returns the number of triangles associated with a GameObject. + public static int GetNumTriangles(GameObject gameObject) + { + var mesh = gameObject.GetComponent(); + var terrain = gameObject.GetComponent(); + + if (mesh != null) + { + return mesh.sharedMesh.triangles.Length / 3; + } + else if (terrain != null) + { + var terrainSimplificationLevel = GetTerrainSimplificationLevel(terrain); + + var w = terrain.terrainData.heightmapResolution; + var h = terrain.terrainData.heightmapResolution; + var s = Mathf.Min(w - 1, Mathf.Min(h - 1, (int)Mathf.Pow(2.0f, terrainSimplificationLevel))); + + if (s == 0) + { + s = 1; + } + + w = ((w - 1) / s) + 1; + h = ((h - 1) / s) + 1; + + return ((w - 1) * (h - 1) * 2); + } + else + { + return 0; + } + } + + [MonoPInvokeCallback(typeof(ClosestHitCallback))] + public static void ClosestHit(ref Ray ray, float minDistance, float maxDistance, out Hit hit, IntPtr userData) + { + var origin = Common.ConvertVector(ray.origin); + var direction = Common.ConvertVector(ray.direction); + + origin += minDistance * direction; + + var layerMask = SteamAudioSettings.Singleton.layerMask; + + hit.objectIndex = 0; + hit.triangleIndex = 0; + hit.materialIndex = 0; + + var numHits = Physics.RaycastNonAlloc(origin, direction, sSingleton.mRayHits, maxDistance, layerMask); + if (numHits > 0) + { + hit.distance = sSingleton.mRayHits[0].distance; + hit.normal = Common.ConvertVector(sSingleton.mRayHits[0].normal); + hit.material = GetMaterialBufferForTransform(sSingleton.mRayHits[0].collider.transform); + } + else + { + hit.distance = Mathf.Infinity; + hit.normal = new Vector3 { x = 0.0f, y = 0.0f, z = 0.0f }; + hit.material = IntPtr.Zero; + } + } + + [MonoPInvokeCallback(typeof(AnyHitCallback))] + public static void AnyHit(ref Ray ray, float minDistance, float maxDistance, out byte occluded, IntPtr userData) + { + var origin = Common.ConvertVector(ray.origin); + var direction = Common.ConvertVector(ray.direction); + + origin += minDistance * direction; + + var layerMask = SteamAudioSettings.Singleton.layerMask; + + var numHits = Physics.RaycastNonAlloc(origin, direction, sSingleton.mRayHits, maxDistance, layerMask); + + occluded = (byte)((numHits > 0) ? 1 : 0); + } + + // This method is called as soon as scripts are loaded, which happens whenever play mode is started + // (in the editor), or whenever the game is launched. We then create a Steam Audio Manager object + // and move it to the Don't Destroy On Load list. + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + static void AutoInitialize() + { + Initialize(ManagerInitReason.Playing); + } + + // Exports the static geometry in a scene. + public static void ExportScene(UnityEngine.SceneManagement.Scene unityScene, bool exportOBJ) + { + var objects = GetStaticGameObjectsForExport(unityScene); + + if (objects == null || objects.Length == 0) + { + Debug.LogWarning(string.Format("Scene {0} has no Steam Audio static geometry. Skipping export.", unityScene.name)); + return; + } + + var dataAsset = (!exportOBJ) ? GetDataAsset(unityScene) : null; + var objFileName = (exportOBJ) ? GetOBJFileName(unityScene) : ""; + + if (!exportOBJ && dataAsset == null) + return; + + if (exportOBJ && (objFileName == null || objFileName.Length == 0)) + return; + + Export(objects, unityScene.name, dataAsset, objFileName, false, exportOBJ); + } + + // Exports a set of GameObjects. + static void Export(GameObject[] objects, string name, SerializedData dataAsset, string objFileName, bool dynamic, bool exportOBJ) + { + var type = (dynamic) ? "Dynamic Object" : "Scene"; + + Vector3[] vertices = null; + Triangle[] triangles = null; + int[] materialIndices = null; + Material[] materials = null; + GetGeometryAndMaterialBuffers(objects, ref vertices, ref triangles, ref materialIndices, ref materials, dynamic, exportOBJ); + + if (vertices.Length == 0 || triangles.Length == 0 || materialIndices.Length == 0 || materials.Length == 0) + { + Debug.LogError(string.Format("Steam Audio {0} [{1}]: No Steam Audio Geometry components attached.", type, name)); + return; + } + + var context = new Context(); + + // Scene type should always be Phonon when exporting. + var scene = new Scene(context, SceneType.Default, null, null, null, null); + + var staticMesh = new StaticMesh(context, scene, vertices, triangles, materialIndices, materials); + staticMesh.AddToScene(scene); + + if (exportOBJ) + { + scene.Commit(); + scene.SaveOBJ(objFileName); + } + else + { + staticMesh.Save(dataAsset); + } + + Debug.Log(string.Format("Steam Audio {0} [{1}]: Exported to {2}.", type, name, (exportOBJ) ? objFileName : dataAsset.name)); + + staticMesh.Release(); + scene.Release(); + } + + static Scene CreateScene(Context context) + { + var sceneType = GetSceneType(); + + var scene = new Scene(context, sceneType, sSingleton.mEmbreeDevice, sSingleton.mRadeonRaysDevice, + ClosestHit, AnyHit); + + if (sceneType == SceneType.Custom) + { + if (sSingleton.mMaterialBuffer == IntPtr.Zero) + { + sSingleton.mMaterialBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Material))); + } + } + + return scene; + } + + // Loads a Steam Audio scene. + static StaticMesh Load(SerializedData dataAsset, Context context, Scene scene) + { + return new StaticMesh(context, scene, dataAsset); + } + + // Unloads the underlying data for dynamic objects. Can either remove only unreferenced data (for use when + // changing scenes) or all data (for use when shutting down). + static void RemoveAllDynamicObjects(bool force = false) + { + var unreferencedDynamicObjects = new List(); + + foreach (var scene in sSingleton.mDynamicObjectRefCounts.Keys) + { + if (force || sSingleton.mDynamicObjectRefCounts[scene] == 0) + { + unreferencedDynamicObjects.Add(scene); + } + } + + foreach (var scene in unreferencedDynamicObjects) + { + sSingleton.mDynamicObjects[scene].Release(); + sSingleton.mDynamicObjects.Remove(scene); + sSingleton.mDynamicObjectRefCounts.Remove(scene); + } + } + + // Unloads all currently-loaded scenes. + static void RemoveAllAdditiveScenes() + { + Marshal.FreeHGlobal(sSingleton.mMaterialBuffer); + + if (sSingleton.mCurrentScene != null) + { + sSingleton.mCurrentScene.Release(); + sSingleton.mCurrentScene = null; + } + } + + static IntPtr GetMaterialBufferForTransform(Transform obj) + { + var material = new Material(); + var found = false; + + var currentObject = obj; + while (currentObject != null) + { + var steamAudioGeometry = currentObject.GetComponent(); + if (steamAudioGeometry != null && steamAudioGeometry.material != null) + { + material = steamAudioGeometry.material.GetMaterial(); + found = true; + break; + } + currentObject = currentObject.parent; + } + + if (!found) + { + material = SteamAudioSettings.Singleton.defaultMaterial.GetMaterial(); + } + + Marshal.StructureToPtr(material, sSingleton.mMaterialBuffer, true); + + return sSingleton.mMaterialBuffer; + } + + // Gather a list of all GameObjects to export in a scene, excluding dynamic objects. + static GameObject[] GetStaticGameObjectsForExport(UnityEngine.SceneManagement.Scene scene) + { + var gameObjects = new List(); + + var roots = scene.GetRootGameObjects(); + foreach (var root in roots) + { + gameObjects.AddRange(GetGameObjectsForExport(root, true)); + } + + return gameObjects.ToArray(); + } + + // Gather a list of all GameObjects to export for a given dynamic object. + static GameObject[] GetDynamicGameObjectsForExport(SteamAudioDynamicObject dynamicObject) + { + return GetGameObjectsForExport(dynamicObject.gameObject).ToArray(); + } + + static bool IsDynamicSubObject(GameObject root, GameObject obj) + { + return (root.GetComponentInParent() != + obj.GetComponentInParent()); + } + + // Ideally, we want to use GameObject.activeInHierarchy to check if a GameObject is active. However, when + // we batch-export dynamic objects, Prefabs are instantiated using AssetDatabase.LoadMainAssetAtPath, + // and isActiveInHierarchy returns false even if all GameObjects in the Prefab return true for + // GameObject.activeSelf. Therefore, we manually walk up the hierarchy and check if the GameObject is active. + static bool IsActiveInHierarchy(Transform obj) + { + if (obj == null) + return true; + + return (obj.gameObject.activeSelf && IsActiveInHierarchy(obj.parent)); + } + + // Given an array of GameObjects, export the vertex, triangle, material index, and material data. + static void GetGeometryAndMaterialBuffers(GameObject[] gameObjects, ref Vector3[] vertices, ref Triangle[] triangles, ref int[] materialIndices, ref Material[] materials, bool isDynamic, bool exportOBJ) + { + var numVertices = new int[gameObjects.Length]; + var numTriangles = new int[gameObjects.Length]; + var totalNumVertices = 0; + var totalNumTriangles = 0; + for (var i = 0; i < gameObjects.Length; ++i) + { + numVertices[i] = GetNumVertices(gameObjects[i]); + numTriangles[i] = GetNumTriangles(gameObjects[i]); + totalNumVertices += numVertices[i]; + totalNumTriangles += numTriangles[i]; + } + + int[] materialIndicesPerObject = null; + GetMaterialMapping(gameObjects, ref materials, ref materialIndicesPerObject); + + vertices = new Vector3[totalNumVertices]; + triangles = new Triangle[totalNumTriangles]; + materialIndices = new int[totalNumTriangles]; + + // If we're exporting a dynamic object, apply the relevant transform. However, if we're exporting + // to an OBJ file, _don't_ apply the transform, so the dynamic object appears centered at its local + // origin. + Transform transform = null; + if (isDynamic && !exportOBJ) + { + var dynamicObject = gameObjects[0].GetComponent(); + if (dynamicObject == null) + { + dynamicObject = GetDynamicObjectInParent(gameObjects[0].transform); + } + transform = dynamicObject.transform; + } + + var verticesOffset = 0; + var trianglesOffset = 0; + for (var i = 0; i < gameObjects.Length; ++i) + { + GetVertices(gameObjects[i], vertices, verticesOffset, transform); + GetTriangles(gameObjects[i], triangles, trianglesOffset); + FixupTriangleIndices(triangles, trianglesOffset, trianglesOffset + numTriangles[i], verticesOffset); + + for (var j = 0; j < numTriangles[i]; ++j) + { + materialIndices[trianglesOffset + j] = materialIndicesPerObject[i]; + } + + verticesOffset += numVertices[i]; + trianglesOffset += numTriangles[i]; + } + } + + // Ideally, we want to use GameObject.GetComponentInParent<>() to find the SteamAudioDynamicObject attached to + // an ancestor of this GameObject. However, GetComponentInParent only returns "active" components, which in + // turn seem to be subject to the same behavior as activeInHierarchy (see above), so we have to manually walk + // the hierarchy upwards to find the first SteamAudioDynamicObject. + static SteamAudioDynamicObject GetDynamicObjectInParent(Transform obj) + { + if (obj == null) + return null; + + var dynamicObject = obj.gameObject.GetComponent(); + if (dynamicObject != null) + return dynamicObject; + + return GetDynamicObjectInParent(obj.parent); + } + + // Populates an array with the vertices associated with a GameObject, starting at a given offset. + static void GetVertices(GameObject gameObject, Vector3[] vertices, int offset, Transform transform) + { + var mesh = gameObject.GetComponent(); + var terrain = gameObject.GetComponent(); + + if (mesh != null) + { + var vertexArray = mesh.sharedMesh.vertices; + for (var i = 0; i < vertexArray.Length; ++i) + { + var transformedVertex = mesh.transform.TransformPoint(vertexArray[i]); + if (transform != null) + { + transformedVertex = transform.InverseTransformPoint(transformedVertex); + } + vertices[offset + i] = Common.ConvertVector(transformedVertex); + } + } + else if (terrain != null) + { + var terrainSimplificationLevel = GetTerrainSimplificationLevel(terrain); + + var w = terrain.terrainData.heightmapResolution; + var h = terrain.terrainData.heightmapResolution; + var s = Mathf.Min(w - 1, Mathf.Min(h - 1, (int)Mathf.Pow(2.0f, terrainSimplificationLevel))); + if (s == 0) + { + s = 1; + } + + w = ((w - 1) / s) + 1; + h = ((h - 1) / s) + 1; + + var heights = terrain.terrainData.GetHeights(0, 0, terrain.terrainData.heightmapResolution, + terrain.terrainData.heightmapResolution); + + var index = 0; + for (var v = 0; v < terrain.terrainData.heightmapResolution; v += s) + { + for (var u = 0; u < terrain.terrainData.heightmapResolution; u += s) + { + var height = heights[v, u]; + + var x = ((float) u / terrain.terrainData.heightmapResolution) * terrain.terrainData.size.x; + var y = height * terrain.terrainData.size.y; + var z = ((float) v / terrain.terrainData.heightmapResolution) * terrain.terrainData.size.z; + + var vertex = new UnityEngine.Vector3 { x = x, y = y, z = z }; + var transformedVertex = terrain.transform.TransformPoint(vertex); + if (transform != null) + { + transformedVertex = transform.InverseTransformPoint(transformedVertex); + } + vertices[offset + index] = Common.ConvertVector(transformedVertex); + ++index; + } + } + } + } + + // Populates an array with the triangles associated with a GameObject, starting at a given offset. + static void GetTriangles(GameObject gameObject, Triangle[] triangles, int offset) + { + var mesh = gameObject.GetComponent(); + var terrain = gameObject.GetComponent(); + + if (mesh != null) + { + var triangleArray = mesh.sharedMesh.triangles; + for (var i = 0; i < triangleArray.Length / 3; ++i) + { + triangles[offset + i].index0 = triangleArray[3 * i + 0]; + triangles[offset + i].index1 = triangleArray[3 * i + 1]; + triangles[offset + i].index2 = triangleArray[3 * i + 2]; + } + } + else if (terrain != null) + { + var terrainSimplificationLevel = GetTerrainSimplificationLevel(terrain); + + var w = terrain.terrainData.heightmapResolution; + var h = terrain.terrainData.heightmapResolution; + var s = Mathf.Min(w - 1, Mathf.Min(h - 1, (int)Mathf.Pow(2.0f, terrainSimplificationLevel))); + if (s == 0) + { + s = 1; + } + + w = ((w - 1) / s) + 1; + h = ((h - 1) / s) + 1; + + var index = 0; + for (var v = 0; v < h - 1; ++v) + { + for (var u = 0; u < w - 1; ++u) + { + var i0 = v * w + u; + var i1 = (v + 1) * w + u; + var i2 = v * w + (u + 1); + triangles[offset + index] = new Triangle + { + index0 = i0, + index1 = i1, + index2 = i2 + }; + + i0 = v * w + (u + 1); + i1 = (v + 1) * w + u; + i2 = (v + 1) * w + (u + 1); + triangles[offset + index + 1] = new Triangle + { + index0 = i0, + index1 = i1, + index2 = i2 + }; + + index += 2; + } + } + } + } + + // When multiple meshes are combined to form a single piece of geometry, each mesh will have + // 0-based triangle indices, even though the combined mesh will have a single vertex buffer. This + // function applies appropriate offsets to triangle indices so make all vertex indices correct. + static void FixupTriangleIndices(Triangle[] triangles, int startIndex, int endIndex, int indexOffset) + { + for (var i = startIndex; i < endIndex; ++i) + { + triangles[i].index0 += indexOffset; + triangles[i].index1 += indexOffset; + triangles[i].index2 += indexOffset; + } + } + + static float GetTerrainSimplificationLevel(Terrain terrain) + { + return terrain.GetComponentInParent().terrainSimplificationLevel; + } + + // Given an array of GameObjects, returns: a) an array containing all the unique materials referenced by + // them, and b) an array indicating for each GameObject, which material it references. + static void GetMaterialMapping(GameObject[] gameObjects, ref Material[] materials, ref int[] materialIndices) + { + var materialMapping = new Dictionary>(); + + // Loop through all the given GameObjects, and generate a dictionary mapping each material + // to a list of GameObjects that reference it. + for (var i = 0; i < gameObjects.Length; ++i) + { + var material = GetMaterialForGameObject(gameObjects[i]); + if (!materialMapping.ContainsKey(material)) + { + materialMapping.Add(material, new List()); + } + materialMapping[material].Add(i); + } + + materials = new Material[materialMapping.Keys.Count]; + materialIndices = new int[gameObjects.Length]; + + // Extract an array of unique materials and an array mapping GameObjects to materials. + var index = 0; + foreach (var material in materialMapping.Keys) + { + materials[index] = material; + foreach (var gameObjectIndex in materialMapping[material]) + { + materialIndices[gameObjectIndex] = index; + } + ++index; + } + } + + // Returns the Steam Audio material associated with a given GameObject. + static Material GetMaterialForGameObject(GameObject gameObject) + { + // Traverse the hierarchy upwards starting at this GameObject, until we find the + // first GameObject that has a Steam Audio Geometry component with a non-empty + // Material property. + var current = gameObject.transform; + while (current != null) + { + var geometry = current.gameObject.GetComponent(); + if (geometry != null && geometry.material != null) + { + return geometry.material.GetMaterial(); + } + + current = current.parent; + } + + // If we didn't find any such GameObject, use the default material specified in + // the Steam Audio Settings. + var defaultMaterial = SteamAudioSettings.Singleton.defaultMaterial; + if (defaultMaterial != null) + { + return SteamAudioSettings.Singleton.defaultMaterial.GetMaterial(); + } + + // The default material was set to null, so create a default material and use it. + Debug.LogWarning( + "A default material has not been set, using built-in default. Click Steam Audio > Settings " + + "to specify a default material."); + return ScriptableObject.CreateInstance().GetMaterial(); + } + + static string GetOBJFileName(UnityEngine.SceneManagement.Scene scene) + { + var fileName = ""; + +#if UNITY_EDITOR + fileName = EditorUtility.SaveFilePanelInProject("Export Scene to OBJ", scene.name, "obj", + "Select a file to export this scene's data to."); +#endif + + return fileName; + } + + static string GetOBJFileName(SteamAudioDynamicObject dynamicObject) + { + var fileName = ""; + +#if UNITY_EDITOR + fileName = EditorUtility.SaveFilePanelInProject("Export Dynamic Object to OBJ", dynamicObject.name, "obj", + "Select a file to export this dynamic object's data to."); +#endif + + return fileName; + } + + static SerializedData GetDataAsset(UnityEngine.SceneManagement.Scene scene) + { + SteamAudioStaticMesh steamAudioStaticMesh = null; + var rootObjects = scene.GetRootGameObjects(); + foreach (var rootObject in rootObjects) + { + steamAudioStaticMesh = rootObject.GetComponentInChildren(); + if (steamAudioStaticMesh != null) + break; + } + + if (steamAudioStaticMesh == null) + { + var activeScene = SceneManager.GetActiveScene(); + SceneManager.SetActiveScene(scene); + var rootObject = new GameObject("Steam Audio Static Mesh"); + steamAudioStaticMesh = rootObject.AddComponent(); +#if UNITY_EDITOR + EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); +#endif + SceneManager.SetActiveScene(activeScene); + } + + if (steamAudioStaticMesh.asset == null) + { + steamAudioStaticMesh.asset = SerializedData.PromptForNewAsset(scene.name); + steamAudioStaticMesh.sceneNameWhenExported = scene.name; + } + + return steamAudioStaticMesh.asset; + } + + static SerializedData GetDataAsset(SteamAudioDynamicObject dynamicObject) + { + return dynamicObject.asset; + } +#endif + } +} diff --git a/Scripts/Runtime/SteamAudioManager.cs.meta b/Scripts/Runtime/SteamAudioManager.cs.meta new file mode 100755 index 0000000..73721c1 --- /dev/null +++ b/Scripts/Runtime/SteamAudioManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b11066ff95bbf3344b868394742f7002 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioMaterial.cs b/Scripts/Runtime/SteamAudioMaterial.cs new file mode 100755 index 0000000..0c6759b --- /dev/null +++ b/Scripts/Runtime/SteamAudioMaterial.cs @@ -0,0 +1,55 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; + +namespace SteamAudio +{ + [CreateAssetMenu(menuName = "Steam Audio/Steam Audio Material")] + public class SteamAudioMaterial : ScriptableObject + { + [Header("Absorption")] + [Range(0.0f, 1.0f)] + public float lowFreqAbsorption = 0.1f; + [Range(0.0f, 1.0f)] + public float midFreqAbsorption = 0.1f; + [Range(0.0f, 1.0f)] + public float highFreqAbsorption = 0.1f; + [Header("Scattering")] + [Range(0.0f, 1.0f)] + public float scattering = 0.5f; + [Header("Transmission")] + [Range(0.0f, 1.0f)] + public float lowFreqTransmission = 0.1f; + [Range(0.0f, 1.0f)] + public float midFreqTransmission = 0.1f; + [Range(0.0f, 1.0f)] + public float highFreqTransmission = 0.1f; + + public Material GetMaterial() + { + var material = new Material { }; + material.absorptionLow = lowFreqAbsorption; + material.absorptionMid = midFreqAbsorption; + material.absorptionHigh = highFreqAbsorption; + material.scattering = scattering; + material.transmissionLow = lowFreqTransmission; + material.transmissionMid = midFreqTransmission; + material.transmissionHigh = highFreqTransmission; + return material; + } + } +} diff --git a/Scripts/Runtime/SteamAudioMaterial.cs.meta b/Scripts/Runtime/SteamAudioMaterial.cs.meta new file mode 100755 index 0000000..151bde7 --- /dev/null +++ b/Scripts/Runtime/SteamAudioMaterial.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1cb82a87a4954a947923856a12b49b38 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioProbeBatch.cs b/Scripts/Runtime/SteamAudioProbeBatch.cs new file mode 100755 index 0000000..3fd25f1 --- /dev/null +++ b/Scripts/Runtime/SteamAudioProbeBatch.cs @@ -0,0 +1,344 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace SteamAudio +{ + [Serializable] + public struct BakedDataLayerInfo + { + public GameObject gameObject; + public BakedDataIdentifier identifier; + public int dataSize; + } + + [AddComponentMenu("Steam Audio/Steam Audio Probe Batch")] + public class SteamAudioProbeBatch : MonoBehaviour + { + [Header("Placement Settings")] + public ProbeGenerationType placementStrategy = ProbeGenerationType.UniformFloor; + [Range(.1f, 50f)] + public float horizontalSpacing = 5f; + [Range(.1f, 20f)] + public float heightAboveFloor = 1.5f; + + [Header("Export Settings")] + public SerializedData asset = null; + + public int probeDataSize = 0; + [SerializeField] Sphere[] mProbeSpheres = null; + [SerializeField] List mBakedDataLayerInfo = new List(); + +#if STEAMAUDIO_ENABLED + ProbeBatch mProbeBatch = null; + + const float kProbeDrawSize = 0.1f; + + public SerializedData GetAsset() + { + if (asset == null) + { + asset = SerializedData.PromptForNewAsset(gameObject.scene.name + "_" + name); + } + + return asset; + } + + public int GetNumProbes() + { + return (mProbeSpheres == null) ? 0 : mProbeSpheres.Length; + } + + public int GetNumLayers() + { + return mBakedDataLayerInfo.Count; + } + + public IntPtr GetProbeBatch() + { + return mProbeBatch.Get(); + } + + private void Awake() + { + if (asset == null) + return; + + mProbeBatch = new ProbeBatch(SteamAudioManager.Context, asset); + mProbeBatch.Commit(); + } + + private void OnDestroy() + { + if (mProbeBatch != null) + { + mProbeBatch.Release(); + } + } + + private void OnEnable() + { + SteamAudioManager.Simulator.AddProbeBatch(mProbeBatch); + } + + private void OnDisable() + { + if (SteamAudioManager.Simulator != null) + { + SteamAudioManager.Simulator.RemoveProbeBatch(mProbeBatch); + } + } + + void OnDrawGizmosSelected() + { + var oldColor = Gizmos.color; + Gizmos.color = Color.magenta; + + var oldMatrix = Gizmos.matrix; + Gizmos.matrix = transform.localToWorldMatrix; + Gizmos.DrawWireCube(new UnityEngine.Vector3(0, 0, 0), new UnityEngine.Vector3(1, 1, 1)); + Gizmos.matrix = oldMatrix; + + Gizmos.color = Color.yellow; + if (mProbeSpheres != null) + { + for (var i = 0; i < mProbeSpheres.Length; ++i) + { + var center = Common.ConvertVector(mProbeSpheres[i].center); + Gizmos.DrawCube(center, new UnityEngine.Vector3(kProbeDrawSize, kProbeDrawSize, kProbeDrawSize)); + } + } + Gizmos.color = oldColor; + } + + public void GenerateProbes() + { + SteamAudioManager.Initialize(ManagerInitReason.GeneratingProbes); + SteamAudioManager.LoadScene(SceneManager.GetActiveScene(), SteamAudioManager.Context, false); + var scene = SteamAudioManager.CurrentScene; + + SteamAudioStaticMesh staticMeshComponent = null; + var rootObjects = SceneManager.GetActiveScene().GetRootGameObjects(); + foreach (var rootObject in rootObjects) + { + staticMeshComponent = rootObject.GetComponentInChildren(); + if (staticMeshComponent) + break; + } + + if (staticMeshComponent == null || staticMeshComponent.asset == null) + { + Debug.LogError(string.Format("Scene {0} has not been exported. Click Steam Audio > Export Active Scene to do so.", SceneManager.GetActiveScene().name)); + return; + } + + var staticMesh = new StaticMesh(SteamAudioManager.Context, scene, staticMeshComponent.asset); + staticMesh.AddToScene(scene); + + scene.Commit(); + + var probeArray = new ProbeArray(SteamAudioManager.Context); + + var probeGenerationParams = new ProbeGenerationParams { }; + probeGenerationParams.type = placementStrategy; + probeGenerationParams.spacing = horizontalSpacing; + probeGenerationParams.height = heightAboveFloor; + probeGenerationParams.transform = Common.TransposeMatrix(Common.ConvertTransform(gameObject.transform)); // Probe generation requires a transposed matrix. + + probeArray.GenerateProbes(scene, probeGenerationParams); + + var numProbes = probeArray.GetNumProbes(); + mProbeSpheres = new Sphere[numProbes]; + for (var i = 0; i < numProbes; ++i) + { + mProbeSpheres[i] = probeArray.GetProbe(i); + } + + var probeBatch = new ProbeBatch(SteamAudioManager.Context); + probeBatch.AddProbeArray(probeArray); + + probeDataSize = probeBatch.Save(GetAsset()); + + probeBatch.Release(); + probeArray.Release(); + staticMesh.Release(); + + SteamAudioManager.ShutDown(); + DestroyImmediate(SteamAudioManager.Singleton.gameObject); + + ResetLayers(); + + Debug.Log("Generated " + mProbeSpheres.Length + " probes for game object " + gameObject.name + "."); + + // Redraw scene view for probes to show up instantly. +#if UNITY_EDITOR + SceneView.RepaintAll(); +#endif + } + + public void DeleteBakedDataForIdentifier(BakedDataIdentifier identifier) + { + if (asset == null) + return; + + SteamAudioManager.Initialize(ManagerInitReason.EditingProbes); + + var probeBatch = new ProbeBatch(SteamAudioManager.Context, asset); + probeBatch.RemoveData(identifier); + probeDataSize = probeBatch.Save(asset); + probeBatch.Release(); + + SteamAudioManager.ShutDown(); + DestroyImmediate(SteamAudioManager.Singleton.gameObject); + + RemoveLayer(identifier); + } + + public int GetSizeForLayer(BakedDataIdentifier identifier) + { + var layerInfo = new BakedDataLayerInfo { }; + if (FindLayer(identifier, ref layerInfo)) + { + return layerInfo.dataSize; + } + else + { + return 0; + } + } + + public BakedDataLayerInfo GetInfoForLayer(int index) + { + return mBakedDataLayerInfo[index]; + } + + public void ResetLayers() + { + mBakedDataLayerInfo.Clear(); + } + + public void AddLayer(GameObject gameObject, BakedDataIdentifier identifier, int dataSize) + { + var layerInfo = new BakedDataLayerInfo { }; + layerInfo.gameObject = gameObject; + layerInfo.identifier = identifier; + layerInfo.dataSize = dataSize; + + mBakedDataLayerInfo.Add(layerInfo); + } + + public void UpdateLayer(BakedDataIdentifier identifier, int dataSize) + { + var layerInfo = new BakedDataLayerInfo { }; + if (FindLayer(identifier, ref layerInfo)) + { + layerInfo.dataSize = dataSize; + } + } + + public void RemoveLayer(BakedDataIdentifier identifier) + { + var layerInfo = new BakedDataLayerInfo { }; + if (FindLayer(identifier, ref layerInfo)) + { + mBakedDataLayerInfo.Remove(layerInfo); + UpdateGameObjectStatistics(layerInfo); + } + } + + public void AddOrUpdateLayer(GameObject gameObject, BakedDataIdentifier identifier, int dataSize) + { + var layerInfo = new BakedDataLayerInfo { }; + if (FindLayer(identifier, ref layerInfo)) + { + UpdateLayer(identifier, dataSize); + } + else + { + AddLayer(gameObject, identifier, dataSize); + } + } + + bool FindLayer(BakedDataIdentifier identifier, ref BakedDataLayerInfo result) + { + foreach (var layerInfo in mBakedDataLayerInfo) + { + if (layerInfo.identifier.Equals(identifier)) + { + result = layerInfo; + return true; + } + } + + return false; + } + + void UpdateGameObjectStatistics(BakedDataLayerInfo layerInfo) + { + if (layerInfo.identifier.type == BakedDataType.Reflections) + { + switch (layerInfo.identifier.variation) + { + case BakedDataVariation.Reverb: + layerInfo.gameObject.GetComponent().UpdateBakedDataStatistics(); + break; + + case BakedDataVariation.StaticSource: + layerInfo.gameObject.GetComponent().UpdateBakedDataStatistics(); + break; + + case BakedDataVariation.StaticListener: + layerInfo.gameObject.GetComponent().UpdateBakedDataStatistics(); + break; + } + } + } + + BakedDataIdentifier GetBakedDataIdentifier() + { + var identifier = new BakedDataIdentifier { }; + identifier.type = BakedDataType.Pathing; + identifier.variation = BakedDataVariation.Dynamic; + return identifier; + } + + public void BeginBake() + { + var tasks = new BakedDataTask[1]; + tasks[0].gameObject = gameObject; + tasks[0].component = this; + tasks[0].name = gameObject.name; + tasks[0].identifier = GetBakedDataIdentifier(); + tasks[0].probeBatches = new SteamAudioProbeBatch[1]; + tasks[0].probeBatchNames = new string[1]; + tasks[0].probeBatchAssets = new SerializedData[1]; + + tasks[0].probeBatches[0] = this; + tasks[0].probeBatchNames[0] = gameObject.name; + tasks[0].probeBatchAssets[0] = GetAsset(); + + Baker.BeginBake(tasks); + } +#endif + } +} diff --git a/Scripts/Runtime/SteamAudioProbeBatch.cs.meta b/Scripts/Runtime/SteamAudioProbeBatch.cs.meta new file mode 100755 index 0000000..c607be9 --- /dev/null +++ b/Scripts/Runtime/SteamAudioProbeBatch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 286962cac82a4fa4e9ec38ab663c9578 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioSettings.cs b/Scripts/Runtime/SteamAudioSettings.cs new file mode 100755 index 0000000..54368e2 --- /dev/null +++ b/Scripts/Runtime/SteamAudioSettings.cs @@ -0,0 +1,163 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace SteamAudio +{ + public enum AudioEngineType + { + Unity, + FMODStudio + } + + [CreateAssetMenu(menuName = "Steam Audio/Steam Audio Settings")] + public class SteamAudioSettings : ScriptableObject + { + [Header("Audio Engine Settings")] + public AudioEngineType audioEngine = AudioEngineType.Unity; + + [Header("HRTF Settings")] + public bool perspectiveCorrection = false; + [Range(.25f, 4.0f)] + public float perspectiveCorrectionFactor = 1.0f; + [Range(-12.0f, 12.0f)] + public float hrtfVolumeGainDB = 0.0f; + public HRTFNormType hrtfNormalizationType = HRTFNormType.None; + public SOFAFile[] SOFAFiles = null; + + [Header("Material Settings")] + public SteamAudioMaterial defaultMaterial = null; + + [Header("Ray Tracer Settings")] + public SceneType sceneType = SceneType.Default; + public LayerMask layerMask = new LayerMask(); + + [Header("Occlusion Settings")] + [Range(1, 128)] + public int maxOcclusionSamples = 16; + + [Header("Real-time Reflections Settings")] + [Range(1024, 65536)] + public int realTimeRays = 4096; + [Range(1, 64)] + public int realTimeBounces = 4; + [Range(0.1f, 10.0f)] + public float realTimeDuration = 1.0f; + [Range(0, 3)] + public int realTimeAmbisonicOrder = 1; + [Range(1, 128)] + public int realTimeMaxSources = 32; + [Range(0, 100)] + public int realTimeCPUCoresPercentage = 5; + [Range(0.1f, 10.0f)] + public float realTimeIrradianceMinDistance = 1.0f; + + [Header("Baked Reflections Settings")] + public bool bakeConvolution = true; + public bool bakeParametric = false; + [Range(1024, 65536)] + public int bakingRays = 16384; + [Range(1, 64)] + public int bakingBounces = 16; + [Range(0.1f, 10.0f)] + public float bakingDuration = 1.0f; + [Range(0, 3)] + public int bakingAmbisonicOrder = 1; + [Range(0, 100)] + public int bakingCPUCoresPercentage = 50; + [Range(0.1f, 10.0f)] + public float bakingIrradianceMinDistance = 1.0f; + + [Header("Baked Pathing Settings")] + [Range(1, 32)] + public int bakingVisibilitySamples = 4; + [Range(0.0f, 2.0f)] + public float bakingVisibilityRadius = 1.0f; + [Range(0.0f, 1.0f)] + public float bakingVisibilityThreshold = 0.1f; + [Range(0.0f, 1000.0f)] + public float bakingVisibilityRange = 1000.0f; + [Range(0.0f, 1000.0f)] + public float bakingPathRange = 1000.0f; + [Range(0, 100)] + public int bakedPathingCPUCoresPercentage = 50; + + [Header("Simulation Update Settings")] + [Range(0.1f, 1.0f)] + public float simulationUpdateInterval = 0.1f; + + [Header("Reflection Effect Settings")] + public ReflectionEffectType reflectionEffectType = ReflectionEffectType.Convolution; + + [Header("Hybrid Reverb Settings")] + [Range(0.1f, 2.0f)] + public float hybridReverbTransitionTime = 1.0f; + [Range(0, 100)] + public int hybridReverbOverlapPercent = 25; + + [Header("OpenCL Settings")] + public OpenCLDeviceType deviceType = OpenCLDeviceType.GPU; + [Range(0, 16)] + public int maxReservedComputeUnits = 8; + [Range(0.0f, 1.0f)] + public float fractionComputeUnitsForIRUpdate = 0.5f; + + [Header("Radeon Rays Settings")] + [Range(1, 16)] + public int bakingBatchSize = 8; + + [Header("TrueAudio Next Settings")] + [Range(0.1f, 10.0f)] + public float TANDuration = 1.0f; + [Range(0, 3)] + public int TANAmbisonicOrder = 1; + [Range(1, 128)] + public int TANMaxSources = 32; + + [Header("Advanced Settings")] + public bool EnableValidation = false; + + static SteamAudioSettings sSingleton = null; + + public static SteamAudioSettings Singleton + { + get + { + if (sSingleton == null) + { + sSingleton = Resources.Load("SteamAudioSettings"); + if (sSingleton == null) + { + sSingleton = CreateInstance(); + sSingleton.name = "Steam Audio Settings"; + +#if UNITY_EDITOR + sSingleton.defaultMaterial = (SteamAudioMaterial) AssetDatabase.LoadAssetAtPath("Assets/Plugins/SteamAudio/Resources/Materials/Default.asset", typeof(SteamAudioMaterial)); + + AssetDatabase.CreateAsset(sSingleton, "Assets/Plugins/SteamAudio/Resources/SteamAudioSettings.asset"); +#endif + } + } + + return sSingleton; + } + } + } +} diff --git a/Scripts/Runtime/SteamAudioSettings.cs.meta b/Scripts/Runtime/SteamAudioSettings.cs.meta new file mode 100755 index 0000000..60d7418 --- /dev/null +++ b/Scripts/Runtime/SteamAudioSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f3efcebd75ef2af49badc83215c91685 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - defaultMaterial: {fileID: 11400000, guid: a086f686223eed942816c70be67841b0, type: 2} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioSource.cs b/Scripts/Runtime/SteamAudioSource.cs new file mode 100755 index 0000000..d6a5184 --- /dev/null +++ b/Scripts/Runtime/SteamAudioSource.cs @@ -0,0 +1,544 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using AOT; +using System; +using System.Runtime.InteropServices; +using UnityEngine; + +namespace SteamAudio +{ + public enum DistanceAttenuationInput + { + CurveDriven, + PhysicsBased + } + + public enum AirAbsorptionInput + { + SimulationDefined, + UserDefined + } + + public enum DirectivityInput + { + SimulationDefined, + UserDefined + } + + public enum OcclusionInput + { + SimulationDefined, + UserDefined + } + + public enum TransmissionInput + { + SimulationDefined, + UserDefined + } + + public enum ReflectionsType + { + Realtime, + BakedStaticSource, + BakedStaticListener + } + + public struct AudioSourceAttenuationData + { + public AudioRolloffMode rolloffMode; + public float minDistance; + public float maxDistance; + public AnimationCurve curve; + } + + [AddComponentMenu("Steam Audio/Steam Audio Source")] + public class SteamAudioSource : MonoBehaviour + { + [Header("HRTF Settings")] + public bool directBinaural = true; + public HRTFInterpolation interpolation = HRTFInterpolation.Nearest; + public bool perspectiveCorrection = false; + + [Header("Attenuation Settings")] + public bool distanceAttenuation = false; + public DistanceAttenuationInput distanceAttenuationInput = DistanceAttenuationInput.CurveDriven; + public float distanceAttenuationValue = 1.0f; + public bool airAbsorption = false; + public AirAbsorptionInput airAbsorptionInput = AirAbsorptionInput.SimulationDefined; + [Range(0.0f, 1.0f)] + public float airAbsorptionLow = 1.0f; + [Range(0.0f, 1.0f)] + public float airAbsorptionMid = 1.0f; + [Range(0.0f, 1.0f)] + public float airAbsorptionHigh = 1.0f; + + [Header("Directivity Settings")] + public bool directivity = false; + public DirectivityInput directivityInput = DirectivityInput.SimulationDefined; + [Range(0.0f, 1.0f)] + public float dipoleWeight = 0.0f; + [Range(0.0f, 4.0f)] + public float dipolePower = 0.0f; + [Range(0.0f, 1.0f)] + public float directivityValue = 1.0f; + + [Header("Occlusion Settings")] + public bool occlusion = false; + public OcclusionInput occlusionInput = OcclusionInput.SimulationDefined; + public OcclusionType occlusionType = OcclusionType.Raycast; + [Range(0.0f, 4.0f)] + public float occlusionRadius = 1.0f; + [Range(1, 128)] + public int occlusionSamples = 16; + [Range(0.0f, 1.0f)] + public float occlusionValue = 1.0f; + public bool transmission = false; + public TransmissionType transmissionType = TransmissionType.FrequencyIndependent; + public TransmissionInput transmissionInput = TransmissionInput.SimulationDefined; + [Range(0.0f, 1.0f)] + public float transmissionLow = 1.0f; + [Range(0.0f, 1.0f)] + public float transmissionMid = 1.0f; + [Range(0.0f, 1.0f)] + public float transmissionHigh = 1.0f; + [Range(1, 8)] + public int maxTransmissionSurfaces = 1; + + [Header("Direct Mix Settings")] + [Range(0.0f, 1.0f)] + public float directMixLevel = 1.0f; + + [Header("Reflections Settings")] + public bool reflections = false; + public ReflectionsType reflectionsType = ReflectionsType.Realtime; + public bool useDistanceCurveForReflections = false; + public SteamAudioBakedSource currentBakedSource = null; + public IntPtr reflectionsIR = IntPtr.Zero; + public float reverbTimeLow = 0.0f; + public float reverbTimeMid = 0.0f; + public float reverbTimeHigh = 0.0f; + public float hybridReverbEQLow = 1.0f; + public float hybridReverbEQMid = 1.0f; + public float hybridReverbEQHigh = 1.0f; + public int hybridReverbDelay = 0; + public bool applyHRTFToReflections = false; + [Range(0.0f, 10.0f)] + public float reflectionsMixLevel = 1.0f; + + [Header("Pathing Settings")] + public bool pathing = false; + public SteamAudioProbeBatch pathingProbeBatch = null; + public bool pathValidation = true; + public bool findAlternatePaths = true; + public float[] pathingEQ = new float[3] { 1.0f, 1.0f, 1.0f }; + public float[] pathingSH = new float[16]; + public bool applyHRTFToPathing = false; + [Range(0.0f, 10.0f)] + public float pathingMixLevel = 1.0f; + +#if STEAMAUDIO_ENABLED + Simulator mSimulator = null; + Source mSource = null; + AudioEngineSource mAudioEngineSource = null; + UnityEngine.Vector3[] mSphereVertices = null; + UnityEngine.Vector3[] mDeformedSphereVertices = null; + Mesh mDeformedSphereMesh = null; + + AudioSource mAudioSource = null; + AudioSourceAttenuationData mAttenuationData = new AudioSourceAttenuationData { }; + DistanceAttenuationModel mCurveAttenuationModel = new DistanceAttenuationModel { }; + GCHandle mThis; + SteamAudioSettings mSettings = null; + + private void Awake() + { + mSimulator = SteamAudioManager.Simulator; + + var settings = SteamAudioManager.GetSimulationSettings(false); + mSource = new Source(SteamAudioManager.Simulator, settings); + mSettings = SteamAudioSettings.Singleton; + + mAudioEngineSource = AudioEngineSource.Create(mSettings.audioEngine); + if (mAudioEngineSource != null) + { + mAudioEngineSource.Initialize(gameObject); + mAudioEngineSource.UpdateParameters(this); + } + + mAudioSource = GetComponent(); + + mThis = GCHandle.Alloc(this); + + if (mSettings.audioEngine == AudioEngineType.Unity && + distanceAttenuation && + distanceAttenuationInput == DistanceAttenuationInput.CurveDriven && + reflections && + useDistanceCurveForReflections) + { + mAttenuationData.rolloffMode = mAudioSource.rolloffMode; + mAttenuationData.minDistance = mAudioSource.minDistance; + mAttenuationData.maxDistance = mAudioSource.maxDistance; + mAttenuationData.curve = mAudioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff); + + mCurveAttenuationModel.type = DistanceAttenuationModelType.Callback; + mCurveAttenuationModel.callback = EvaluateDistanceCurve; + mCurveAttenuationModel.userData = GCHandle.ToIntPtr(mThis); + mCurveAttenuationModel.dirty = Bool.False; + } + } + + private void Start() + { + if (mAudioEngineSource != null) + { + mAudioEngineSource.UpdateParameters(this); + } + } + + private void OnDestroy() + { + if (mAudioEngineSource != null) + { + mAudioEngineSource.Destroy(); + mAudioEngineSource = null; + } + + if (mSource != null) + { + mSource.Release(); + mSource = null; + } + } + + ~SteamAudioSource() + { + mThis.Free(); + } + + private void OnEnable() + { + mSource.AddToSimulator(mSimulator); + SteamAudioManager.AddSource(this); + + if (mAudioEngineSource != null) + { + mAudioEngineSource.UpdateParameters(this); + } + } + + private void OnDisable() + { + SteamAudioManager.RemoveSource(this); + mSource.RemoveFromSimulator(mSimulator); + } + + private void Update() + { + if (mAudioEngineSource != null) + { + mAudioEngineSource.UpdateParameters(this); + } + } + + private void OnDrawGizmosSelected() + { + if (directivity && directivityInput == DirectivityInput.SimulationDefined && dipoleWeight > 0.0f) + { + if (mDeformedSphereMesh == null) + { + InitializeDeformedSphereMesh(32, 32); + } + + DeformSphereMesh(); + + var oldColor = Gizmos.color; + Gizmos.color = Color.red; + Gizmos.DrawWireMesh(mDeformedSphereMesh, transform.position, transform.rotation); + Gizmos.color = oldColor; + } + } + + public void SetInputs(SimulationFlags flags) + { + var listener = SteamAudioManager.GetSteamAudioListener(); + + var inputs = new SimulationInputs { }; + inputs.source.origin = Common.ConvertVector(transform.position); + inputs.source.ahead = Common.ConvertVector(transform.forward); + inputs.source.up = Common.ConvertVector(transform.up); + inputs.source.right = Common.ConvertVector(transform.right); + + if (mSettings.audioEngine == AudioEngineType.Unity && + distanceAttenuation && + distanceAttenuationInput == DistanceAttenuationInput.CurveDriven && + reflections && + useDistanceCurveForReflections) + { + inputs.distanceAttenuationModel = mCurveAttenuationModel; + } + else + { + inputs.distanceAttenuationModel.type = DistanceAttenuationModelType.Default; + } + + inputs.airAbsorptionModel.type = AirAbsorptionModelType.Default; + inputs.directivity.dipoleWeight = dipoleWeight; + inputs.directivity.dipolePower = dipolePower; + inputs.occlusionType = occlusionType; + inputs.occlusionRadius = occlusionRadius; + inputs.numOcclusionSamples = occlusionSamples; + inputs.numTransmissionRays = maxTransmissionSurfaces; + inputs.reverbScaleLow = 1.0f; + inputs.reverbScaleMid = 1.0f; + inputs.reverbScaleHigh = 1.0f; + inputs.hybridReverbTransitionTime = mSettings.hybridReverbTransitionTime; + inputs.hybridReverbOverlapPercent = mSettings.hybridReverbOverlapPercent / 100.0f; + inputs.baked = (reflectionsType != ReflectionsType.Realtime) ? Bool.True : Bool.False; + inputs.pathingProbes = (pathingProbeBatch != null) ? pathingProbeBatch.GetProbeBatch() : IntPtr.Zero; + inputs.visRadius = mSettings.bakingVisibilityRadius; + inputs.visThreshold = mSettings.bakingVisibilityThreshold; + inputs.visRange = mSettings.bakingVisibilityRange; + inputs.pathingOrder = mSettings.bakingAmbisonicOrder; + inputs.enableValidation = pathValidation ? Bool.True : Bool.False; + inputs.findAlternatePaths = findAlternatePaths ? Bool.True : Bool.False; + + if (reflectionsType == ReflectionsType.BakedStaticSource) + { + if (currentBakedSource != null) + { + inputs.bakedDataIdentifier = currentBakedSource.GetBakedDataIdentifier(); + } + } + else if (reflectionsType == ReflectionsType.BakedStaticListener) + { + if (listener != null && listener.currentBakedListener != null) + { + inputs.bakedDataIdentifier = listener.currentBakedListener.GetBakedDataIdentifier(); + } + } + + inputs.flags = SimulationFlags.Direct; + if (reflections) + { + if ((reflectionsType == ReflectionsType.Realtime) || + (reflectionsType == ReflectionsType.BakedStaticSource && currentBakedSource != null) || + (reflectionsType == ReflectionsType.BakedStaticListener && listener != null && listener.currentBakedListener != null)) + { + inputs.flags = inputs.flags | SimulationFlags.Reflections; + } + } + if (pathing) + { + if (pathingProbeBatch == null) + { + pathing = false; + Debug.LogWarningFormat("Pathing probe batch not set, disabling pathing for source {0}.", gameObject.name); + } + else + { + inputs.flags = inputs.flags | SimulationFlags.Pathing; + } + } + + inputs.directFlags = 0; + if (distanceAttenuation) + inputs.directFlags = inputs.directFlags | DirectSimulationFlags.DistanceAttenuation; + if (airAbsorption) + inputs.directFlags = inputs.directFlags | DirectSimulationFlags.AirAbsorption; + if (directivity) + inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Directivity; + if (occlusion) + inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Occlusion; + if (transmission) + inputs.directFlags = inputs.directFlags | DirectSimulationFlags.Transmission; + + mSource.SetInputs(flags, inputs); + } + + public SimulationOutputs GetOutputs(SimulationFlags flags) + { + return mSource.GetOutputs(flags); + } + + public Source GetSource() + { + return mSource; + } + + public void UpdateOutputs(SimulationFlags flags) + { + var outputs = mSource.GetOutputs(flags); + + if (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity && + ((flags & SimulationFlags.Direct) != 0)) + { + if (distanceAttenuation && distanceAttenuationInput == DistanceAttenuationInput.PhysicsBased) + { + distanceAttenuationValue = outputs.direct.distanceAttenuation; + } + + if (airAbsorption && airAbsorptionInput == AirAbsorptionInput.SimulationDefined) + { + airAbsorptionLow = outputs.direct.airAbsorptionLow; + airAbsorptionMid = outputs.direct.airAbsorptionMid; + airAbsorptionHigh = outputs.direct.airAbsorptionHigh; + } + + if (directivity && directivityInput == DirectivityInput.SimulationDefined) + { + directivityValue = outputs.direct.directivity; + } + + if (occlusion && occlusionInput == OcclusionInput.SimulationDefined) + { + occlusionValue = outputs.direct.occlusion; + } + + if (transmission && transmissionInput == TransmissionInput.SimulationDefined) + { + transmissionLow = outputs.direct.transmissionLow; + transmissionMid = outputs.direct.transmissionMid; + transmissionHigh = outputs.direct.transmissionHigh; + } + } + + if (pathing && ((flags & SimulationFlags.Pathing) != 0)) + { + outputs.pathing.eqCoeffsLow = Mathf.Max(0.1f, outputs.pathing.eqCoeffsLow); + outputs.pathing.eqCoeffsMid = Mathf.Max(0.1f, outputs.pathing.eqCoeffsMid); + outputs.pathing.eqCoeffsHigh = Mathf.Max(0.1f, outputs.pathing.eqCoeffsHigh); + } + } + + void InitializeDeformedSphereMesh(int nPhi, int nTheta) + { + var dPhi = (2.0f * Mathf.PI) / nPhi; + var dTheta = Mathf.PI / nTheta; + + mSphereVertices = new UnityEngine.Vector3[nPhi * nTheta]; + var index = 0; + for (var i = 0; i < nPhi; ++i) + { + var phi = i * dPhi; + for (var j = 0; j < nTheta; ++j) + { + var theta = (j * dTheta) - (0.5f * Mathf.PI); + + var x = Mathf.Cos(theta) * Mathf.Sin(phi); + var y = Mathf.Sin(theta); + var z = Mathf.Cos(theta) * -Mathf.Cos(phi); + + var vertex = new UnityEngine.Vector3(x, y, z); + + mSphereVertices[index++] = vertex; + } + } + + mDeformedSphereVertices = new UnityEngine.Vector3[nPhi * nTheta]; + Array.Copy(mSphereVertices, mDeformedSphereVertices, mSphereVertices.Length); + + var indices = new int[6 * nPhi * (nTheta - 1)]; + index = 0; + for (var i = 0; i < nPhi; ++i) + { + for (var j = 0; j < nTheta - 1; ++j) + { + var i0 = i * nTheta + j; + var i1 = i * nTheta + (j + 1); + var i2 = ((i + 1) % nPhi) * nTheta + (j + 1); + var i3 = ((i + 1) % nPhi) * nTheta + j; + + indices[index++] = i0; + indices[index++] = i1; + indices[index++] = i2; + indices[index++] = i0; + indices[index++] = i2; + indices[index++] = i3; + } + } + + mDeformedSphereMesh = new Mesh(); + mDeformedSphereMesh.vertices = mDeformedSphereVertices; + mDeformedSphereMesh.triangles = indices; + mDeformedSphereMesh.RecalculateNormals(); + } + + void DeformSphereMesh() + { + for (var i = 0; i < mSphereVertices.Length; ++i) + { + mDeformedSphereVertices[i] = DeformedVertex(mSphereVertices[i]); + } + + mDeformedSphereMesh.vertices = mDeformedSphereVertices; + } + + UnityEngine.Vector3 DeformedVertex(UnityEngine.Vector3 vertex) + { + var cosine = vertex.z; + var r = Mathf.Pow(Mathf.Abs((1.0f - dipoleWeight) + dipoleWeight * cosine), dipolePower); + var deformedVertex = vertex; + deformedVertex.Scale(new UnityEngine.Vector3(r, r, r)); + return deformedVertex; + } + + [MonoPInvokeCallback(typeof(DistanceAttenuationCallback))] + public static float EvaluateDistanceCurve(float distance, IntPtr userData) + { + var target = (SteamAudioSource) GCHandle.FromIntPtr(userData).Target; + + var rMin = target.mAttenuationData.minDistance; + var rMax = target.mAttenuationData.maxDistance; + + switch (target.mAttenuationData.rolloffMode) + { + case AudioRolloffMode.Logarithmic: + if (distance < rMin) + return 1.0f; + else if (distance < rMax) + return 0.0f; + else + return rMin / distance; + + case AudioRolloffMode.Linear: + if (distance < rMin) + return 1.0f; + else if (distance > rMax) + return 0.0f; + else + return (rMax - distance) / (rMax - rMin); + + case AudioRolloffMode.Custom: +#if UNITY_2018_1_OR_NEWER + return target.mAttenuationData.curve.Evaluate(distance / rMax); +#else + if (distance < rMin) + return 1.0f; + else if (distance > rMax) + return 0.0f; + else + return rMin / distance; +#endif + + default: + return 0.0f; + } + } +#endif + } +} diff --git a/Scripts/Runtime/SteamAudioSource.cs.meta b/Scripts/Runtime/SteamAudioSource.cs.meta new file mode 100755 index 0000000..8b31d4f --- /dev/null +++ b/Scripts/Runtime/SteamAudioSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 59c3684b22f00604a97bb68037fcf4cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/SteamAudioStaticMesh.cs b/Scripts/Runtime/SteamAudioStaticMesh.cs new file mode 100755 index 0000000..adb2e68 --- /dev/null +++ b/Scripts/Runtime/SteamAudioStaticMesh.cs @@ -0,0 +1,80 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using UnityEngine; + +namespace SteamAudio +{ + public class SteamAudioStaticMesh : MonoBehaviour + { + [Header("Export Settings")] + public SerializedData asset = null; + public string sceneNameWhenExported = ""; + +#if STEAMAUDIO_ENABLED + StaticMesh mStaticMesh = null; + + void Start() + { + if (asset == null) + { + Debug.LogWarningFormat("No asset set for Steam Audio Static Mesh in scene {0}. Export the scene before clicking Play.", + gameObject.scene.name); + } + } + + void OnDestroy() + { + if (mStaticMesh != null) + { + mStaticMesh.Release(); + } + } + + void OnEnable() + { + if (mStaticMesh != null) + { + mStaticMesh.AddToScene(SteamAudioManager.CurrentScene); + SteamAudioManager.ScheduleCommitScene(); + } + } + + void OnDisable() + { + if (mStaticMesh != null && SteamAudioManager.CurrentScene != null) + { + mStaticMesh.RemoveFromScene(SteamAudioManager.CurrentScene); + SteamAudioManager.ScheduleCommitScene(); + } + } + + void Update() + { + if (mStaticMesh == null && asset != null) + { + mStaticMesh = new StaticMesh(SteamAudioManager.Context, SteamAudioManager.CurrentScene, asset); + + if (enabled) + { + mStaticMesh.AddToScene(SteamAudioManager.CurrentScene); + SteamAudioManager.ScheduleCommitScene(); + } + } + } +#endif + } +} diff --git a/Scripts/Runtime/SteamAudioStaticMesh.cs.meta b/Scripts/Runtime/SteamAudioStaticMesh.cs.meta new file mode 100755 index 0000000..bd774c4 --- /dev/null +++ b/Scripts/Runtime/SteamAudioStaticMesh.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8173b2a8dbe2d2d48995bb2ba9a49ff1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/TrueAudioNextDevice.cs b/Scripts/Runtime/TrueAudioNextDevice.cs new file mode 100755 index 0000000..ede43d5 --- /dev/null +++ b/Scripts/Runtime/TrueAudioNextDevice.cs @@ -0,0 +1,58 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; + +namespace SteamAudio +{ + public class TrueAudioNextDevice + { + IntPtr mTrueAudioNextDevice = IntPtr.Zero; + + public TrueAudioNextDevice(OpenCLDevice openCLDevice, int frameSize, int irSize, int order, int maxSources) + { + var deviceSettings = new TrueAudioNextDeviceSettings { }; + deviceSettings.frameSize = frameSize; + deviceSettings.irSize = irSize; + deviceSettings.order = order; + deviceSettings.maxSources = maxSources; + + var status = API.iplTrueAudioNextDeviceCreate(openCLDevice.Get(), ref deviceSettings, out mTrueAudioNextDevice); + if (status != Error.Success) + throw new Exception(string.Format("Unable to create TrueAudio Next device. [{0}]", status)); + } + + public TrueAudioNextDevice(TrueAudioNextDevice device) + { + mTrueAudioNextDevice = API.iplTrueAudioNextDeviceRetain(device.mTrueAudioNextDevice); + } + + ~TrueAudioNextDevice() + { + Release(); + } + + public void Release() + { + API.iplTrueAudioNextDeviceRelease(ref mTrueAudioNextDevice); + } + + public IntPtr Get() + { + return mTrueAudioNextDevice; + } + } +} diff --git a/Scripts/Runtime/TrueAudioNextDevice.cs.meta b/Scripts/Runtime/TrueAudioNextDevice.cs.meta new file mode 100755 index 0000000..0d7a5f1 --- /dev/null +++ b/Scripts/Runtime/TrueAudioNextDevice.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fdd785831c5dd8c43ab06d5c23bb56c6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs b/Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs new file mode 100755 index 0000000..c1ad6e3 --- /dev/null +++ b/Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs @@ -0,0 +1,40 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public sealed class UnityAudioEngineAmbisonicSource : AudioEngineAmbisonicSource + { + AudioSource mAudioSource = null; + + public override void Initialize(GameObject gameObject) + { + mAudioSource = gameObject.GetComponent(); + } + + public override void UpdateParameters(SteamAudioAmbisonicSource ambisonicSource) + { + if (!mAudioSource) + return; + + var index = 0; + mAudioSource.SetAmbisonicDecoderFloat(index++, (ambisonicSource.applyHRTF) ? 1.0f : 0.0f); + } + } +} diff --git a/Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs.meta b/Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs.meta new file mode 100755 index 0000000..8e321a4 --- /dev/null +++ b/Scripts/Runtime/UnityAudioEngineAmbisonicSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c6e7b360f01d93347b477af15e75be7f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/UnityAudioEngineSource.cs b/Scripts/Runtime/UnityAudioEngineSource.cs new file mode 100755 index 0000000..1e36873 --- /dev/null +++ b/Scripts/Runtime/UnityAudioEngineSource.cs @@ -0,0 +1,94 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public sealed class UnityAudioEngineSource : AudioEngineSource + { + AudioSource mAudioSource = null; + SteamAudioSource mSteamAudioSource = null; + int mHandle = -1; + + public override void Initialize(GameObject gameObject) + { + mAudioSource = gameObject.GetComponent(); + + mSteamAudioSource = gameObject.GetComponent(); + if (mSteamAudioSource) + { + mHandle = API.iplUnityAddSource(mSteamAudioSource.GetSource().Get()); + } + } + + public override void Destroy() + { + var index = 28; + mAudioSource.SetSpatializerFloat(index, -1); + + if (mSteamAudioSource) + { + API.iplUnityRemoveSource(mHandle); + } + } + + public override void UpdateParameters(SteamAudioSource source) + { + if (!mAudioSource) + return; + + var index = 0; + mAudioSource.SetSpatializerFloat(index++, (source.distanceAttenuation) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (source.airAbsorption) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (source.directivity) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (source.occlusion) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (source.transmission) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (source.reflections) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (source.pathing) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, (float) source.interpolation); + mAudioSource.SetSpatializerFloat(index++, source.distanceAttenuationValue); + mAudioSource.SetSpatializerFloat(index++, (source.distanceAttenuationInput == DistanceAttenuationInput.CurveDriven) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, source.airAbsorptionLow); + mAudioSource.SetSpatializerFloat(index++, source.airAbsorptionMid); + mAudioSource.SetSpatializerFloat(index++, source.airAbsorptionHigh); + mAudioSource.SetSpatializerFloat(index++, (source.airAbsorptionInput == AirAbsorptionInput.UserDefined) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, source.directivityValue); + mAudioSource.SetSpatializerFloat(index++, source.dipoleWeight); + mAudioSource.SetSpatializerFloat(index++, source.dipolePower); + mAudioSource.SetSpatializerFloat(index++, (source.directivityInput == DirectivityInput.UserDefined) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, source.occlusionValue); + mAudioSource.SetSpatializerFloat(index++, (float) source.transmissionType); + mAudioSource.SetSpatializerFloat(index++, source.transmissionLow); + mAudioSource.SetSpatializerFloat(index++, source.transmissionMid); + mAudioSource.SetSpatializerFloat(index++, source.transmissionHigh); + mAudioSource.SetSpatializerFloat(index++, source.directMixLevel); + mAudioSource.SetSpatializerFloat(index++, (source.applyHRTFToReflections) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, source.reflectionsMixLevel); + mAudioSource.SetSpatializerFloat(index++, (source.applyHRTFToPathing) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, source.pathingMixLevel); + index++; // Skip 2 deprecated params. + index++; + mAudioSource.SetSpatializerFloat(index++, (source.directBinaural) ? 1.0f : 0.0f); + mAudioSource.SetSpatializerFloat(index++, mHandle); + mAudioSource.SetSpatializerFloat(index++, (source.perspectiveCorrection) ? 1.0f : 0.0f); + } + } +} + +#endif diff --git a/Scripts/Runtime/UnityAudioEngineSource.cs.meta b/Scripts/Runtime/UnityAudioEngineSource.cs.meta new file mode 100755 index 0000000..c596f31 --- /dev/null +++ b/Scripts/Runtime/UnityAudioEngineSource.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 92cc150395b3d034aa2e8fc975634251 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Runtime/UnityAudioEngineState.cs b/Scripts/Runtime/UnityAudioEngineState.cs new file mode 100755 index 0000000..2f72e81 --- /dev/null +++ b/Scripts/Runtime/UnityAudioEngineState.cs @@ -0,0 +1,76 @@ +// +// Copyright 2017-2023 Valve Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#if STEAMAUDIO_ENABLED + +using System; +using UnityEngine; + +namespace SteamAudio +{ + public sealed class UnityAudioEngineState : AudioEngineState + { + public override void Initialize(IntPtr context, IntPtr defaultHRTF, SimulationSettings simulationSettings, PerspectiveCorrection correction) + { + API.iplUnityInitialize(context); + API.iplUnitySetHRTF(defaultHRTF); + API.iplUnitySetSimulationSettings(simulationSettings); + API.iplUnitySetPerspectiveCorrection(correction); + } + + public override void Destroy() + { + API.iplUnityTerminate(); + } + + public override void SetHRTF(IntPtr hrtf) + { + API.iplUnitySetHRTF(hrtf); + } + + public override void SetPerspectiveCorrection(PerspectiveCorrection correction) + { + API.iplUnitySetPerspectiveCorrection(correction); + } + + public override void SetReverbSource(Source reverbSource) + { + API.iplUnitySetReverbSource(reverbSource.Get()); + } + } + + public sealed class UnityAudioEngineStateHelpers : AudioEngineStateHelpers + { + public override Transform GetListenerTransform() + { + var audioListener = GameObject.FindObjectOfType(); + return (audioListener != null) ? audioListener.transform : null; + } + + public override AudioSettings GetAudioSettings() + { + var audioSettings = new AudioSettings { }; + + audioSettings.samplingRate = UnityEngine.AudioSettings.outputSampleRate; + + var numBuffers = 0; + UnityEngine.AudioSettings.GetDSPBufferSize(out audioSettings.frameSize, out numBuffers); + + return audioSettings; + } + } +} + +#endif diff --git a/Scripts/Runtime/UnityAudioEngineState.cs.meta b/Scripts/Runtime/UnityAudioEngineState.cs.meta new file mode 100755 index 0000000..651210d --- /dev/null +++ b/Scripts/Runtime/UnityAudioEngineState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a1c6ea05d9a254e4eb65412b568878b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SteamAudioUnity.asmdef b/SteamAudioUnity.asmdef new file mode 100755 index 0000000..241b579 --- /dev/null +++ b/SteamAudioUnity.asmdef @@ -0,0 +1,14 @@ +{ + "name": "SteamAudioUnity", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/SteamAudioUnity.asmdef.meta b/SteamAudioUnity.asmdef.meta new file mode 100755 index 0000000..8a6d081 --- /dev/null +++ b/SteamAudioUnity.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 558d81aa619cc114fbdab8165212bc9d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: