Skip to content

youngwoocho02/PurrNetMultiplayerServicesHandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 GameObjects Multiplayer 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's NetworkManager and Purrnity Transport.

What is Multiplayer Services Package? And Why Use It?

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.

Prerequisites

Before you begin, ensure your project has the following packages installed:

Installation

  1. Install Dependencies: Using the Unity Package Manager, install the Unity Transport and Multiplayer Services packages from the Unity Registry.
  2. Install PurrNet: Add the PurrNet package to your project.
  3. Install Purrnity Transport: Add the package via Git URL in the Package Manager:
    https://github.com/youngwoocho02/PurrnityTransport.git
    
  4. Install this Handler: Add the package via Git URL in the Package Manager:
    https://github.com/youngwoocho02/PurrNetMultiplayerServicesHandler.git
    
  5. Configure Transport: On your NetworkManager GameObject, add the PurrnityTransport component.

Usage Examples

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);
}

License

This project is distributed under the MIT License. See the LICENSE file for more information.

Related Resources

About

No description, website, or topics provided.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages