A handler to bridge Unity 6's Multiplayer Services package with the PurrNet networking solution. This allows you to use Unity's session management with PurrNet without writing complex boilerplate code.
Note: This package is a near 1:1 adaptation of the
Netcode for GameObjectsMultiplayer Services handler (NetworkHandler). The session lifecycle logic (Direct/Relay setup, start/stop flow) is preserved as-is, with only the networking calls adapted to work with PurrNet'sNetworkManagerandPurrnity Transport.
Unity's Multiplayer Services package is an integrated solution designed to dramatically simplify the development of multiplayer games. It acts as a central hub that combines various powerful Unity Gaming Services (UGS) like Lobby, Relay, Matchmaker, and Multiplay Hosting into a unified, high-level API.
The core concept of this package is the Session. A session represents a group of players playing together, and it abstracts away the complex backend operations required to connect them.
By using this handler with PurrNet, you can leverage all these benefits from Unity's ecosystem while still using PurrNet's networking framework.
Before you begin, ensure your project has the following packages installed:
Unity 6.0or newerPurrNet: PurrNet networking frameworkPurrnity Transport(dev.purrnet.purrnity): Unity Transport wrapper for PurrNetUnity Transport(com.unity.transportversion 2.0 or newer)Unity Multiplayer Services(com.unity.services.multiplayerversion 1.1.0 or newer)
- Install Dependencies: Using the Unity Package Manager, install the
Unity TransportandMultiplayer Servicespackages from the Unity Registry. - Install PurrNet: Add the PurrNet package to your project.
- Install Purrnity Transport: Add the package via Git URL in the Package Manager:
https://github.com/youngwoocho02/PurrnityTransport.git - Install this Handler: Add the package via Git URL in the Package Manager:
https://github.com/youngwoocho02/PurrNetMultiplayerServicesHandler.git - Configure Transport: On your
NetworkManagerGameObject, add thePurrnityTransportcomponent.
Create Direct Session
private async Task CreateDirectSession()
{
var options = new SessionOptions()
{
MaxPlayers = 4,
}.WithPurrDirect();
// or use .WithPurrDirect("0.0.0.0", "192.168.1.100", 7777);
// for custom addresses
var result = await MultiplayerService.Instance.CreateSessionAsync(options);
Debug.Log($"Id: {result.Id}");
Debug.Log($"Code: {result.Code}");
}Create Relay Session
private async Task CreateRelaySession()
{
var options = new SessionOptions()
{
MaxPlayers = 4,
}.WithPurrRelay();
var result = await MultiplayerService.Instance.CreateSessionAsync(options);
Debug.Log($"Id: {result.Id}");
Debug.Log($"Code: {result.Code}");
}Join Session By Id
private async Task JoinSessionById(string sessionId)
{
var options = new JoinSessionOptions()
{
Password = null,
}.WithPurrHandler();
var result = await MultiplayerService.Instance.JoinSessionByIdAsync(sessionId, options);
}Join Session By Code
private async Task JoinSessionByCode(string sessionCode, string password)
{
var options = new JoinSessionOptions()
{
Password = password,
}.WithPurrHandler();
var result = await MultiplayerService.Instance.JoinSessionByCodeAsync(sessionCode, options);
}Quick Join Or Create Session
private async Task QuickJoinOrCreateSession()
{
var quickJoinOption = new QuickJoinOptions()
{
Filters = new List<FilterOption>
{
new(FilterField.AvailableSlots, "1", FilterOperation.GreaterOrEqual),
},
Timeout = TimeSpan.FromSeconds(10),
CreateSession = true,
};
var sessionOption = new SessionOptions()
{
MaxPlayers = 4,
}.WithPurrRelay();
var result = await MultiplayerService.Instance.MatchmakeSessionAsync(quickJoinOption, sessionOption);
}This project is distributed under the MIT License. See the LICENSE file for more information.