// Returns room properties of the given |room|. private static RoomProperties GetRoomProperties(WwiseResonanceAudioRoom 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); }
/// Returns whether the listener is currently inside the given |room| boundaries. public static bool IsListenerInsideRoom(WwiseResonanceAudioRoom room) { // Compute the room position relative to the listener. if (ListenerTransform == null) { // Listener does not exist, skip processing. return(false); } Vector3 relativePosition = ListenerTransform.position - 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)); }
/// 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(WwiseResonanceAudioRoom 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. uint roomEffectsBusId = AkSoundEngine.GetIDFromString(roomEffectsBusName); if (enabledRooms.Count > 0) { WwiseResonanceAudioRoom 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); AkSoundEngine.SendPluginCustomGameData(roomEffectsBusId, null, AkPluginType.AkPluginTypeMixer, companyId, roomEffectsPluginId, roomPropertiesPtr, (uint)roomPropertiesSize); Marshal.FreeHGlobal(roomPropertiesPtr); } else { // Set the room properties to null, which will effectively disable the room effects. AkSoundEngine.SendPluginCustomGameData(roomEffectsBusId, null, AkPluginType.AkPluginTypeMixer, companyId, roomEffectsPluginId, IntPtr.Zero, 0U); } }