This showcase highlights how to quickly integrate key multiplayer features from the platform to build a project that facilitates easy interaction with others.
In Decommissioned, you can join or create a game in two ways: Quick Match and Private Match.
The Quick Match button initiates a process where the application tries to join a random room as a client using the Photon random room API. If no room is available, it creates a new room as a host.
Anyone can join a public match before it starts if there is space. If all rooms are full, a new room is created for the player trying to join.
This option creates a private room. Only users who receive invites through the Meta Platform can join.
The MainMenu script is central to navigation. It encapsulates the API for navigating the application, starting the connection flow through the NetworkLayer using Application.Core and Application.Oculus.
The Application.Core script manages network state changes. When a player connects or disconnects, the Application.Oculus script configures them into the appropriate room with the correct GroupPresenceState.
Upon connection, the application navigates to the Lobby scene using the SceneLoader. The scene loader manages scene states and navigation using Netcode. When connected through Netcode, the application uses Netcode's NetworkSceneManager to synchronize the current Unity scene among connected users.
When a user receives an invitation, whether the game is launched or not, Application.Oculus handles the intent generated by this process.
The application checks the intent information and triggers the appropriate navigation flow. The core information needed is the lobbySessionId, which names the room the user wants to join.
VoipController sets up the VoIP speaker and recorder for players. The recorder captures the local player's voice and sends it over the network, where a speaker on the other client plays the sound. It also checks for audio recording permissions from the platform.
VoipHandler tracks the recorder or speaker of an entity, simplifying muting and unmuting or starting and stopping recording by referencing the recorder and speaker. This is used by the muting behavior detailed below.
As players move during a match, their voice chat state (muted/unmuted) may change based on nearby players. Various components access and change this state through PlayerVoip.
The application sets group presence when users change scenes and networked rooms, allowing others to join easily. The main implementation is in GroupPresenceState, which implements the group presence API and maintains the state locally.
This project uses Netcode for GameObjects with the Photon Realtime Transport. We used a fork of the transport package from Ultimate Glove Ball.
The fork includes:
- Adding intent on connection as a client, host, or to the lobby. PhotonRealtimeTransport
- Creating a private room with a visible flag.
- Adding a region override to change regions.
- Supporting join random room failure. PhotonRealtimeTransport.MatchMaking
- Adding a function to handle room creation with parameters. The parameters getter function can be hooked to the PhotonRealtimeTransport.Connection at runtime, giving full ownership to the project on room creation.
