FMODi paigaldamine projekti sisse, fmod project created, assets are imported into FMOD; AudioManager and FMODEvents scripts, VR is set up

This commit is contained in:
Timur Nizamov
2025-10-12 20:57:56 +03:00
parent cb73b9cbbc
commit f542c4c57e
770 changed files with 47580 additions and 3 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ce39533effc93ba409e337ba540bf789
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93923a20291353a40809350917bab197
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
{
"name": "FMODUnityResonanceEditor",
"references": [
"FMODUnityResonance"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_2021_3_OR_NEWER"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 194213485063a984b98ce9410892267a
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,186 @@
// Copyright 2017 Google Inc. All rights reserved.
//
// 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;
using System.Collections;
using static FMODUnityResonance.FmodResonanceAudioRoom;
namespace FMODUnityResonance
{
/// A custom editor for properties on the FmodResonanceAudioRoom script. This appears in the
/// Inspector window of a FmodResonanceAudioRoom object.
[CustomEditor(typeof(FmodResonanceAudioRoom))]
[CanEditMultipleObjects]
public class FmodResonanceAudioRoomEditor : Editor
{
private SerializedProperty leftWall = null;
private SerializedProperty rightWall = null;
private SerializedProperty floor = null;
private SerializedProperty ceiling = null;
private SerializedProperty backWall = null;
private SerializedProperty frontWall = null;
private SerializedProperty reflectivity = null;
private SerializedProperty reverbGainDb = null;
private SerializedProperty reverbBrightness = null;
private SerializedProperty reverbTime = null;
private SerializedProperty size = null;
private GUIContent surfaceMaterialsLabel;
private GUIContent surfaceMaterialLabel;
private GUIContent reflectivityLabel;
private GUIContent reverbGainLabel;
private GUIContent reverbPropertiesLabel;
private GUIContent reverbBrightnessLabel;
private GUIContent reverbTimeLabel;
private GUIContent sizeLabel;
private static readonly string[] SurfaceMaterialDisplay = new string[] {
L10n.Tr("Transparent"),
L10n.Tr("Acoustic Ceiling Tiles"),
L10n.Tr("Brick Bare"),
L10n.Tr("Brick Painted"),
L10n.Tr("Concrete Block Coarse"),
L10n.Tr("Concrete Block Painted"),
L10n.Tr("Curtain Heavy"),
L10n.Tr("Fiberglass Insulation"),
L10n.Tr("Glass Thin"),
L10n.Tr("Glass Thick"),
L10n.Tr("Grass"),
L10n.Tr("Linoleum On Concrete"),
L10n.Tr("Marble"),
L10n.Tr("Metal"),
L10n.Tr("Parquet On Concrete"),
L10n.Tr("Plaster Rough"),
L10n.Tr("Plaster Smooth"),
L10n.Tr("Plywood Panel"),
L10n.Tr("Polished Concrete Or Tile"),
L10n.Tr("Sheetrock"),
L10n.Tr("Water Or Ice Surface"),
L10n.Tr("Wood Ceiling"),
L10n.Tr("Wood Panel"),
};
private static readonly int[] SurfaceMaterialValues = new int[] {
(int)SurfaceMaterial.Transparent,
(int)SurfaceMaterial.AcousticCeilingTiles,
(int)SurfaceMaterial.BrickBare,
(int)SurfaceMaterial.BrickPainted,
(int)SurfaceMaterial.ConcreteBlockCoarse,
(int)SurfaceMaterial.ConcreteBlockPainted,
(int)SurfaceMaterial.CurtainHeavy,
(int)SurfaceMaterial.FiberglassInsulation,
(int)SurfaceMaterial.GlassThin,
(int)SurfaceMaterial.GlassThick,
(int)SurfaceMaterial.Grass,
(int)SurfaceMaterial.LinoleumOnConcrete,
(int)SurfaceMaterial.Marble,
(int)SurfaceMaterial.Metal,
(int)SurfaceMaterial.ParquetOnConcrete,
(int)SurfaceMaterial.PlasterRough,
(int)SurfaceMaterial.PlasterSmooth,
(int)SurfaceMaterial.PlywoodPanel,
(int)SurfaceMaterial.PolishedConcreteOrTile,
(int)SurfaceMaterial.Sheetrock,
(int)SurfaceMaterial.WaterOrIceSurface,
(int)SurfaceMaterial.WoodCeiling,
(int)SurfaceMaterial.WoodPanel,
};
private void OnEnable()
{
surfaceMaterialsLabel = new GUIContent(L10n.Tr("Surface Materials"),
L10n.Tr("Room surface materials to calculate the acoustic properties of the room."));
surfaceMaterialLabel = new GUIContent(L10n.Tr("Surface Material"),
L10n.Tr("Surface material used to calculate the acoustic properties of the room."));
reflectivityLabel = new GUIContent(L10n.Tr("Reflectivity"),
L10n.Tr("Adjusts what proportion of the direct sound is reflected back by each surface, after an appropriate delay. Reverberation is unaffected by this setting."));
reverbGainLabel = new GUIContent(L10n.Tr("Gain (dB)"),
L10n.Tr("Applies a gain adjustment to the reverberation in the room. The default value will leave reverb unaffected."));
reverbPropertiesLabel = new GUIContent(L10n.Tr("Reverb Properties"),
L10n.Tr("Parameters to adjust the reverb properties of the room."));
reverbBrightnessLabel = new GUIContent(L10n.Tr("Brightness"),
L10n.Tr("Adjusts the balance between high and low frequencies in the reverb."));
reverbTimeLabel = new GUIContent(L10n.Tr("Time"),
L10n.Tr("Adjusts the overall duration of the reverb by a positive scaling factor."));
sizeLabel = new GUIContent(L10n.Tr("Size"), L10n.Tr("Sets the room dimensions."));
leftWall = serializedObject.FindProperty("LeftWall");
rightWall = serializedObject.FindProperty("RightWall");
floor = serializedObject.FindProperty("Floor");
ceiling = serializedObject.FindProperty("Ceiling");
backWall = serializedObject.FindProperty("BackWall");
frontWall = serializedObject.FindProperty("FrontWall");
reflectivity = serializedObject.FindProperty("Reflectivity");
reverbGainDb = serializedObject.FindProperty("ReverbGainDb");
reverbBrightness = serializedObject.FindProperty("ReverbBrightness");
reverbTime = serializedObject.FindProperty("ReverbTime");
size = serializedObject.FindProperty("Size");
}
/// @cond
public override void OnInspectorGUI()
{
serializedObject.Update();
// Add clickable script field, as would have been provided by DrawDefaultInspector()
MonoScript script = MonoScript.FromMonoBehaviour(target as MonoBehaviour);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false);
EditorGUI.EndDisabledGroup();
EditorGUILayout.LabelField(surfaceMaterialsLabel);
++EditorGUI.indentLevel;
DrawSurfaceMaterial(leftWall, L10n.Tr("Left Wall"));
DrawSurfaceMaterial(rightWall, L10n.Tr("Right Wall"));
DrawSurfaceMaterial(floor, L10n.Tr("Floor"));
DrawSurfaceMaterial(ceiling, L10n.Tr("Ceiling"));
DrawSurfaceMaterial(backWall, L10n.Tr("Back Wall"));
DrawSurfaceMaterial(frontWall, L10n.Tr("Front Wall"));
--EditorGUI.indentLevel;
EditorGUILayout.Separator();
EditorGUILayout.Slider(reflectivity, 0.0f, FmodResonanceAudio.MaxReflectivity, reflectivityLabel);
EditorGUILayout.Separator();
EditorGUILayout.LabelField(reverbPropertiesLabel);
++EditorGUI.indentLevel;
EditorGUILayout.Slider(reverbGainDb, FmodResonanceAudio.MinGainDb, FmodResonanceAudio.MaxGainDb,
reverbGainLabel);
EditorGUILayout.Slider(reverbBrightness, FmodResonanceAudio.MinReverbBrightness,
FmodResonanceAudio.MaxReverbBrightness, reverbBrightnessLabel);
EditorGUILayout.Slider(reverbTime, 0.0f, FmodResonanceAudio.MaxReverbTime, reverbTimeLabel);
--EditorGUI.indentLevel;
EditorGUILayout.Separator();
EditorGUILayout.PropertyField(size, sizeLabel);
serializedObject.ApplyModifiedProperties();
}
/// @endcond
private void DrawSurfaceMaterial(SerializedProperty surfaceMaterial, string displayName)
{
EditorGUILayout.BeginHorizontal();
GUIContent labelContent = new GUIContent(displayName, surfaceMaterialLabel.tooltip);
EditorGUILayout.LabelField(labelContent, GUILayout.Width(150));
surfaceMaterial.intValue = EditorGUILayout.IntPopup(
surfaceMaterial.intValue, SurfaceMaterialDisplay, SurfaceMaterialValues);
EditorGUILayout.EndHorizontal();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 935c6716e27bd481e97897dd9e1de595
timeCreated: 1511395157
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
#if UNITY_2020_2_OR_NEWER
[assembly: UnityEditor.Localization]
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6711f1f86af21644c897cc89748266f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,195 @@
msgid ""
msgstr ""
"Project-Id-Version: FMOD for Unity\n"
"POT-Creation-Date: 2024-12-20 15:03+1100\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_hans\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.5\n"
"X-Poedit-KeywordsList: ;L10n.Tr\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SearchPath-0: .\n"
#: FmodResonanceAudioRoomEditor.cs:51
msgid "Transparent"
msgstr "透明"
#: FmodResonanceAudioRoomEditor.cs:52
msgid "Acoustic Ceiling Tiles"
msgstr "吸音天花板瓦"
#: FmodResonanceAudioRoomEditor.cs:53
msgid "Brick Bare"
msgstr "裸砖"
#: FmodResonanceAudioRoomEditor.cs:54
msgid "Brick Painted"
msgstr "涂漆砖"
#: FmodResonanceAudioRoomEditor.cs:55
msgid "Concrete Block Coarse"
msgstr "粗糙混凝土块"
#: FmodResonanceAudioRoomEditor.cs:56
msgid "Concrete Block Painted"
msgstr "涂漆混凝土块"
#: FmodResonanceAudioRoomEditor.cs:57
msgid "Curtain Heavy"
msgstr "厚重窗帘"
#: FmodResonanceAudioRoomEditor.cs:58
msgid "Fiberglass Insulation"
msgstr "玻璃纤维绝缘"
#: FmodResonanceAudioRoomEditor.cs:59
msgid "Glass Thin"
msgstr "薄玻璃"
#: FmodResonanceAudioRoomEditor.cs:60
msgid "Glass Thick"
msgstr "厚玻璃"
#: FmodResonanceAudioRoomEditor.cs:61
msgid "Grass"
msgstr "草地"
#: FmodResonanceAudioRoomEditor.cs:62
msgid "Linoleum On Concrete"
msgstr "沥青混凝土"
#: FmodResonanceAudioRoomEditor.cs:63
msgid "Marble"
msgstr "大理石"
#: FmodResonanceAudioRoomEditor.cs:64
msgid "Metal"
msgstr "金属"
#: FmodResonanceAudioRoomEditor.cs:65
msgid "Parquet On Concrete"
msgstr "混凝土上的镶木地板"
#: FmodResonanceAudioRoomEditor.cs:66
msgid "Plaster Rough"
msgstr "粗糙石膏"
#: FmodResonanceAudioRoomEditor.cs:67
msgid "Plaster Smooth"
msgstr "光滑石膏"
#: FmodResonanceAudioRoomEditor.cs:68
msgid "Plywood Panel"
msgstr "胶合板"
#: FmodResonanceAudioRoomEditor.cs:69
msgid "Polished Concrete Or Tile"
msgstr "抛光混凝土或瓷砖"
#: FmodResonanceAudioRoomEditor.cs:70
msgid "Sheetrock"
msgstr "石膏板"
#: FmodResonanceAudioRoomEditor.cs:71
msgid "Water Or Ice Surface"
msgstr "水面或冰面"
#: FmodResonanceAudioRoomEditor.cs:72
msgid "Wood Ceiling"
msgstr "木质天花板"
#: FmodResonanceAudioRoomEditor.cs:73
msgid "Wood Panel"
msgstr "木板"
#: FmodResonanceAudioRoomEditor.cs:104
msgid "Surface Materials"
msgstr "表面材质"
#: FmodResonanceAudioRoomEditor.cs:105
msgid "Room surface materials to calculate the acoustic properties of the room."
msgstr "用于计算房间声学属性的房间表面材质。"
#: FmodResonanceAudioRoomEditor.cs:106
msgid "Surface Material"
msgstr "表面材质"
#: FmodResonanceAudioRoomEditor.cs:107
msgid "Surface material used to calculate the acoustic properties of the room."
msgstr "用于计算房间声学属性的表面材质。"
#: FmodResonanceAudioRoomEditor.cs:108
msgid "Reflectivity"
msgstr "反射率"
#: FmodResonanceAudioRoomEditor.cs:109
msgid "Adjusts what proportion of the direct sound is reflected back by each surface, after an appropriate delay. Reverberation is unaffected by this setting."
msgstr "调整每个表面在适当延迟后反射回直接声音的比例。混响效果不受此设置影响。"
#: FmodResonanceAudioRoomEditor.cs:110
msgid "Gain (dB)"
msgstr "增加增益(分贝)"
#: FmodResonanceAudioRoomEditor.cs:111
msgid "Applies a gain adjustment to the reverberation in the room. The default value will leave reverb unaffected."
msgstr "对房间中的混响应用增益调整。默认值将不影响混响效果。"
#: FmodResonanceAudioRoomEditor.cs:112
msgid "Reverb Properties"
msgstr "混响属性"
#: FmodResonanceAudioRoomEditor.cs:113
msgid "Parameters to adjust the reverb properties of the room."
msgstr "用于调整房间混响属性的参数。"
#: FmodResonanceAudioRoomEditor.cs:114
msgid "Brightness"
msgstr "亮度"
#: FmodResonanceAudioRoomEditor.cs:115
msgid "Adjusts the balance between high and low frequencies in the reverb."
msgstr "调整混响中高频和低频之间的平衡。"
#: FmodResonanceAudioRoomEditor.cs:116
msgid "Time"
msgstr "时间"
#: FmodResonanceAudioRoomEditor.cs:117
msgid "Adjusts the overall duration of the reverb by a positive scaling factor."
msgstr "通过正比例缩放因子调整混响的整体持续时间。"
#: FmodResonanceAudioRoomEditor.cs:118
msgid "Size"
msgstr "尺寸"
#: FmodResonanceAudioRoomEditor.cs:118
msgid "Sets the room dimensions."
msgstr "设置房间的尺寸。"
#: FmodResonanceAudioRoomEditor.cs:144
msgid "Left Wall"
msgstr "左墙"
#: FmodResonanceAudioRoomEditor.cs:145
msgid "Right Wall"
msgstr "右墙"
#: FmodResonanceAudioRoomEditor.cs:146
msgid "Floor"
msgstr "地板"
#: FmodResonanceAudioRoomEditor.cs:147
msgid "Ceiling"
msgstr "天花板"
#: FmodResonanceAudioRoomEditor.cs:148
msgid "Back Wall"
msgstr "后墙"
#: FmodResonanceAudioRoomEditor.cs:149
msgid "Front Wall"
msgstr "前墙"

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: df892acb3265e0043b3bb1b8981b5aeb
LocalizationImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 05a6a02c28ee77a49b6fcadf67aff3b7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
{
"name": "FMODUnityResonance",
"references": [
"FMODUnity"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_2021_3_OR_NEWER"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 44d09cf463b68274884d8a3c8a94e528
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,290 @@
// Copyright 2017 Google Inc. All rights reserved.
//
// 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 System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using FMODUnity;
namespace FMODUnityResonance
{
/// This is the main Resonance Audio class that communicates with the FMOD Unity integration. Native
/// functions of the system can only be called through this class to preserve the internal system
/// functionality.
public static class FmodResonanceAudio
{
/// Maximum allowed gain value in decibels.
public const float MaxGainDb = 24.0f;
/// Minimum allowed gain value in decibels.
public const float MinGainDb = -24.0f;
/// Maximum allowed reverb brightness modifier value.
public const float MaxReverbBrightness = 1.0f;
/// Minimum allowed reverb brightness modifier value.
public const float MinReverbBrightness = -1.0f;
/// Maximum allowed reverb time modifier value.
public const float MaxReverbTime = 3.0f;
/// Maximum allowed reflectivity multiplier of a room surface material.
public const float MaxReflectivity = 2.0f;
// Right-handed to left-handed matrix converter (and vice versa).
private static readonly Matrix4x4 flipZ = Matrix4x4.Scale(new Vector3(1, 1, -1));
// Get a handle to the Resonance Audio Listener FMOD Plugin.
private static readonly string listenerPluginName = "Resonance Audio Listener";
// Size of |RoomProperties| struct in bytes.
private static readonly int roomPropertiesSize = Marshal.SizeOf<RoomProperties>();
// Plugin data parameter index for the room properties.
private static readonly int roomPropertiesIndex = 1;
// Boundaries instance to be used in room detection logic.
private static Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
// Container to store the currently active rooms in the scene.
private static List<FmodResonanceAudioRoom> enabledRooms = new List<FmodResonanceAudioRoom>();
// Current listener position.
private static FMOD.VECTOR listenerPositionFmod = new FMOD.VECTOR();
// FMOD Resonance Audio Listener Plugin.
private static FMOD.DSP listenerPlugin;
/// Updates the room effects of the environment with given |room| properties.
/// @note This should only be called from the main Unity thread.
public static void UpdateAudioRoom(FmodResonanceAudioRoom room, bool roomEnabled)
{
// Update the enabled rooms list.
if (roomEnabled)
{
if (!enabledRooms.Contains(room))
{
enabledRooms.Add(room);
}
}
else
{
enabledRooms.Remove(room);
}
// Update the current room effects to be applied.
if (enabledRooms.Count > 0)
{
FmodResonanceAudioRoom currentRoom = enabledRooms[enabledRooms.Count - 1];
RoomProperties roomProperties = GetRoomProperties(currentRoom);
// Pass the room properties into a pointer.
IntPtr roomPropertiesPtr = Marshal.AllocHGlobal(roomPropertiesSize);
Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
ListenerPlugin.setParameterData(roomPropertiesIndex, GetBytes(roomPropertiesPtr,
roomPropertiesSize));
Marshal.FreeHGlobal(roomPropertiesPtr);
}
else
{
// Set the room properties to a null room, which will effectively disable the room effects.
ListenerPlugin.setParameterData(roomPropertiesIndex, GetBytes(IntPtr.Zero, 0));
}
}
/// Returns whether the listener is currently inside the given |room| boundaries.
public static bool IsListenerInsideRoom(FmodResonanceAudioRoom room)
{
// Compute the room position relative to the listener.
FMOD.VECTOR unused;
RuntimeManager.CoreSystem.get3DListenerAttributes(0, out listenerPositionFmod, out unused,
out unused, out unused);
Vector3 listenerPosition = new Vector3(listenerPositionFmod.x, listenerPositionFmod.y,
listenerPositionFmod.z);
Vector3 relativePosition = listenerPosition - room.transform.position;
Quaternion rotationInverse = Quaternion.Inverse(room.transform.rotation);
// Set the size of the room as the boundary and return whether the listener is inside.
bounds.size = Vector3.Scale(room.transform.lossyScale, room.Size);
return bounds.Contains(rotationInverse * relativePosition);
}
[StructLayout(LayoutKind.Sequential)]
private struct RoomProperties
{
// Center position of the room in world space.
public float PositionX;
public float PositionY;
public float PositionZ;
// Rotation (quaternion) of the room in world space.
public float RotationX;
public float RotationY;
public float RotationZ;
public float RotationW;
// Size of the shoebox room in world space.
public float DimensionsX;
public float DimensionsY;
public float DimensionsZ;
// Material name of each surface of the shoebox room.
public FmodResonanceAudioRoom.SurfaceMaterial MaterialLeft;
public FmodResonanceAudioRoom.SurfaceMaterial MaterialRight;
public FmodResonanceAudioRoom.SurfaceMaterial MaterialBottom;
public FmodResonanceAudioRoom.SurfaceMaterial MaterialTop;
public FmodResonanceAudioRoom.SurfaceMaterial MaterialFront;
public FmodResonanceAudioRoom.SurfaceMaterial MaterialBack;
// User defined uniform scaling factor for reflectivity. This parameter has no effect when set
// to 1.0f.
public float ReflectionScalar;
// User defined reverb tail gain multiplier. This parameter has no effect when set to 0.0f.
public float ReverbGain;
// Adjusts the reverberation time across all frequency bands. RT60 values are multiplied by this
// factor. Has no effect when set to 1.0f.
public float ReverbTime;
// Controls the slope of a line from the lowest to the highest RT60 values (increases high
// frequency RT60s when positive, decreases when negative). Has no effect when set to 0.0f.
public float ReverbBrightness;
};
// Returns the FMOD Resonance Audio Listener Plugin.
private static FMOD.DSP ListenerPlugin
{
get
{
if (!listenerPlugin.hasHandle())
{
listenerPlugin = Initialize();
}
return listenerPlugin;
}
}
// Converts given |db| value to its amplitude equivalent where 'dB = 20 * log10(amplitude)'.
private static float ConvertAmplitudeFromDb(float db)
{
return Mathf.Pow(10.0f, 0.05f * db);
}
// Converts given |position| and |rotation| from Unity space to audio space.
private static void ConvertAudioTransformFromUnity(ref Vector3 position,
ref Quaternion rotation)
{
// Compose the transformation matrix.
Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, Vector3.one);
// Convert the transformation matrix from left-handed to right-handed.
transformMatrix = flipZ * transformMatrix * flipZ;
// Update |position| and |rotation| respectively.
position = transformMatrix.GetColumn(3);
rotation = Quaternion.LookRotation(transformMatrix.GetColumn(2), transformMatrix.GetColumn(1));
}
// Returns a byte array of |length| created from |ptr|.
private static byte[] GetBytes(IntPtr ptr, int length)
{
if (ptr != IntPtr.Zero)
{
byte[] byteArray = new byte[length];
Marshal.Copy(ptr, byteArray, 0, length);
return byteArray;
}
// Return an empty array if the pointer is null.
return new byte[1];
}
// Returns room properties of the given |room|.
private static RoomProperties GetRoomProperties(FmodResonanceAudioRoom room)
{
RoomProperties roomProperties;
Vector3 position = room.transform.position;
Quaternion rotation = room.transform.rotation;
Vector3 scale = Vector3.Scale(room.transform.lossyScale, room.Size);
ConvertAudioTransformFromUnity(ref position, ref rotation);
roomProperties.PositionX = position.x;
roomProperties.PositionY = position.y;
roomProperties.PositionZ = position.z;
roomProperties.RotationX = rotation.x;
roomProperties.RotationY = rotation.y;
roomProperties.RotationZ = rotation.z;
roomProperties.RotationW = rotation.w;
roomProperties.DimensionsX = scale.x;
roomProperties.DimensionsY = scale.y;
roomProperties.DimensionsZ = scale.z;
roomProperties.MaterialLeft = room.LeftWall;
roomProperties.MaterialRight = room.RightWall;
roomProperties.MaterialBottom = room.Floor;
roomProperties.MaterialTop = room.Ceiling;
roomProperties.MaterialFront = room.FrontWall;
roomProperties.MaterialBack = room.BackWall;
roomProperties.ReverbGain = ConvertAmplitudeFromDb(room.ReverbGainDb);
roomProperties.ReverbTime = room.ReverbTime;
roomProperties.ReverbBrightness = room.ReverbBrightness;
roomProperties.ReflectionScalar = room.Reflectivity;
return roomProperties;
}
// Initializes and returns the FMOD Resonance Audio Listener Plugin.
private static FMOD.DSP Initialize()
{
// Search through all busses on in banks.
int numBanks = 0;
FMOD.DSP dsp = new FMOD.DSP();
FMOD.Studio.Bank[] banks = null;
RuntimeManager.StudioSystem.getBankCount(out numBanks);
RuntimeManager.StudioSystem.getBankList(out banks);
for (int currentBank = 0; currentBank < numBanks; ++currentBank)
{
int numBusses = 0;
FMOD.Studio.Bus[] busses = null;
banks[currentBank].getBusCount(out numBusses);
banks[currentBank].getBusList(out busses);
for (int currentBus = 0; currentBus < numBusses; ++currentBus)
{
// Make sure the channel group of the current bus is assigned properly.
string busPath = null;
busses[currentBus].getPath(out busPath);
RuntimeManager.StudioSystem.getBus(busPath, out busses[currentBus]);
busses[currentBus].lockChannelGroup();
RuntimeManager.StudioSystem.flushCommands();
FMOD.ChannelGroup channelGroup;
busses[currentBus].getChannelGroup(out channelGroup);
if (channelGroup.hasHandle())
{
int numDsps = 0;
channelGroup.getNumDSPs(out numDsps);
for (int currentDsp = 0; currentDsp < numDsps; ++currentDsp)
{
channelGroup.getDSP(currentDsp, out dsp);
string dspNameSb;
int unusedInt = 0;
uint unusedUint = 0;
dsp.getInfo(out dspNameSb, out unusedUint, out unusedInt, out unusedInt, out unusedInt);
if (dspNameSb.ToString().Equals(listenerPluginName) && dsp.hasHandle())
{
return dsp;
}
}
}
busses[currentBus].unlockChannelGroup();
}
}
RuntimeUtils.DebugLogError(listenerPluginName + " not found in the FMOD project.");
return dsp;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6794e6301575a445d8588930a0752568
timeCreated: 1511395157
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
// Copyright 2017 Google Inc. All rights reserved.
//
// 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.Serialization;
using System.Collections;
namespace FMODUnityResonance
{
/// Resonance Audio room component that simulates environmental effects of a room with respect to
/// the properties of the attached game object.
[AddComponentMenu("ResonanceAudio/FmodResonanceAudioRoom")]
public class FmodResonanceAudioRoom : MonoBehaviour
{
/// Material type that determines the acoustic properties of a room surface.
public enum SurfaceMaterial
{
Transparent = 0, ///< Transparent
AcousticCeilingTiles = 1, ///< Acoustic ceiling tiles
BrickBare = 2, ///< Brick, bare
BrickPainted = 3, ///< Brick, painted
ConcreteBlockCoarse = 4, ///< Concrete block, coarse
ConcreteBlockPainted = 5, ///< Concrete block, painted
CurtainHeavy = 6, ///< Curtain, heavy
FiberglassInsulation = 7, ///< Fiberglass insulation
GlassThin = 8, ///< Glass, thin
GlassThick = 9, ///< Glass, thick
Grass = 10, ///< Grass
LinoleumOnConcrete = 11, ///< Linoleum on concrete
Marble = 12, ///< Marble
Metal = 13, ///< Galvanized sheet metal
ParquetOnConcrete = 14, ///< Parquet on concrete
PlasterRough = 15, ///< Plaster, rough
PlasterSmooth = 16, ///< Plaster, smooth
PlywoodPanel = 17, ///< Plywood panel
PolishedConcreteOrTile = 18, ///< Polished concrete or tile
Sheetrock = 19, ///< Sheetrock
WaterOrIceSurface = 20, ///< Water or ice surface
WoodCeiling = 21, ///< Wood ceiling
WoodPanel = 22 ///< Wood panel
}
/// Room surface material in negative x direction.
[FormerlySerializedAs("leftWall")]
public SurfaceMaterial LeftWall = SurfaceMaterial.ConcreteBlockCoarse;
/// Room surface material in positive x direction.
[FormerlySerializedAs("rightWall")]
public SurfaceMaterial RightWall = SurfaceMaterial.ConcreteBlockCoarse;
/// Room surface material in negative y direction.
[FormerlySerializedAs("floor")]
public SurfaceMaterial Floor = SurfaceMaterial.ParquetOnConcrete;
/// Room surface material in positive y direction.
[FormerlySerializedAs("ceiling")]
public SurfaceMaterial Ceiling = SurfaceMaterial.PlasterRough;
/// Room surface material in negative z direction.
[FormerlySerializedAs("backWall")]
public SurfaceMaterial BackWall = SurfaceMaterial.ConcreteBlockCoarse;
/// Room surface material in positive z direction.
[FormerlySerializedAs("frontWall")]
public SurfaceMaterial FrontWall = SurfaceMaterial.ConcreteBlockCoarse;
/// Reflectivity scalar for each surface of the room.
[FormerlySerializedAs("reflectivity")]
public float Reflectivity = 1.0f;
/// Reverb gain modifier in decibels.
[FormerlySerializedAs("reverbGainDb")]
public float ReverbGainDb = 0.0f;
/// Reverb brightness modifier.
[FormerlySerializedAs("reverbBrightness")]
public float ReverbBrightness = 0.0f;
/// Reverb time modifier.
[FormerlySerializedAs("reverbTime")]
public float ReverbTime = 1.0f;
/// Size of the room (normalized with respect to scale of the game object).
[FormerlySerializedAs("size")]
public Vector3 Size = Vector3.one;
private void OnEnable()
{
FmodResonanceAudio.UpdateAudioRoom(this, FmodResonanceAudio.IsListenerInsideRoom(this));
}
private void OnDisable()
{
FmodResonanceAudio.UpdateAudioRoom(this, false);
}
private void Update()
{
FmodResonanceAudio.UpdateAudioRoom(this, FmodResonanceAudio.IsListenerInsideRoom(this));
}
private void OnDrawGizmosSelected()
{
// Draw shoebox model wireframe of the room.
Gizmos.color = Color.yellow;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero, Size);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6b0c5e63920ee4f55b7ec5248525af4b
timeCreated: 1511395157
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: