This package provides access to HiFi Spatialized Audio in Unity.
Please see Install package.
- Create an account: https://account.highfidelity.com/dev/account
- Create a HiFi "App" for whatever project you're workining on.
- Create a "Space" inside the App where Users can meet.
- For each User that will be connecting to the Space: create a JSON Web Token (JWT). The JWT is a compressed binary blob with info about the App Space and the User's publicly visible name (aka optional User ID). Note: since the User's publicly visible name is optional it is technically possible to use a single JWT for all Users in the Space, however then all HiFi peers'
IncomingAudioAPIData
will have uniquevisitHashID
but the sameprovidedUserID
. - In the Unity project:
- Add com.endel.nativewebsocket package via git URL: https://github.com/endel/NativeWebSocket.git#upm
- Add Highfidelity's modified com.unity.webrtc package via git URL: https://github.com/highfidelity/com.unity.webrtc.git#2.4.0-directAudio
- Add this com.highfidelity.spatialized-audio package.
- Create a HiFi.HiFiCommunicator for the User.
- Set the
HiFiCommunicator.SignalingServiceUrl
towss://api.highfidelity.com:8001/
. - Set the
HiFiCommunicator.JWT
- Call
HiFiCommunicator.ConnectToHiFiAudioAPIServer();
- Every frame set
HiFiCommunicator.UserData.Position
and.Orientation
in the HiFi-frame. Note the HiFi world coordinate frame is right-hand Cartesian with forward=z-axis and up=y-axis. The Unity project will undoubtedly be using a different coordinate system and values must be transformed into the HiFi-frame before settingHiFiCommunicator.UserData
. There is aHiFiCoordinateFrameUtil
class to help with this.
- Import the dependencies and the package https://github.com/highfidelity/hifi-spatial-audio-unity.git.
- Import the Bumpers Sample from the package. (e.g., select the HiFi Spatialized Audio package in the Package Manager => Samples => Bumpers => Import)
- From the Project window, add Assets => Samples => HiFi Spatialized Audio => 0.1.0 => Bumpers => Scenes => BumpersScene to the Hierarchy, and remove any other scenes.
- In the "BumpersScene" Hierarchy, select gameManager. In the Inspector, click on the empty text box next to "Hi Fi Jwt". Enter a JWT generated from https://account.highfidelity.com
- Set up an Input Axis Rotate if it doesn't already exist, using Edit => Project Setting... => Input Manager => Axes. Increase size to get a new field. Change values:
Name: Rotate
Negative Button: d
Positive Button: a
Alt Negative Button: right
Alt Positive Button: left
Gravity: 3
Sensitivity: 3
Snap: (checked)
Type: Key or Mouse Button
Axis: X axis