This repository will guide you setting up LiveKit for your browser based game Unity game. (WebGL builds only.)
Note the classes:
- LiveKitSetup, on the root of the player prefab,
- LiveKitAudio, this is where connecting to a room & all the other callbacks are/will be registered.
- The setup script enables the audio script on only the local clients, but the sphere colliders are enabled for all other clients.
There are 2 touchpoints for spatial audio:
- When a player's sphere collider overlaps with another (and their audio tracks are already published) player's sphere collider, we add them to the local player's rangeList and also subscribe to their tracks,
- When a player publishes their audio tracks, all other players subscribe to their tracks if that player happens to be near them.
If you take care of these 2 cases, you will have a neat, working spatial audio implementation, barring edge cases that you'll have to account for.
A few steps in Unity to make sure everything works correctly:
- Ensure in Player Settings -> Physics, LiveKitAudio layer only interacts with LiveKitAudio layer.
- The sphere collider on the LiveKitAudio Game Object on the player prefab must be disabled.
- Assign the sphere collider of this GameObject into the Setup script on the root of the player prefab.