Example #1
0
 // Updates room properties with the given |room|.
 private static void UpdateRoomProperties(ResonanceAudioRoom room)
 {
     FillGeometryOfRoomProperties(room.transform.position, room.transform.rotation,
                                  Vector3.Scale(room.transform.lossyScale, room.size));
     FillWallMaterialsOfRoomProperties(room.leftWall, room.rightWall, room.floor, room.ceiling,
                                       room.frontWall, room.backWall);
     FillModifiersOfRoomProperties(room.reverbGainDb, room.reverbTime, room.reverbBrightness,
                                   room.reflectivity);
 }
    /// 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(ResonanceAudioRoom currentRoom)
    {
        // Update the current room effects to be applied.
        RoomProperties roomProperties = GetRoomProperties(currentRoom);
        // Pass the room properties into a pointer.
        IntPtr roomPropertiesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(roomProperties));

        Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
        SetRoomProperties(roomPropertiesPtr);
        SetRt60ValuesAndProxyRoomProperties(null, IntPtr.Zero);
        Marshal.FreeHGlobal(roomPropertiesPtr);
    }
Example #3
0
 /// Updates the room effects of the environment with the given |room|.
 /// @note This should only be called from the main Unity thread.
 public static void UpdateRoom(ResonanceAudioRoom room)
 {
     if (roomPropertiesPtr == IntPtr.Zero)
     {
         // Allocate the unmanaged memory only once.
         roomPropertiesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(roomProperties));
     }
     UpdateRoomProperties(room);
     Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
     SetRoomProperties(roomPropertiesPtr, null);
     Marshal.DestroyStructure(roomPropertiesPtr, typeof(RoomProperties));
 }
Example #4
0
    /// Returns whether the listener is currently inside the given |room| boundaries.
    private static bool IsListenerInsideRoom(ResonanceAudioRoom room)
    {
        bool      isInside          = false;
        Transform listenerTransform = ResonanceAudio.ListenerTransform;

        if (listenerTransform != null)
        {
            Vector3    relativePosition = listenerTransform.position - room.transform.position;
            Quaternion rotationInverse  = Quaternion.Inverse(room.transform.rotation);

            bounds.size = Vector3.Scale(room.transform.lossyScale, room.size);
            isInside    = bounds.Contains(rotationInverse * relativePosition);
        }
        return(isInside);
    }
Example #5
0
    // Updates the list of room effects regions with the given |room|.
    private static void UpdateRoomEffectsRegions(ResonanceAudioRoom room, bool isEnabled)
    {
        int regionIndex = -1;

        for (int i = 0; i < roomEffectsRegions.Count; ++i)
        {
            if (roomEffectsRegions[i].room == room)
            {
                regionIndex = i;
                break;
            }
        }
        if (isEnabled && regionIndex == -1)
        {
            roomEffectsRegions.Add(new RoomEffectsRegion(room, null));
        }
        else if (!isEnabled && regionIndex != -1)
        {
            roomEffectsRegions.RemoveAt(regionIndex);
        }
    }
Example #6
0
 /// Removes a Resonance Audio room.
 public static void RemoveRoom(ResonanceAudioRoom room)
 {
     UpdateRoomEffectsRegions(room, false);
     UpdateRoomEffects();
 }
Example #7
0
 /// Adds or removes a Resonance Audio room depending on whether the listener is inside |room|.
 public static void UpdateRoom(ResonanceAudioRoom room)
 {
     UpdateRoomEffectsRegions(room, IsListenerInsideRoom(room));
     UpdateRoomEffects();
 }
Example #8
0
 public RoomEffectsRegion(ResonanceAudioRoom room, ResonanceAudioReverbProbe reverbProbe)
 {
     this.room        = room;
     this.reverbProbe = reverbProbe;
 }
 /// Removes a Resonance Audio room.
 public static void RemoveRoom(ResonanceAudioRoom room)
 {
     UpdateRoomEffectsRegion(new RoomEffectsRegion(room), false);
 }
 /// Constructs an instance that holds a Resonance Audio room.
 public RoomEffectsRegion(ResonanceAudioRoom room)
 {
     this.room        = room;
     this.reverbProbe = null;
 }