Voice For PUN2

內容

Concept

The Voice for PUN2 layer logic is inherited from the original Photon Voice 1 or PUNVoice: Voice client state can be automatically synchronized with PUN's client state.

The main use case in mind is that each player has network-instantiated PUN prefab (character or avatar) where audio is 3D positioned. A single audio stream has a pair of components one on each endpoint: the Recorder and the Speaker. When using PUN the pair is linked via Photon View ID.

回到首頁
 

Key Components

PhotonVoiceNetwork

PhotonVoiceNetwork is a singleton: one instance only should exist. If multiple instances are present, only one be kept and others will be destroyed. We cannot predict which instance will be kept so you better make sure only one exists. Any new extra instance created at runtime will be destroyed. If you add PhotonVoiceNetwork from a prefab, make sure it's instantiated once.

The PhotonVoiceNetwork extends VoiceConnection and adds PUN related features: The default SpeakerFactory is overridden and you can tweak how much you want the PUN and Voice clients' states to be in sync. Also PUN and Voice can share the same AppSettings from the PhotonServerSettings.

回到首頁
 

Default SpeakerFactory

The new factory will try to find the proper Speaker for the audio stream info using the Photon View ID exchanged as custom user data object.

回到首頁
 

Auto Connect And Join

If PUN joins a room, the Voice client can connect and join a corresponding voice room as well.

回到首頁
 

Auto Leave And Disconnect

If PUN leaves the room the Voice client can disconnect automatically.

回到首頁
 

Use PUN Settings

A setting to decide if the Voice client will use the same AppSettings from PUN's PhotonNetwork.PhotonServerSettings. By default this is true (enabled).

回到首頁
 

Use PUN Auth Values

A setting to decide if the Voice client will use the same AuthenticationValues as PUN's PhotonNetwork.AuthValues. By default this is true (enabled). This requires the Voice application to have the same custom authentication dashboard configuration as the PUN application.

回到首頁
 

PhotonVoiceView

The PhotonVoiceView is the component responsible for setting up the Recorder and Speaker for the network-instantiated PUN prefab.

回到首頁
 

Suggested Workflow

Scene Setup (PhotonVoiceNetwork)

  1. Set Voice AppId in the AppSettings from PUN's PhotonServerSettings.
  2. Add a PhotonVoiceNetwork to the scene and enable "Don't Destroy On Load".
  3. Add a Recorder to the scene, update its properties and assign it to PhotonVoiceNetwork.PrimaryRecorder.

回到首頁
 

Prefab Setup (PhotonVoiceView)

  1. Add a PhotonVoiceView to a GameObject of a PUN prefab that has a PhotonView attached to it.
  2. Set PhotonVoiceView.UsePrimaryRecorder to true.
  3. Add a Speaker to the prefab and assign it to the PhotonVoiceView.SpeakerInUse.

To Document Top