/// 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(WwiseGvrAudioRoom 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) { WwiseGvrAudioRoom 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, AkSoundEngine.AK_MIXER_FX_SLOT, roomPropertiesPtr, (uint)roomPropertiesSize); Marshal.FreeHGlobal(roomPropertiesPtr); } else { // Set the room properties to null, which will effectively disable the room effects. AkSoundEngine.SendPluginCustomGameData(roomEffectsBusId, AkSoundEngine.AK_MIXER_FX_SLOT, IntPtr.Zero, 0U); } }
// Returns room properties of the given |room|. private static RoomProperties GetRoomProperties(WwiseGvrAudioRoom 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(WwiseGvrAudioRoom room) { // Compute the room position relative to the listener. AkSoundEngine.GetListenerPosition(0, listenerTransform); Vector3 listenerPosition = new Vector3(listenerTransform.Position().X, listenerTransform.Position().Y, listenerTransform.Position().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)); }