This document is about: VOICE 2
SWITCH TO

PUN Voice Demo

The PUN Voice Demo is a simple four-player mobile friendly game where players can talk to each other.
Other than matchmaking, the game has 4 different playable characters and 3 different camera views.
The demo is based on Unity's tutorial "Survival Shooter"
and is available in the Photon Voice package.

PUN Voice Demo Screenshot
PUN Voice demo running

Setup

To try out the PUN Voice demo:

  1. Download the package from the Asset Store.
  2. Open the project in Unity and load DemoPunScene.
  3. Open PhotonServerSettings in Unity Inspector (Menu: "Window" -> "Photon Unity Networking" -> "Highlight Server Settings"):
  4. Build, run and enjoy!

Features

In this section we will talk about the features exposed in the demo.

Multiple Characters

When trying the demo with your friends you will notice that every player will have his own unique character and will be spawned in a random position.
This is handled using CharacterInstantiation class. In OnJoinedRoom callback we choose a prefab based on actor number and randmize spawn position.

Connection and Calibration

PUN Voice Demo - Control Buttons
PUN Voice Demo - Control Buttons

On the bottom right corner, you can find calibration and connection buttons.
The calibration button works only when joined to a voice room and is useful to tune loudness level.
Read more about "calibration".

The other two buttons "connects to" or "disconnects from" PUN or Photon Voice respectively.

Settings

By making some settings easily accesible from the UI,
we want to give you a shortcut to tune up your Photon Voice applications.

In-Game Settings

PUN Voice Demo In-Game Settings
PUN Voice Demo In-Game Settings

The most important runtime settings for Photon Voice applications are grouped in a single ToggleGroup:

  • Transmit: When disabled voice transmission will be switched off. Otherwise, the sound will be recorded locally and transmitted.
  • Mute Speaker: This setting does what it says, it mutes speakers by setting volume to zero.
  • VoiceDetection: This setting enables or disables Voice Detection feature.
  • DebugEcho: This setting is useful when testing Voice applications using a single client. If on, audio stream sent will be sent back to the original sender from the server. To be used for debug purposes only.

Global Settings

PUN Voice Demo Global Settings
PUN Voice Demo Global Settings
  • AutoConnectAndJoin: Automatically joins Photon Voice client to a "voice room" when PUN client is joined to a "PUN room".
  • AutoLeaveAndDisconnect: Automatically disconnects Photon Voice client when PUN client is disconnected.
  • DebugVoice: Toggles debug mode.
    Debug text will appear on top left corner of the screen containing: PUN and Voice applications ClientState, Microphone device used and some Voice stats.
    If on, it also shows Voice speaker lag on top of every "speaking" character.

Highlighting Voice Components

In order to illustrate how the two main Voice components work we used an isometric view that is shown on top of every player.
This view is based on Unity's new UI system in "World Space" mode. It contains 2 icons:

"Speaker" icon

PUN Voice Demo - Highlighting Speaker
PUN Voice Demo - Highlighting Speaker

The purpose of this icon is to show when a player's voice is being played.
It is bound to the PhotonVoiceView component.
The image is shown or hidden based on this code:

C#

speakerSprite.enabled = photonVoiceView.IsSpeaking;

Also, when DebugVoice global setting is toggled, a text will start showing up in the same view containing a constantly updated number.
It should inform about the lag in the speaker component. It is enabled or disabled as follows:

C#

bufferLagText.enabled = showSpeakerLag && photonVoiceView.IsSpeaking;
if (bufferLagText.enabled)
{
    bufferLagText.text = string.Format("{0}", photonVoiceView.SpeakerInUse.Lag);
}

"Bubble speech" icon

PUN Voice Demo - Highlighting Recorder
PUN Voice Demo - Highlighting Recorder

The purpose of this icon is to show when a player's voice is being recorded and transmitted.
It is bound to the PhotonVoiceView component.
The image is shown or hidden based on this code:

C#

recorderSprite.enabled = photonVoiceView.IsRecording;

You can take a look at the "Highlighter.cs" file and class with the same name to know more about this.

Different Cameras

Since Photon Voice can be used in any type of games, AR and VR included, it would help to have a working example showing how good is the 3D sound experience.
For this purpose, we have prepared 3 camera modes:

  • "First Person"
PUN Voice Demo - First Person View
PUN Voice Demo - First Person View
  • "Third Person"
PUN Voice Demo - Third Person View
PUN Voice Demo - Third Person View
  • "Orthographic" (Default)
PUN Voice Demo - Orthographic View
PUN Voice Demo - Orthographic View

You switch between them freely and seamlessly at any time once you're joined to a room.
Three respective buttons are available on the top right corner of the screen once the player's character is instantiated.

Mobile Joystick

The demo includes support for mobile touch input.
On smartphones or tablets, you can use the joystick UI that comes with the demo which is based on Unity's Standard Assets.
To be able to use this feature you need to enable "Mobile Input" from Unity's menu and switch to a compatible platform in Unity's build settings.

PUN Voice Demo - Android Screenshot
PUN Voice Demo - Android Screenshot

Debug Mode

When the DebugVoice toggle is on, the Debug Mode is enabled.
During this mode, extra information is displayed on the top left corner of the screen which contains:

  • State of PUN Client
  • State of Voice Client
  • Average and peak voice amplitudes
  • List of microphone devices available or a warning if none. Generally, most devices contain one microphone.
PUN Voice Demo - Debug Mode
PUN Voice Demo - Debug Mode
Back to top