Voice - PUN2 Integration
- Voice - PUN2 Integration
- Key Components
- Suggested Workflow
Voice - PUN2 Integration
The main use is that each player has a network-instantiated PUN prefab (character or avatar) where audio is 3D positioned. Audio streams are created in the Voice room synchronously with PUN prefab instantiation in the scene. The Recorder attached to the network object produces an audio stream. The Speaker attached to the remote copy of this network object consumes the audio stream. Photon View ID is used to find the correct Speaker for the Recorder.
With this integration it's also possible to simply make the Voice room follow the state of the PUN room and stream through
PunVoiceClient.Instance.PrimaryRecorder not bound to any network object.
An implementation of voiceconnection that maintains connections and synchronizes the states of 2 rooms: Voice and PUN.
PunVoiceClient.Instance.UsePunAppSettings: if true,
PhotonNetwork.PhotonServerSettingsare used. Otherwise, set the values specific to the PunVoiceClient singleton in the "App Settings" foldout.
PunVoiceClient.Instance.UsePunAuthValues: if true, the Voice client will use the same
PhotonNetwork.AuthValues. This requires the Voice application to have the same custom authentication dashboard configuration as the PUN application.
Following The PUN State
PunVoiceClient.Instance.AutoConnectAndJoin: if PUN client joins a room, the Voice client connects and joins the corresponding Voice room as well.
PunVoiceClient.Instance.AutoLeaveAndDisconnect: if PUN client leaves the room, the Voice client disconnects automatically.
PunVoiceClient.Instance.PrimaryRecorder: an object with a Recorder component useful for scenarios where there is only 1 outgoing stream per client.
PunVoiceClient.Instance.UsePrimaryRecorder: if true, the Recorder attached to the Primary Recorder object will be automatically initialized and used for streaming. The Recorder will not be bound to any network object. Uncheck it if you are using
PunVoiceClient.Instance.SpeakerPrefab: a prefab that will be used to instantiate a speaker object when a new incoming stream is detected and the object that this stream belongs to does not have a Speaker in its hierarchy. Set it if you are not using
PhotonVoiceViewprefabs or these prefabs do not have a Speaker component. Must contain a Speaker component.
The component assigned to the
PhotoView prefab and responsible for setting up the Recorder and Speaker.
On the streaming side, it starts the Recorder found in the prefab hierarchy, or if not found,
On the receiving side, It starts the Speaker found in the prefab hierarchy, or if not found, instantiates it from
- Set Voice AppId in the AppSettings from PUN's
- Add a PunVoiceClient to the scene.
- Add an object with a Recorder to the scene and assign it to
- Create a prefab with a Speaker and assign it to
- Add a
PhotonVoiceViewto the PUN prefab object that has a
PhotonViewattached to it.
- Instantiate this prefab after joining a room.
See see sample for pun2 for more information .