Exercise - Spatialize button interaction sounds
In this unit, you'll learn how to spatialize the button interaction sounds and learn how to use an audio clip to test spatialized button interaction.
Add a button
To add the Button prefab, in the Project window, select Packages and type "PressableButton_32x32mm_IconAndTextUnder" in the search bar.
The button prefab is the entry represented by a blue icon. Click and drag the PressableButton_32x32mm_IconAndTextUnder prefab into the Hierarchy. With the PressableButton_32x32mm_IconAndTextUnder object still selected, in the Inspector window, configure the Transform component as follows:
- Position: X = 0, Y = 1.6, Z = 0.5
- Rotation: X = 0, Y = 0, Z = 0
- Scale: X = 1, Y = 1, Z = 1
To focus in on the objects in the scene, you can double-click the PressableButton_32x32mm_IconAndTextUnder object, and then zoom slightly in again.
Spatialize button feedback
In this step, you'll spatialize the audio feedback for the button. For related design suggestions, see spatial sound design.
In the Audio Mixer window, you'll define destinations called Mixer Groups for audio playback from Audio Source components.
To open the Audio Mixer window, select Window > Audio > Audio Mixer in the Unity menu:
Create a Mixer by clicking the + next to Mixers and enter a suitable name to the Mixer; for example, Spatial Audio Mixer. The new mixer includes a default Group called Master.
Open and right-click the mixer, then select Add effect at bottom > Microsoft Spatializer Mixer.
In the Hierarchy window, select the PressableButton_32x32mm_IconAndTextUnder, then find the Audio Source component in the Inspector window and configure the Audio Source component as follows:
- For the Output property, choose the Mixer that you created.
- Check the Spatialize checkbox.
- Move the Spatial Blend slider to 3D (1).
Note
If you move Spatial Blend to 1 (3D) without checking the Spatialize checkbox, Unity will use its panning spatializer instead of the Microsoft Spatializer with HRTFs.
Adjust the volume curve
By default, Unity attenuates spatialized sounds as they get farther from the listener. When this attenuation is applied to interaction feedback sounds, the interface can become more difficult to use.
To disable this attenuation, you need to adjust the Volume curve In the Audio Source component.
In the Hierarchy window, select the PressableButton_32x32mm_IconAndTextUnder, then navigate to Audio Source > 3D Sound Settings in the Inspector window and configure the settings as follows:
- Set the Volume Rolloff property to Linear Rolloff.
- Drag the endpoint on the Volume curve (the red curve) from 0 on the y axis up to 1.
- To adjust the shape of the Volume curve to be flat, drag the white curve shape control to be parallel to the X axis.
Test the spatialized audio
To test the spatialized audio in the Unity editor, you need to add an audio clip in the Audio Source component with Loop option checked in on PressableButton_32x32mm_IconAndTextUnder object.
In the Play mode, move the PressableButton_32x32mm_IconAndTextUnder object from left to right and compare with and without spatial audio enabled on your workstation. You can also change the Audio Source settings for testing by:
- Moving the Spatial Blend property between 0 and 1 (2D non-spatialized and 3D spatialized sound).
- Checking and unchecking the Spatialize property.
Try out the app on HoloLens 2. In the app, you can select the button and hear the spatialized button interaction sounds.
Note
Building and testing on HoloLens 2 is not mandatory. Alternatively, you can test on the HoloLens 2 Emulator if you don't have a device. You can purchase devices at HoloLens.com.