Resonance Audio Tutorial
We will be building off of the Unity 4.1 Throw a Ball Tutorial so complete and/or open that project. If you are not using VR, don't worry about the VR Prefabs or scripts attached to the objects. Instead follow the directions directly below.
[Non-VR only] Interactivity
If you are not using VR, we will need to add a few scripts to make things interactive.
First add an empty GameObject and call it Player. Move your Main Camera to the Player to make it a child of the Player GameObject.
Now add a Character Controller Component to the Player and transform it such that it is just above the floor plane.
Now add the following new script to the Player and call it DemoPlayerController:
Then, attach the Main Camera to the script.
Now, to the Ball, add the following script called AudioDemoBallController:
Lastly, create an empty GameObject and call it GameManager.
To this GameObject, attach the following script called AudioDemoManager:
Then attach the Main Camera and the Ball to the script.
Now you should be able to run the application, move around, and click on the ball to move it to a random location.
Resonance Audio Setup
Begin by downloading the latest unitypackage file from the Resonance Releases page. Now navigate to Unity.
In your project, go to Assets -> Import Package -> Custom Package. Then navigate to the <folder you extracted>/bin/unity. Click on the ResonanceAudioForUnity package you just downloaded and click "Open". Accept everything for importing.
Navigate to Edit -> Project Settings -> Audio and for both the Spatializer Plugin and the Ambisonic Decoder Plugin select "Resonance Audio".
Using Resonance Audio
Now we are ready to begin using Resonance Audio!
First, make sure that the your camera has an Audio Listener component and add one if it does not (the CameraRig object in the case of the Steam VR Tutorial).
Now to the Ball object, add an Audio Source Component.
Either download a sound clip from online or use one of the Steam VR audio files for the AudioClip field of our Audio Source.
Be sure that both Play On Awake and Loop are checked so that audio starts and continues while we are in VR.
Also make sure to set the Spatial Blend slider all the way to the right (value of 1) for 3D spatialization.
Then, under 3D Sound Settings, click to enable the Spatialize checkbox as well as the Spatialize Post Effects sub-checkbox.
Now also add a Resonance Audio Source Component to the Ball. I would recommend enabling occlusion since our audio source will be dynamic.
Now you are ready to test run the application!
Click run to start the application (make sure you have headphones or are using a headset built into a HMD if you are using VR).
You should be able to hear your audio coming from the ball!
If you are in VR, try moving/throwing the ball and holding it up to each ear. The sound should be varying spatially!
Changing the Environment
Now create an empty GameObject and call it Room.
Add a Resonance Audio Room Component to it and change the Size to fit the entire environment. Feel free to add actual walls and a ceiling for a visual cue.
Feel free to change the material type of each of the walls and run the application again to see how the audio changes. Be sure to re-export your scene!